Make it possible to opt-out jemalloc for heaptrack (#14634)
This commit is contained in:
parent
fa53f0293d
commit
d63b2baf0e
|
@ -19,5 +19,12 @@ solana-metrics = { path = "../metrics", version = "1.6.0" }
|
|||
jemallocator = "0.3.2"
|
||||
jemalloc-ctl = "0.3.2"
|
||||
|
||||
[features]
|
||||
# mainly for heaptrack, which seems to be incompatible with jemalloc
|
||||
# opt-out ("no-" prefix) is chosen for convenience for the default case
|
||||
# (= with jemalloc), considering complexies of proper opt-in (default)
|
||||
# feature plumbing
|
||||
no-jemalloc = []
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
|
|
@ -4,6 +4,7 @@ pub mod thread_mem_usage;
|
|||
#[cfg(unix)]
|
||||
extern crate jemallocator;
|
||||
|
||||
#[cfg(not(feature = "no-jemalloc"))]
|
||||
#[cfg(unix)]
|
||||
#[global_allocator]
|
||||
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#[cfg(not(feature = "no-jemalloc"))]
|
||||
#[cfg(unix)]
|
||||
use jemalloc_ctl::thread;
|
||||
|
||||
pub fn datapoint(_name: &'static str) {
|
||||
#[cfg(not(feature = "no-jemalloc"))]
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let allocated = thread::allocatedp::mib().unwrap();
|
||||
|
@ -12,29 +14,32 @@ pub fn datapoint(_name: &'static str) {
|
|||
}
|
||||
|
||||
pub struct Allocatedp {
|
||||
#[cfg(not(feature = "no-jemalloc"))]
|
||||
#[cfg(unix)]
|
||||
allocated: thread::ThreadLocal<u64>,
|
||||
}
|
||||
|
||||
impl Allocatedp {
|
||||
pub fn default() -> Self {
|
||||
#[cfg(not(feature = "no-jemalloc"))]
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let allocated = thread::allocatedp::mib().unwrap();
|
||||
let allocated = allocated.read().unwrap();
|
||||
Self { allocated }
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
#[cfg(any(feature = "no-jemalloc", not(unix)))]
|
||||
Self {}
|
||||
}
|
||||
|
||||
/// Return current thread heap usage
|
||||
pub fn get(&self) -> u64 {
|
||||
#[cfg(not(feature = "no-jemalloc"))]
|
||||
#[cfg(unix)]
|
||||
{
|
||||
self.allocated.get()
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
#[cfg(any(feature = "no-jemalloc", not(unix)))]
|
||||
0
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue