Schedule unconscious agents by oldest last_run

Pick the agent that ran longest ago (or never) instead of
scanning alphabetically. Fairness via min_by_key(last_run).

Co-Authored-By: ProofOfConcept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-10 03:20:20 -04:00
parent 74945e5754
commit be44a3bb0d

View file

@ -187,17 +187,14 @@ impl Unconscious {
}
let running = self.agents.iter().filter(|a| a.is_running()).count();
if running >= self.max_concurrent { return; }
let slots = self.max_concurrent - running;
let ready: Vec<usize> = self.agents.iter().enumerate()
for _ in running..self.max_concurrent {
let next = self.agents.iter().enumerate()
.filter(|(_, a)| a.should_run())
.map(|(i, _)| i)
.take(slots)
.collect();
for idx in ready {
self.spawn_agent(idx).await;
.min_by_key(|(_, a)| a.last_run);
match next {
Some((idx, _)) => self.spawn_agent(idx).await,
None => break,
}
}
}