Repository navigation
Runtime: empty small-object slabs go back to the system (#685 tier 1) - #3395
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.
A freed small block joined its class's freelist and its slab stayed mapped for the life of the process: a program's small-object memory was its high-water mark (#685).
What changes. A slab whose block map has no bit set holds no live block, so every block carved from it is on a freelist. A sweep finds those slabs, unlinks their blocks from the freelists and unmaps them (
rt_release_empty_slabs, rt/rt_core.w). The hot path pays one counter: the sweep runs when the free blocks have doubled since the last one (plus a floor of 32,768), so its walk is paid by the frees that grew the lists, and a program whose free blocks hold steady never sweeps. The slab being carved is never released. The page index keeps a released slab's keys with no start and drops them at its next rebuild, which is now sized by live slabs. wasm keeps its slabs (linear memory never shrinks and its unmap recycler is bounded): each platform statesrt_unmap_returns_pages.WITH_ALLOC_NO_REUSEnever sweeps.Measured (darwin-aarch64).
behav_685_empty_slabs_released.w(200,000 48-byte blocks, freed, twice)with check src/main.wwallThe last row is the cost: a program that allocates and frees the same 13 MB over and over pays about 1 ms a round to map it again. The compiler's peak does not move, as expected: this returns memory after a peak, it does not lower one. That is tier 2 of the issue (phase-scoped arenas), which stays open.
A first version kept a live count in each slab and cost a self-check 2%; this one reads the block maps the allocator already keeps.
Battery GREEN on c34c123;
:release-checksgreen.Part of #685 (tier 1).