unconscious: release lock during slow spawn work
Split trigger() into phases so the Unconscious mutex is only held briefly: - reap_finished(): check handles, restore completed autos - select_to_spawn(): pick agents, take their autos out - prepare_spawn(): slow work (Store::load, query, Agent::new) - NO LOCK - complete_spawn()/abort_spawn(): store results back Previously held the lock for 28+ seconds during Store::load and query execution. Now lock hold time should be milliseconds. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
f56fc3a7c7
commit
f40d8cfa9d
2 changed files with 142 additions and 85 deletions
|
|
@ -346,7 +346,19 @@ impl Mind {
|
|||
s.unc_idle = true;
|
||||
}
|
||||
loop {
|
||||
unc.lock().await.trigger().await;
|
||||
// Phase 1: quick work under lock
|
||||
let to_spawn = {
|
||||
let mut guard = unc.lock().await;
|
||||
guard.reap_finished();
|
||||
guard.select_to_spawn()
|
||||
};
|
||||
// Phase 2: slow work outside lock
|
||||
for (idx, name, auto) in to_spawn {
|
||||
match crate::mind::unconscious::prepare_spawn(&name, auto).await {
|
||||
Ok(result) => unc.lock().await.complete_spawn(idx, result),
|
||||
Err(auto) => unc.lock().await.abort_spawn(idx, auto),
|
||||
}
|
||||
}
|
||||
// Check if conscious became active
|
||||
if *unc_rx.borrow() { break; }
|
||||
// Brief yield to not starve other tasks
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue