diff --git a/Cargo.lock b/Cargo.lock index f250fd2ff25b..dd60250b5431 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12326,6 +12326,7 @@ dependencies = [ "sp-maybe-compressed-blob", "sp-tracing", "tikv-jemalloc-ctl", + "tikv-jemallocator", "tokio", "tracing-gum", "tracking-allocator", @@ -19159,9 +19160,6 @@ dependencies = [ [[package]] name = "tracking-allocator" version = "1.0.0" -dependencies = [ - "tikv-jemallocator", -] [[package]] name = "trie-bench" diff --git a/polkadot/node/core/pvf/prepare-worker/Cargo.toml b/polkadot/node/core/pvf/prepare-worker/Cargo.toml index f52798780f46..0721ae9c475c 100644 --- a/polkadot/node/core/pvf/prepare-worker/Cargo.toml +++ b/polkadot/node/core/pvf/prepare-worker/Cargo.toml @@ -14,6 +14,7 @@ rayon = "1.5.1" tikv-jemalloc-ctl = { version = "0.5.0", optional = true } tokio = { version = "1.24.2", features = ["fs", "process"] } tracking-allocator = { path = "../../../tracking-allocator", optional = true } +tikv-jemallocator = { version = "0.5.0", optional = true } parity-scale-codec = { version = "3.6.1", default-features = false, features = ["derive"] } @@ -34,7 +35,7 @@ tikv-jemalloc-ctl = "0.5.0" [features] builder = [] jemalloc-allocator = ["dep:tikv-jemalloc-ctl"] -tracking-allocator = ["dep:tracking-allocator"] +tracking-allocator = ["dep:tracking-allocator", "dep:tikv-jemallocator"] [dev-dependencies] criterion = { version = "0.4.0", default-features = false, features = ["cargo_bench_support"] } diff --git a/polkadot/node/core/pvf/prepare-worker/src/lib.rs b/polkadot/node/core/pvf/prepare-worker/src/lib.rs index ac116cf78631..43b7e60220e8 100644 --- a/polkadot/node/core/pvf/prepare-worker/src/lib.rs +++ b/polkadot/node/core/pvf/prepare-worker/src/lib.rs @@ -52,8 +52,14 @@ use std::{ time::Duration, }; use tokio::{io, net::UnixStream}; + +#[cfg(feature = "tracking-allocator")] +use tikv_jemallocator::Jemalloc; +#[cfg(feature = "tracking-allocator")] +use tracking_allocator::TrackingAllocator; #[cfg(feature = "tracking-allocator")] -use tracking_allocator::ALLOC; +#[global_allocator] +static ALLOC: TrackingAllocator = TrackingAllocator(Jemalloc); /// Contains the bytes for a successfully compiled artifact. pub struct CompiledArtifact(Vec); diff --git a/polkadot/node/tracking-allocator/Cargo.toml b/polkadot/node/tracking-allocator/Cargo.toml index 81f95b923398..0edbb5fcc741 100644 --- a/polkadot/node/tracking-allocator/Cargo.toml +++ b/polkadot/node/tracking-allocator/Cargo.toml @@ -4,6 +4,3 @@ description = "Tracking allocator to control amount of memory consumed by PVF pr version.workspace = true authors.workspace = true edition.workspace = true - -[dependencies] -tikv-jemallocator = "0.5.0" diff --git a/polkadot/node/tracking-allocator/src/lib.rs b/polkadot/node/tracking-allocator/src/lib.rs index 5b51f26184ab..40d0022803f6 100644 --- a/polkadot/node/tracking-allocator/src/lib.rs +++ b/polkadot/node/tracking-allocator/src/lib.rs @@ -18,7 +18,6 @@ use core::alloc::{GlobalAlloc, Layout}; use std::sync::atomic::{AtomicBool, Ordering}; -use tikv_jemallocator::Jemalloc; struct TrackingAllocatorData { lock: AtomicBool, @@ -82,7 +81,7 @@ impl TrackingAllocatorData { static mut ALLOCATOR_DATA: TrackingAllocatorData = TrackingAllocatorData { lock: AtomicBool::new(false), current: 0, peak: 0 }; -pub struct TrackingAllocator(A); +pub struct TrackingAllocator(pub A); impl TrackingAllocator { // SAFETY: @@ -131,6 +130,3 @@ unsafe impl GlobalAlloc for TrackingAllocator { self.0.realloc(ptr, layout, new_size) } } - -#[global_allocator] -pub static ALLOC: TrackingAllocator = TrackingAllocator(Jemalloc);