Skip to main content

Crate stoolap_jemalloc

Crate stoolap_jemalloc 

Source
Expand description

A jemalloc-style memory allocator in pure Rust, with a sampling heap profiler that writes pprof profiles.

use stoolap_jemalloc::Jemalloc;

#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc::new();

fn main() {
    stoolap_jemalloc::prof::activate();
    // ... work ...
    stoolap_jemalloc::prof::write_pprof("heap.pb").unwrap();
}

Then go tool pprof -http=: heap.pb.

Design, after jemalloc:

  • size classes with 8-byte steps up to 128 bytes, then four per doubling
  • a thread cache per thread, flushed in batches and trimmed over time
  • 4 arenas per CPU; small classes come from slabs, larger ones from page runs inside 4 MiB chunks, and those above 1 MiB from their own mappings
  • freed pages go back to the OS after 5 to 10 seconds
  • heap profiling by sampling, on average once per 512 KiB allocated

Modules§

background
A thread that returns free memory to the OS on time. Without it, decay runs as the allocator is used, so a process that stops allocating keeps its free pages. It is started explicitly, as in jemalloc, where background threads are off by default: a library that starts threads on its own surprises sandboxes, thread counts and forking programs.
prof
Sampling heap profiler.

Structs§

Jemalloc
The allocator; install it with #[global_allocator]:
Stats
Memory the allocator holds from the OS, in bytes

Functions§

purge
Returns the calling thread’s cached objects, then every free page and cached huge mapping, to the OS
stats
A snapshot of the allocator’s counters