Skip to content

Relax MeteredExecutor state update ordering - #2680

Open
namtran1812 wants to merge 1 commit into
facebook:mainfrom
namtran1812:optimize/metered-executor-relaxed-state
Open

Relax MeteredExecutor state update ordering#2680
namtran1812 wants to merge 1 commit into
facebook:mainfrom
namtran1812:optimize/metered-executor-relaxed-state

Conversation

@namtran1812

Copy link
Copy Markdown

Summary

Relax the successful MeteredExecutorImpl::modifyState() compare-exchange from memory_order_seq_cst to memory_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 same state_ word with a relaxed atomic RMW.

Details

modifyState() has three callers:

  • add(): enqueues the task first, then updates pending/worker counts
  • resume(): clears the paused bit and reserves workers to schedule
  • worker(): decrements pending/worker counts before dequeuing the task

None 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.

@meta-cla

meta-cla Bot commented Aug 15, 2026

Copy link
Copy Markdown

Hi @namtran1812!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla meta-cla Bot added the CLA Signed label Aug 15, 2026
@meta-cla

meta-cla Bot commented Aug 15, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants