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"))?;Profiling is enabled by default. To build the allocator without profiler
hooks, depend on this crate with default-features = false; in that mode the
profiling API remains available but cannot start a profiler.
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.
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.
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). - 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_
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.