pub struct TurboMalloc;Expand description
Turbo’s preferred global allocator. This is a new type instead of a type alias because you can’t use type aliases to instantiate unit types (E0423).
Implementations§
Source§impl TurboMalloc
impl TurboMalloc
Sourcepub fn memory_usage() -> usize
pub fn memory_usage() -> usize
Returns the bytes mimalloc currently has committed from the OS. This measures what the allocator holds rather than the process’s total footprint, and it does not track frees in lock step, since mimalloc reuses and purges pages on its own schedule.
See current_commit in mi_process_info, which documents each figure mimalloc reports.
Without the custom_allocator feature this is a process-wide live-bytes counter instead,
which is approximate because threads buffer their updates.
Sourcepub fn thread_stop()
pub fn thread_stop()
Clears the calling thread’s allocation counters. Call this when a thread is about to stop, so a thread that reuses its slot does not inherit the previous totals.
pub fn thread_park()
Sourcepub fn collect(force: bool)
pub fn collect(force: bool)
When using mimalloc triggers some cleanup
force=false: process threadlocal free lists and other threadlocal deferred work
only operates on thread local data and should be fast
force=true: do all the work of process=false and then process global shared structures and
return memory to the OS if possible, this is much slower and should only be done rarely.
pub fn allocation_counters() -> AllocationCounters
pub fn reset_allocation_counters(start: AllocationCounters)
Sourcepub fn memory_pressure() -> Option<u8>
pub fn memory_pressure() -> Option<u8>
Returns a memory pressure value in the range 0..=100, or None when
the current platform does not expose a memory pressure signal or a
query for it failed.
0 means no memory pressure, 100 means maximum pressure.
- On Linux this is derived from
/proc/pressure/memory(thesomeavg10stall percentage), falling back to(MemTotal - MemAvailable) / MemTotalfrom/proc/meminfowhen PSI is not available (older kernels, noCONFIG_PSI, or containers without access). - On macOS this is derived from the
kern.memorystatus_levelsysctl (100 - free_memory_percentage). - On Windows this is
MEMORYSTATUSEX::dwMemoryLoad(percentage of physical memory in use). - On other platforms this returns
None.
Trait Implementations§
Source§impl GlobalAlloc for TurboMalloc
impl GlobalAlloc for TurboMalloc
Source§unsafe fn alloc(&self, layout: Layout) -> *mut u8
unsafe fn alloc(&self, layout: Layout) -> *mut u8
layout. Read more