Repository navigation
perf: skip the waiter lock on an uncontended mutex unlock - #1234
Merged
Merged
Conversation
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.
Under the green backend, every
Mutex.unlocktook the mutex's internal waiter lock to drain a list of parked green tasks that is almost always empty. Onlock_sweep/breaker(one breaker per task, so the locks are uncontended),pith_mutex_unlockwas 56% of the profile.The state word now has a third value: 2 means "held, with green tasks registered". A waiter moves the state from 1 to 2 under the waiter lock before it registers. If the lock was released in between, that move fails on the 0 and the waiter retries the acquire instead of parking.
unlockswaps in 0 and takes the waiter lock only when the old value was 2. This is the usual futex register-then-recheck. An os-thread waiter still spins on the 0 to 1 compare-exchange and never sets 2.Interleaved medians of 7 at 16 workers, main against this branch:
The other lock_sweep and metrics_contention rows and cpu_parallel_sync are within noise. Reruns of the two labels rows with 15 trials gave medians of 51.7 vs 52.3 and 92.6 vs 92.0 ms.
Local corpus, leak, memcheck, green (including
green-mutex), result-box, cargo test, seed, TLS-barrier and panic gates pass.