Reduce locking contention in TaskQueue
Categories
(Core :: XPCOM, enhancement)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox153 | --- | fixed |
People
(Reporter: nika, Assigned: nika)
References
(Depends on 1 open bug)
Details
Attachments
(2 files)
Currently, when running a number of tasks dispatched to a TaskQueue, we acquire the TaskQueue's QueueMonitor 3 times per-task. This is an excessive number of locking calls, and is likely partially responsible for worsening the locking contention issue from bug 1981051.
| Assignee | ||
Comment 1•1 year ago
|
||
This patch aims to reduce lock contention when dispatching to TaskQueue, by reducing the frequency with which the runner thread needs to acquire the TaskQueue monitor.
Prior to this change, if there is a backlog of queued runnables, TaskQueue::Runner would acquire mQueueMonitor 3 times per event. After this change, mQueueMonitor will only be acquired when the set of tasks read the last time the monitor was held have all been processed.
TaskQueue would need to change to use an unbounded lock-free MPSC queue in order to further reduce contention when dispatching. Doing so is a much larger project, and would require more substantial changes to the TaskQueue type to make state management (especially around shutdown) avoid locking.
Comment 4•11 months ago
•
|
||
Backed out for causing multiple failures
Failure log mda-bc
Failure log bc
Failure push mda
Failure push gtest
Comment 5•4 months ago
|
||
There is an r+ patch which didn't land and no activity in this bug for 2 weeks.
:nika, could you have a look please?
If you still have some work to do, you can add an action "Plan Changes" in Phabricator.
For more information, please visit BugBot documentation.
Comment 6•4 months ago
|
||
I think there is just higher priority work than fixing the backout, right now.
| Assignee | ||
Updated•4 months ago
|
Comment 7•3 months ago
|
||
MaybeAsyncCreateAudioSink used mAsyncInitTaskQueue->IsEmpty() inside
the dispatched runnable as a "let the newest call do the init"
coalesce check. With the previous commit's bulk-steal Runner,
IsEmpty() returns !mIsRunning rather than mTasks.IsEmpty(), so it
stays false for the duration of any in-flight runnable and the
coalesce check always reports "newer queued" — the AudioSink would
never actually initialize.
Replace the TaskQueue-state query with an explicit monotonic dispatch
sequence counter on the wrapper. Each MaybeAsyncCreateAudioSink call
increments mAsyncDispatchSeq and the dispatched runnable captures the
value; if the live counter has advanced past that snapshot when the
runnable runs, a newer call has superseded it and we short-circuit.
Only the newest dispatch does the init, preserving the existing
"later wins" semantic.
Updated•3 months ago
|
Updated•3 months ago
|
https://hg.mozilla.org/mozilla-central/rev/8d217b003092
https://hg.mozilla.org/mozilla-central/rev/aec432fc144f
Description
•