fix(trace): avoid allocation while swapping profiles - #15720
Open
rgrinberg wants to merge 1 commit into
Open
Conversation
Capture sampled heap state in references allocated before taking the profile mutex, then construct the snapshot tuple after releasing it. This prevents an allocation callback from recursively acquiring the sample mutex. Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
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.
Alloc.swapcurrently constructs its result tuple while holding the allocation profiler's sample mutex. At sufficiently high sampling rates, that allocation can invoke a Memprof callback which attempts to acquire the same mutex, terminating Dune withMutex.lock: Resource deadlock avoided.Capture the sampled heap fields in references allocated before taking the mutex, and construct the returned tuple only after releasing it. This keeps the critical section allocation-free without changing the snapshot contents.