Avoid acquiring lock and notify if no worker is parking - #1591
Merged
Merged
Conversation
qinsoon
added a commit
to oscardssmith/mmtk-core
that referenced
this pull request
Sep 14, 2026
Master's mmtk#1591 replaces the branch's lock-free wake-up fast path with its own: `WorkerParker` moves out of `WorkerMonitorSync` and `parked_workers` becomes an `AtomicUsize`, so `notify_work_available` can test it without taking the monitor lock. That supersedes this branch's `sleeping` counter, which existed only to be that lock-free reading and was strictly narrower -- `sleeping <= parked_workers` always, since a worker increments it only after `inc_parked_workers`. Master's counter is the more conservative test (it also counts the last parked worker while it runs `on_last_parked`), so it can cost an occasional redundant lock acquisition but cannot miss a wake-up. Dropped with it, both now judged not to earn their divergence: - `inactive_waiters`, and the `notify_inactive_while_locked` gate it fed. It only suppressed a `notify_all` on `active_worker_number_changed` when no worker was waiting there -- one no-op FUTEX_WAKE per bucket boundary, which is noise against a pause. The extra call it added to `wake_n_while_locked` was not load-bearing either: `set_active_workers` documents that its caller must follow with `notify_work_available(true)`, so a reactivation always arrives as `WakeAll`, never as `Wake(n)`. - `wake_all_override` (`MMTK_WAKE_ALL`), which existed to measure what the targeted wake-ups were worth. mmtk#1589 settled that. worker_monitor.rs is now byte-identical to master. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR moves
WorkerParkeroutside ofWorkerMonitorSync. The main goal is to accessparked_workersas an atomic without the lock. This allows us to avoid acquiring the lock and waking up all workers innotify_work_available-- which almost happens for every newly added work packet.