Expand description
Rust global allocator support for the in-tree mimalloc build.
use mimalloc_pprof::{prof, MiMalloc};
#[global_allocator] static ALLOCATOR: MiMalloc = MiMalloc;
prof::start(512 * 1024);
prof::dump_file(std::path::Path::new("heap.prof"))?;Since 0.12.0 every observability subsystem is opt-in and the default build is a
plain fast allocator whose malloc/free fast path is byte-identical to upstream
mimalloc. Enable what you need with cargo features – pprof (the example above),
memory-events, diagnostics, dhat (implies memory-events), owner-gate, or
full for all of them:
mimalloc-pprof = { version = "1", features = ["pprof"] }The whole API compiles and links in every configuration: a subsystem that was not
built in simply reports itself off (prof::start returns false, heap_dump_json
returns None, and so on), so no #[cfg] is needed at the call site. Cargo features
are additive and unified across the dependency graph, so a dependency that enables one
enables it for your build too – cargo tree -e features shows who.
See the README’s Rust integration guide for frame-pointer and line-table
build flags. Open the resulting profile with pprof -http=: app.exe heap.prof.
Modules§
- dhat
- Exact DHAT v2 heap/lifetime profiling controls.
- memory_
events - Opt-in allocation-change accounting and callbacks (
include/mimalloc/memory-events.h). - options
- mimalloc’s
mi_option_*settings: the runtime knobs behind everyMIMALLOC_*environment variable. - prof
- Safe controls for mimalloc’s sampled heap profiler.
- stats
- The allocator’s own exact statistics, as opposed to the sampled numbers
crate::prof::statsreports. - sys
- Raw bindings to the in-tree mimalloc static amalgamation.
Structs§
- Idle
Park - Returned by
park_while_idle; ends the park when dropped. - MiMalloc
- A
#[global_allocator]implementation backed by mimalloc. - Prof
Config - Ergonomic, Rust-facing sibling of
mi_prof_config_t(include/mimalloc/profile.h) forenable_heap_profiling_with. - Purge
AllReport - What a
purge_all/purge_all_excall returned to the OS and which threads it could not reach (issue #366). Mirrorsmi_purge_all_report_t. - Purge
Flags - Flags for
purge_all_ex(issue #366).
Enums§
- Dump
Format - Output format for
ProfConfig::dump_at_exit. - Prof
Config Mode - How
ProfConfigfields interact with the profiler’s environment variables andmi_option_*settings. - Purge
Status - The outcome of a
purge_all/purge_all_excall (issue #366).
Constants§
- HEAP_
DUMP_ JSON_ DEFAULT_ WAIT_ MS - Default owner-acquisition deadline used by
heap_dump_json. - PURGE_
ALL_ DEFAULT_ WAIT_ MS - The
wait_msC’smi_purge_allpasses tomi_purge_all_ex, and whatpurge_alluses.
Functions§
- enable_
heap_ profiling - Turn on sampled heap profiling at the default sample rate.
- enable_
heap_ profiling_ with - Turn on sampled heap profiling using a struct-based configuration.
- expand⚠
- Try to grow an allocation in place, without moving it.
- heap_
dump_ json - Live per-heap -> per-page -> (optional) per-block JSON snapshot of the current
subprocess (issue #269, Bun parity P4). Backs Bun’s shipped
bun:jscheapStats({dump:true|"blocks"}).mimallocDump; seesrc/heap-dump.cfor the JSON shape ({"heaps":[{"seq":N,"pages":[{"id","block_size","used","reserved","thread_id"}], "blocks":[[id,size],...]}]},blockspresent only wheninclude_blocks). - heap_
dump_ json_ ex - Live heap JSON capture with an explicit owner-acquisition deadline.
- heap_
snapshot_ to_ file - Write a binary heap snapshot to
path(issue #338, Bun parity). - on_
thread_ idle - Tell mimalloc this thread is idle (issue #272, Bun parity P7a).
- park_
while_ idle - Guard form of
on_thread_idlefor a thread that is about to BLOCK: hands this thread’s heaps to the background scavenger, which does the idle work above while this thread sits in the kernel, and takes them back on drop. - purge_
all - Process-wide eager purge from any thread (issue #366), with the C default of a 100 ms
owner-acquisition wait:
mi_purge_all(force), but with the report kept. - purge_
all_ ex - Process-wide eager purge from any thread (issue #366): the full form of
purge_all. - purge_
holes_ report - Print, per size class, what hole purging leaves behind (issue #272, Bun parity P7b).
- purge_
holes_ stats - What page hole purging has reclaimed, process wide (issue #272, Bun parity P7b).
- recalloc⚠
- Grow or shrink an allocation to
count * sizebytes, zeroing any newly-exposed tail. - rezalloc⚠
- Grow or shrink an allocation, zeroing any newly-exposed tail.
- scavenger_
stop - Stop the background scavenger thread (issue #272).
- unwrapped_
free ⚠ - Free a pointer returned by
unwrapped_mallocorunwrapped_realloc. - unwrapped_
malloc ⚠ - Allocate
sizebytes from mimalloc’s raw-OS-layer “unwrapped” path. - unwrapped_
realloc ⚠ - Resize a pointer returned by
unwrapped_mallocorunwrapped_realloc. - usable_
size ⚠ - Bytes actually available in an allocation, which may exceed what was requested.