Repository navigation
fork: take the meta-data lock before the arena reserve lock in the fork handlers - #33
Merged
Merged
Conversation
…rk handlers A meta-data allocation (`_mi_meta_zalloc*`) holds `theap_meta_lock` and can need a fresh arena, which takes `arena_reserve_lock` (`mi_arenas_try_alloc`). The fork prepare handler acquired them the other way round, so a `fork()` racing a meta allocation that had to reserve an arena could deadlock. Nothing under the reserve lock allocates meta data, so meta -> reserve is the one consistent order; the handlers now use it. Also `mi_theap_zalloc_csize` returned non-zeroed memory for sizes above MI_SMALL_SIZE_MAX (it called `mi_theap_malloc` on that branch; upstream f60b4cf).
Jarred-Sumner
added a commit
to oven-sh/bun
that referenced
this pull request
Sep 3, 2026
Bumps oven-sh/mimalloc from 942b834 to 6a64e1b (12 commits). - Allocate the per-bin abandoned-page bitmaps on first abandon (oven-sh/mimalloc#32) - A heap being released abandons its pages unmapped - Order the heap delete walk against concurrent frees - Take the meta-data lock before the arena reserve lock in the fork handlers (oven-sh/mimalloc#33) - Tests for heap release on many threads
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.
A meta-data allocation holds
theap_meta_lockand can need a fresh arena, which takesarena_reserve_lock(mi_arenas_try_alloc)._mi_process_fork_prepareacquired them in the opposite order, so afork()racing a meta allocation that had to reserve an arena could deadlock. Nothing under the reserve lock allocates meta data, so meta → reserve is the consistent order; the prepare/parent handlers now use it.