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