Make it possible to opt-out jemalloc for heaptrack (#14634)

This commit is contained in:
Ryo Onodera 2021-01-18 20:58:52 +09:00 committed by GitHub
parent fa53f0293d
commit d63b2baf0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 2 deletions

View File

@ -19,5 +19,12 @@ solana-metrics = { path = "../metrics", version = "1.6.0" }
jemallocator = "0.3.2" jemallocator = "0.3.2"
jemalloc-ctl = "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] [package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"] targets = ["x86_64-unknown-linux-gnu"]

View File

@ -4,6 +4,7 @@ pub mod thread_mem_usage;
#[cfg(unix)] #[cfg(unix)]
extern crate jemallocator; extern crate jemallocator;
#[cfg(not(feature = "no-jemalloc"))]
#[cfg(unix)] #[cfg(unix)]
#[global_allocator] #[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;

View File

@ -1,7 +1,9 @@
#[cfg(not(feature = "no-jemalloc"))]
#[cfg(unix)] #[cfg(unix)]
use jemalloc_ctl::thread; use jemalloc_ctl::thread;
pub fn datapoint(_name: &'static str) { pub fn datapoint(_name: &'static str) {
#[cfg(not(feature = "no-jemalloc"))]
#[cfg(unix)] #[cfg(unix)]
{ {
let allocated = thread::allocatedp::mib().unwrap(); let allocated = thread::allocatedp::mib().unwrap();
@ -12,29 +14,32 @@ pub fn datapoint(_name: &'static str) {
} }
pub struct Allocatedp { pub struct Allocatedp {
#[cfg(not(feature = "no-jemalloc"))]
#[cfg(unix)] #[cfg(unix)]
allocated: thread::ThreadLocal<u64>, allocated: thread::ThreadLocal<u64>,
} }
impl Allocatedp { impl Allocatedp {
pub fn default() -> Self { pub fn default() -> Self {
#[cfg(not(feature = "no-jemalloc"))]
#[cfg(unix)] #[cfg(unix)]
{ {
let allocated = thread::allocatedp::mib().unwrap(); let allocated = thread::allocatedp::mib().unwrap();
let allocated = allocated.read().unwrap(); let allocated = allocated.read().unwrap();
Self { allocated } Self { allocated }
} }
#[cfg(not(unix))] #[cfg(any(feature = "no-jemalloc", not(unix)))]
Self {} Self {}
} }
/// Return current thread heap usage /// Return current thread heap usage
pub fn get(&self) -> u64 { pub fn get(&self) -> u64 {
#[cfg(not(feature = "no-jemalloc"))]
#[cfg(unix)] #[cfg(unix)]
{ {
self.allocated.get() self.allocated.get()
} }
#[cfg(not(unix))] #[cfg(any(feature = "no-jemalloc", not(unix)))]
0 0
} }