//! the global allocator, picked by the `alloc-*` features. the hydrant binary, the benches and
//! hydrant-ffi all include this file, so benchmarks allocate the way production does.
#[cfg(feature = "alloc-mimalloc")]
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
#[cfg(feature = "alloc-jemalloc")]
#[global_allocator]
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
// bake the tuned jemalloc runtime config into the binary. the prefixed tikv build reads
// the `_rjem_malloc_conf` symbol (plain `malloc_conf` silently no-ops). `percpu_arena`
// pins one arena per cpu, bounding per-arena dirty-page retention — the dominant rss lever
// here (~2.4x less resident than the default 4*ncpu arenas); `background_thread` purges
// asynchronously so `dirty_decay_ms:1000`/`muzzy_decay_ms:0` return pages without sync
// munmap churn. measured 1.72 GiB steady vs 4.14 for mimalloc. both options are linux-only
// (they no-op or warn elsewhere), so gate to linux; other targets get vanilla jemalloc.
// overridable at runtime via _RJEM_MALLOC_CONF.
#[cfg(all(feature = "alloc-jemalloc", target_os = "linux"))]
#[allow(non_upper_case_globals)]
#[unsafe(export_name = "_rjem_malloc_conf")]
pub static _rjem_malloc_conf: Option<&'static core::ffi::CStr> =
Some(c"background_thread:true,percpu_arena:percpu,dirty_decay_ms:1000,muzzy_decay_ms:0");
#[cfg(feature = "alloc-snmalloc")]
#[global_allocator]
static GLOBAL: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc;