fix(runtime): retag mimalloc OS mappings off the IOAccelerator VM tag (#6882)#6889
Merged
Conversation
…r VM tag mimalloc (the global allocator, #62) tags its mappings VM tag 100, which macOS tooling decodes as IOAccelerator — the whole JS heap renders as GPU driver memory in vmmap/Instruments/footprint. js_gc_init now retags to VM_MEMORY_APPLICATION_SPECIFIC_1 (240) on Apple 64-bit targets, deferring to an explicit MIMALLOC_OS_TAG env override. Adds a profiling section to internals/memory-model.md and a unit test pinning the retag.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (5)
📝 WalkthroughWalkthroughChangesmacOS memory tagging
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Closes #6882.
Problem
mimalloc (Perry's
#[global_allocator]since #62) tags its OS mappings with VM tag 100, which macOS tooling —vmmap, Instruments' VM Tracker,footprint— decodes asIOAccelerator. Every Perry process on macOS therefore appears to hold hundreds of MB of GPU-driver memory (644 MB mapped / 422 MB resident on the churn benchmark in #6882), and the actual JS heap is invisible as a category. Anyone profiling Perry memory starts by chasing a GPU ghost.Fix
js_gc_init— the first runtime call in every compiled binary's prelude, already home to per-platform one-time setup — retags mimalloc's mappings toVM_MEMORY_APPLICATION_SPECIFIC_1(240) viami_option_set(mi_option_os_tag, 240):cfg(all(target_pointer_width = "64", target_vendor = "apple"))): the tag is only consulted by Apple kernels, and mimalloc itself is already 64-bit-only.MIMALLOC_OS_TAGenv setting wins — the retag is skipped so profilers can keep steering the tag themselves.js_gc_init.js_gc_init(early Rust startup) keep tag 100; the bulk of the heap (arena blocks, GC metadata) maps afterwards.Adds
libmimalloc-sys(the crate mimalloc already depends on, same version resolution) as an Apple-only dependency for itsextendedoption API.Also in this PR
docs/src/internals/memory-model.md: new "Profiling Perry's memory on macOS" section — where the heap shows up (Memory Tag 240, notMALLOC_*), what pre-macOS tools attribute Perry's heap to IOAccelerator (GPU) — mimalloc VM tag 100 collision #6882IOAcceleratorregions meant, theMIMALLOC_OS_TAGoverride, and theMADV_FREE/RSS accounting caveat.gc::tests::os_tag::js_gc_init_retags_mimalloc_os_mappingspinning the retag (skips itself whenMIMALLOC_OS_TAGis set, mirroring the runtime's deference).Verification
vmmap -summaryon the #6882 churn benchmark compiled with this branch (macOS 26.5, Apple Silicon):Benchmark output unchanged (
39998000000).Unit suite:
cargo test -p perry-runtime --lib gc::— 477 passed, 2 failed; the same 2 failures (gc::tests::copying::large_object_old_born_array_slot_write_keeps_young_child_alive,gc::tests::teardown::map_set_side_allocations_release_on_thread_exit) reproduce on pristineorigin/main(fd74751) with this branch's changes stashed — pre-existing on main, unrelated to this PR.No behavior change beyond the mapping tag — allocation paths, sizes, and performance are untouched.
Summary by CodeRabbit
Improvements
Documentation
Tests