Relax MeteredExecutor state update ordering - #2680
Conversation
|
Hi @namtran1812! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Summary
Relax the successful
MeteredExecutorImpl::modifyState()compare-exchange frommemory_order_seq_csttomemory_order_relaxed.state_is a packed bookkeeping word containing the pending-task count, pause state, and number of workers in the wrapped executor queue. Its updates require atomicity and per-object modification ordering, but do not publish task contents or synchronize unrelated memory.Task publication is handled separately by
UMPMCQueue, which provides its own synchronization between enqueue and dequeue.pause()already updates the samestate_word with a relaxed atomic RMW.Details
modifyState()has three callers:add(): enqueues the task first, then updates pending/worker countsresume(): clears the paused bit and reserves workers to scheduleworker(): decrements pending/worker counts before dequeuing the taskNone of these uses the
state_CAS as a cross-object publication mechanism.The initial load and failed CAS in
modifyState()are already relaxed, so this removes the remaining unnecessary sequentially-consistent operation from the state-update path.Related to #2656.