Skip to content

fix(trace): avoid allocation while swapping profiles - #15720

Open
rgrinberg wants to merge 1 commit into
ocaml:mainfrom
rgrinberg:push-xotkoulyyxll
Open

fix(trace): avoid allocation while swapping profiles#15720
rgrinberg wants to merge 1 commit into
ocaml:mainfrom
rgrinberg:push-xotkoulyyxll

Conversation

@rgrinberg

Copy link
Copy Markdown
Member

Alloc.swap currently 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 with Mutex.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.

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

1 participant