Skip to content

fix(runtime): retag mimalloc OS mappings off the IOAccelerator VM tag (#6882)#6889

Merged
proggeramlug merged 1 commit into
mainfrom
fix/6882-mimalloc-vm-tag
Jul 27, 2026
Merged

fix(runtime): retag mimalloc OS mappings off the IOAccelerator VM tag (#6882)#6889
proggeramlug merged 1 commit into
mainfrom
fix/6882-mimalloc-vm-tag

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

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 as IOAccelerator. 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 to VM_MEMORY_APPLICATION_SPECIFIC_1 (240) via mi_option_set(mi_option_os_tag, 240):

  • Apple 64-bit only (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.
  • An explicit MIMALLOC_OS_TAG env setting wins — the retag is skipped so profilers can keep steering the tag themselves.
  • Idempotent, like the rest of js_gc_init.
  • Pages mapped before 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 its extended option 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, not MALLOC_*), what pre-macOS tools attribute Perry's heap to IOAccelerator (GPU) — mimalloc VM tag 100 collision #6882 IOAccelerator regions meant, the MIMALLOC_OS_TAG override, and the MADV_FREE/RSS accounting caveat.
  • Unit test gc::tests::os_tag::js_gc_init_retags_mimalloc_os_mappings pinning the retag (skips itself when MIMALLOC_OS_TAG is set, mirroring the runtime's deference).

Verification

vmmap -summary on the #6882 churn benchmark compiled with this branch (macOS 26.5, Apple Silicon):

before (main):
IOAccelerator                    644.4M   422.1M   422.1M        8

after (this branch):
IOAccelerator                     4352K      32K     32K         1   ← pre-js_gc_init residue only
Memory Tag 240                   640.1M   421.8M  387.5M         7   ← the JS heap, correctly attributed
Memory Tag 240 (reserved)        384.0M       0K      0K         1

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 pristine origin/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

    • Improved macOS memory tagging so Perry heap allocations are classified more clearly in profiling tools.
    • Added support for extended memory-tagging behavior on 64-bit Apple platforms.
  • Documentation

    • Added guidance for interpreting Perry memory usage, heap classifications, and RSS measurements in macOS profiling tools.
  • Tests

    • Added coverage verifying the expected macOS memory tag during garbage collector initialization.

…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.
@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7cfe8848-cc96-4bd0-971a-a8416b8949a8

📥 Commits

Reviewing files that changed from the base of the PR and between fd74751 and 4e1dbe0.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • crates/perry-runtime/Cargo.toml
  • crates/perry-runtime/src/gc/mod.rs
  • crates/perry-runtime/src/gc/tests/mod.rs
  • crates/perry-runtime/src/gc/tests/os_tag.rs
  • docs/src/internals/memory-model.md

📝 Walkthrough

Walkthrough

Changes

macOS memory tagging

Layer / File(s) Summary
Configure and apply mimalloc OS tagging
crates/perry-runtime/Cargo.toml, crates/perry-runtime/src/gc/...
Apple 64-bit builds enable mimalloc’s extended API, and js_gc_init sets the OS memory tag to 240 when MIMALLOC_OS_TAG is unset. A platform-specific test verifies the resulting value.
Document macOS memory attribution
docs/src/internals/memory-model.md
Documents mimalloc-backed heap regions, macOS VM tag labels, early mappings, and purging effects in profiling tools.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: andrewtdiz

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/6882-mimalloc-vm-tag

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@proggeramlug
proggeramlug merged commit 8eddd8e into main Jul 27, 2026
27 of 30 checks passed
@proggeramlug
proggeramlug deleted the fix/6882-mimalloc-vm-tag branch July 27, 2026 04:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macOS tools attribute Perry's heap to IOAccelerator (GPU) — mimalloc VM tag 100 collision

1 participant