reifydb_allocator_jemalloc/
lib.rs1#![cfg_attr(not(debug_assertions), deny(clippy::disallowed_methods))]
5#![cfg_attr(debug_assertions, warn(clippy::disallowed_methods))]
6#![cfg_attr(not(debug_assertions), deny(warnings))]
7#![allow(clippy::tabs_in_doc_comments)]
8
9#[cfg(not(target_env = "msvc"))]
10use tikv_jemalloc_ctl::{epoch, stats};
11#[cfg(not(target_env = "msvc"))]
12use tikv_jemallocator::Jemalloc;
13
14#[cfg(not(target_env = "msvc"))]
15pub type Allocator = Jemalloc;
16
17#[cfg(not(target_env = "msvc"))]
18pub const ALLOCATOR: Allocator = Jemalloc;
19
20#[cfg(not(target_env = "msvc"))]
21pub fn verify() {
22 epoch::advance().expect(
23 "reifydb-allocator-jemalloc: jemalloc epoch advance failed; jemalloc is not the active allocator for this process",
24 );
25 let allocated = stats::allocated::read()
26 .expect("reifydb-allocator-jemalloc: jemalloc stats::allocated read failed; jemalloc is not the active allocator for this process");
27 assert!(
28 allocated > 0,
29 "reifydb-allocator-jemalloc: jemalloc reports 0 allocated bytes at startup; allocator is not bound to this process"
30 );
31}
32
33#[cfg(not(target_env = "msvc"))]
34pub fn stats() -> (u64, u64, u64, u64, u64, u64) {
35 let _ = epoch::advance();
36 (
37 stats::allocated::read().unwrap_or(0) as u64,
38 stats::active::read().unwrap_or(0) as u64,
39 stats::resident::read().unwrap_or(0) as u64,
40 stats::mapped::read().unwrap_or(0) as u64,
41 stats::retained::read().unwrap_or(0) as u64,
42 stats::metadata::read().unwrap_or(0) as u64,
43 )
44}
45
46#[cfg(target_env = "msvc")]
47compile_error!("reifydb-allocator-jemalloc does not support MSVC; use the (Phase 2) mimalloc backend instead");