Skip to content

Avoid acquiring lock and notify if no worker is parking - #1591

Merged
qinsoon merged 3 commits into
mmtk:masterfrom
qinsoon:mmtk-core-scheduler-lock-elision
Sep 14, 2026
Merged

qinsoon merged 3 commits into
mmtk:masterfrom
qinsoon:mmtk-core-scheduler-lock-elision

Conversation

@qinsoon

@qinsoon qinsoon commented Sep 14, 2026

Copy link
Copy Markdown
Member

This PR moves WorkerParker outside of WorkerMonitorSync. The main goal is to access parked_workers as an atomic without the lock. This allows us to avoid acquiring the lock and waking up all workers in notify_work_available -- which almost happens for every newly added work packet.

@qinsoon
qinsoon requested a review from wks September 14, 2026 06:41

@wks wks left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@qinsoon
qinsoon added this pull request to the merge queue Sep 14, 2026
Merged via the queue into mmtk:master with commit 0226c65 Sep 14, 2026
34 checks passed
@qinsoon
qinsoon deleted the mmtk-core-scheduler-lock-elision branch September 14, 2026 09:00
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants