Skip to main content

reifydb_allocator_jemalloc/
lib.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2// Copyright (c) 2026 ReifyDB
3
4#![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(target_env = "msvc")]
34compile_error!("reifydb-allocator-jemalloc does not support MSVC; use the (Phase 2) mimalloc backend instead");