From 23690fd83788e113e801f6aee1cebb7d76e8346a Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 18 Aug 2024 17:36:33 -0400 Subject: [PATCH] make jemalloc stats an optional feature Signed-off-by: strawberry --- Cargo.toml | 6 +++--- nix/pkgs/main/default.nix | 4 +++- src/core/Cargo.toml | 5 +++++ src/core/alloc/je.rs | 7 ++++++- src/main/Cargo.toml | 3 +++ 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6d008896..6f4ada7c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -400,17 +400,17 @@ version = "0.34.0" git = "https://github.com/girlbossceo/jemallocator" rev = "c32af15f3b440ae5e46c3404f78b19093bbd5294" default-features = false -features = ["stats", "unprefixed_malloc_on_supported_platforms"] +features = ["unprefixed_malloc_on_supported_platforms"] [workspace.dependencies.tikv-jemallocator] git = "https://github.com/girlbossceo/jemallocator" rev = "c32af15f3b440ae5e46c3404f78b19093bbd5294" default-features = false -features = ["stats", "unprefixed_malloc_on_supported_platforms"] +features = ["unprefixed_malloc_on_supported_platforms"] [workspace.dependencies.tikv-jemalloc-ctl] git = "https://github.com/girlbossceo/jemallocator" rev = "c32af15f3b440ae5e46c3404f78b19093bbd5294" default-features = false -features = ["stats", "use_std"] +features = ["use_std"] [workspace.dependencies.console-subscriber] version = "0.4" diff --git a/nix/pkgs/main/default.nix b/nix/pkgs/main/default.nix index 66d60b77..47b98432 100644 --- a/nix/pkgs/main/default.nix +++ b/nix/pkgs/main/default.nix @@ -57,7 +57,9 @@ rust-jemalloc-sys' = (rust-jemalloc-sys.override { # we dont need cxx/C++ integration [ "--disable-cxx" ] ++ # tikv-jemalloc-sys/profiling feature - lib.optional (featureEnabled "jemalloc_prof") "--enable-prof"; + lib.optional (featureEnabled "jemalloc_prof") "--enable-prof" ++ + # tikv-jemalloc-sys/stats feature + (if (featureEnabled "jemalloc_stats") then [ "--enable-stats" ] else [ "--disable-stats" ]); }); buildDepsOnlyEnv = diff --git a/src/core/Cargo.toml b/src/core/Cargo.toml index a5c379e9..87943e60 100644 --- a/src/core/Cargo.toml +++ b/src/core/Cargo.toml @@ -32,6 +32,11 @@ jemalloc = [ jemalloc_prof = [ "tikv-jemalloc-sys/profiling", ] +jemalloc_stats = [ + "tikv-jemalloc-sys/stats", + "tikv-jemalloc-ctl/stats", + "tikv-jemallocator/stats", +] hardened_malloc = [ "dep:hardened_malloc-rs" ] diff --git a/src/core/alloc/je.rs b/src/core/alloc/je.rs index 08bfc49a..7561eb95 100644 --- a/src/core/alloc/je.rs +++ b/src/core/alloc/je.rs @@ -2,7 +2,6 @@ use std::ffi::{c_char, c_void}; -use tikv_jemalloc_ctl as mallctl; use tikv_jemalloc_sys as ffi; use tikv_jemallocator as jemalloc; @@ -10,8 +9,10 @@ use tikv_jemallocator as jemalloc; static JEMALLOC: jemalloc::Jemalloc = jemalloc::Jemalloc; #[must_use] +#[cfg(feature = "jemalloc_stats")] pub fn memory_usage() -> Option { use mallctl::stats; + use tikv_jemalloc_ctl as mallctl; let mibs = |input: Result| { let input = input.unwrap_or_default(); @@ -33,6 +34,10 @@ pub fn memory_usage() -> Option { )) } +#[must_use] +#[cfg(not(feature = "jemalloc_stats"))] +pub fn memory_usage() -> Option { None } + #[must_use] pub fn memory_stats() -> Option { const MAX_LENGTH: usize = 65536 - 4096; diff --git a/src/main/Cargo.toml b/src/main/Cargo.toml index c002c125..424bfad7 100644 --- a/src/main/Cargo.toml +++ b/src/main/Cargo.toml @@ -87,6 +87,9 @@ jemalloc = [ jemalloc_prof = [ "conduit-core/jemalloc_prof", ] +jemalloc_stats = [ + "conduit-core/jemalloc_stats", +] perf_measurements = [ "dep:opentelemetry", "dep:tracing-flame",