tikv / jemallocator

Rust allocator using jemalloc as a backend
Other
347 stars 58 forks source link

Does MALLOC_CONF actually work? #65

Closed errantmind closed 1 year ago

errantmind commented 1 year ago

Hello, I'm micro-benchmarking Rust allocators (Linux) and I cannot get MALLOC_CONF to work.

[target.'cfg(not(target_env = "msvc"))'.dependencies]
jemallocator = "0.5.4"
jemalloc-ctl = "0.5.4"
#[global_allocator]
#[cfg(not(target_env = "msvc"))]
static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc;

fn main() {
    use jemalloc_ctl::{epoch, stats, opt};
    println!("tcache {:?}", opt::tcache::read().unwrap());
    println!("tcache_max {:?}", opt::tcache_max::read().unwrap());
    println!("background_thread {:?}", opt::background_thread::read().unwrap());
}
cargo build --release

MALLOC_CONF="background_thread:true,metadata_thp:always,percpu_arena:percpu,tcache_max:131072,tcache:true" ./target/release/faf-allocator-bench
tcache true
tcache_max 32768
background_thread false

Note:

BusyJay commented 1 year ago

Unless unprefixed_malloc_on_supported_platforms features is enabled, all jemalloc related symbols are prefixed with _rjem_. So instead of using MALLOC_CONF, you should specify _RJEM_MALLOC_CONF.

errantmind commented 1 year ago

That worked, thanks.