Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ members = [
"polkadot/core-primitives",
"polkadot/erasure-coding",
"polkadot/erasure-coding/fuzzer",
"polkadot/jemalloc-shim",
"polkadot/node/collation-generation",
"polkadot/node/core/approval-voting",
"polkadot/node/core/approval-voting-parallel",
Expand Down Expand Up @@ -1115,6 +1116,7 @@ polkadot-core-primitives = { path = "polkadot/core-primitives", default-features
polkadot-dispute-distribution = { path = "polkadot/node/network/dispute-distribution", default-features = false }
polkadot-erasure-coding = { path = "polkadot/erasure-coding", default-features = false }
polkadot-gossip-support = { path = "polkadot/node/network/gossip-support", default-features = false }
polkadot-jemalloc-shim = { path = "polkadot/jemalloc-shim" }
polkadot-network-bridge = { path = "polkadot/node/network/bridge", default-features = false }
polkadot-node-collation-generation = { path = "polkadot/node/collation-generation", default-features = false }
polkadot-node-core-approval-voting = { path = "polkadot/node/core/approval-voting", default-features = false }
Expand Down
5 changes: 5 additions & 0 deletions cumulus/polkadot-omni-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ workspace = true
color-eyre = { workspace = true }

# Local
polkadot-jemalloc-shim = { workspace = true }
polkadot-omni-node-lib = { workspace = true, features = ["rococo-native", "westend-native"] }

[target.'cfg(target_os = "linux")'.dependencies]
polkadot-jemalloc-shim = { workspace = true, features = ["jemalloc-allocator"] }

[dev-dependencies]
assert_cmd = { workspace = true }

Expand All @@ -26,6 +30,7 @@ substrate-build-script-utils = { workspace = true, default-features = true }

[features]
default = []
jemalloc-allocator = ["polkadot-jemalloc-shim/jemalloc-allocator"]
runtime-benchmarks = [
"polkadot-omni-node-lib/runtime-benchmarks",
]
Expand Down
5 changes: 5 additions & 0 deletions cumulus/polkadot-parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,17 @@ sp-genesis-builder = { workspace = true, default-features = true }
sp-keyring = { workspace = true, default-features = true }

# Polkadot
polkadot-jemalloc-shim = { workspace = true }
xcm = { workspace = true, default-features = true }

# Cumulus
cumulus-client-consensus-aura = { workspace = true }
cumulus-primitives-core = { workspace = true, default-features = true }
yet-another-parachain-runtime = { workspace = true }

[target.'cfg(target_os = "linux")'.dependencies]
polkadot-jemalloc-shim = { workspace = true, features = ["jemalloc-allocator"] }

[dev-dependencies]
assert_cmd = { workspace = true }

Expand All @@ -63,6 +67,7 @@ substrate-build-script-utils = { workspace = true, default-features = true }

[features]
default = []
jemalloc-allocator = ["polkadot-jemalloc-shim/jemalloc-allocator"]
runtime-benchmarks = [
"cumulus-primitives-core/runtime-benchmarks",
"parachains-common/runtime-benchmarks",
Expand Down
12 changes: 3 additions & 9 deletions polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ path = "src/bin/prepare-worker.rs"

[dependencies]
color-eyre = { workspace = true }
tikv-jemallocator = { optional = true, features = ["unprefixed_malloc_on_supported_platforms"], workspace = true }
polkadot-jemalloc-shim = { workspace = true }

# Crates in our workspace, defined as dependencies so we can pass them feature flags.
polkadot-cli = { features = ["rococo-native", "westend-native"], workspace = true, default-features = true }
Expand All @@ -80,7 +80,7 @@ polkadot-node-core-pvf-common = { workspace = true, default-features = true }
polkadot-node-core-pvf-execute-worker = { workspace = true, default-features = true }

[target.'cfg(target_os = "linux")'.dependencies]
tikv-jemallocator = { workspace = true, features = ["unprefixed_malloc_on_supported_platforms"] }
polkadot-jemalloc-shim = { workspace = true, features = ["jemalloc-allocator"] }

[dev-dependencies]
assert_cmd = { workspace = true }
Expand All @@ -99,13 +99,7 @@ try-runtime = ["polkadot-cli/try-runtime"]
fast-runtime = ["polkadot-cli/fast-runtime"]
runtime-metrics = ["polkadot-cli/runtime-metrics"]
pyroscope = ["polkadot-cli/pyroscope"]
jemalloc-allocator = [
"dep:tikv-jemallocator",
"polkadot-cli/jemalloc-allocator",
"polkadot-node-core-pvf-prepare-worker/jemalloc-allocator",
"polkadot-node-core-pvf/jemalloc-allocator",
"polkadot-overseer/jemalloc-allocator",
]
jemalloc-allocator = ["polkadot-jemalloc-shim/jemalloc-allocator"]

# Generate the metadata hash needed for CheckMetadataHash
# in the builtin test runtimes (westend and rococo).
Expand Down
31 changes: 31 additions & 0 deletions polkadot/jemalloc-shim/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[package]
name = "polkadot-jemalloc-shim"
version = "1.0.0"
description = "Shim crate to enable jemalloc-allocator feature for polkadot crates and setting global allocator to jemalloc"
license.workspace = true
authors.workspace = true
edition.workspace = true
homepage.workspace = true
repository.workspace = true

[lints]
workspace = true

[package.metadata.polkadot-sdk]
exclude-from-umbrella = true

[dependencies]
polkadot-cli = { optional = true, workspace = true }
polkadot-node-core-pvf = { optional = true, workspace = true }
polkadot-node-core-pvf-prepare-worker = { optional = true, workspace = true }
polkadot-overseer = { optional = true, workspace = true }
tikv-jemallocator = { optional = true, features = ["unprefixed_malloc_on_supported_platforms"], workspace = true }

[features]
jemalloc-allocator = [
"dep:tikv-jemallocator",
"polkadot-cli/jemalloc-allocator",
"polkadot-node-core-pvf-prepare-worker/jemalloc-allocator",
"polkadot-node-core-pvf/jemalloc-allocator",
"polkadot-overseer/jemalloc-allocator",
]
26 changes: 26 additions & 0 deletions polkadot/jemalloc-shim/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

//! Shim crate to enable `jemalloc-allocator` feature for Polkadot crates.
//!
//! Because [there doesn't exist any easier way right now](https://github.com/rust-lang/cargo/issues/1197), we
//! need an entire crate to handle `jemalloc` enabling/disabling. This way we can enable it by
//! default on Linux, but have it optional on all other OSes.

/// Sets the global allocator to `jemalloc` when the feature is enabled.
#[cfg(feature = "jemalloc-allocator")]
#[global_allocator]
static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
3 changes: 3 additions & 0 deletions polkadot/node/core/pvf/execute-worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ repository.workspace = true
[lints]
workspace = true

[package.metadata.polkadot-sdk]
exclude-from-umbrella = true

[dependencies]
cfg-if = { workspace = true }
cpu-time = { workspace = true }
Expand Down
3 changes: 3 additions & 0 deletions polkadot/node/core/pvf/prepare-worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ repository.workspace = true
[lints]
workspace = true

[package.metadata.polkadot-sdk]
exclude-from-umbrella = true

[[bench]]
name = "prepare_rococo_runtime"
harness = false
Expand Down
6 changes: 0 additions & 6 deletions polkadot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@

use color_eyre::eyre;

/// Global allocator. Changing it to another allocator will require changing
/// `memory_stats::MemoryAllocationTracker`.
#[cfg(any(target_os = "linux", feature = "jemalloc-allocator"))]
#[global_allocator]
static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;

fn main() -> eyre::Result<()> {
color_eyre::install()?;
polkadot_cli::run()?;
Expand Down
10 changes: 10 additions & 0 deletions prdoc/pr_10709.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title: Introduce a "jemalloc-shim" crate
doc:
- audience: Node Operator
description: |-
This crate basically serves as a hack to properly enable `jemalloc` on Linux and disable it on all other OSes by default.
crates:
- name: polkadot
bump: patch
- name: polkadot-jemalloc-shim
bump: patch
12 changes: 0 additions & 12 deletions umbrella/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -912,8 +912,6 @@ node = [
"polkadot-node-core-pvf",
"polkadot-node-core-pvf-checker",
"polkadot-node-core-pvf-common",
"polkadot-node-core-pvf-execute-worker",
"polkadot-node-core-pvf-prepare-worker",
"polkadot-node-core-runtime-api",
"polkadot-node-metrics",
"polkadot-node-network-protocol",
Expand Down Expand Up @@ -2472,16 +2470,6 @@ default-features = false
optional = true
path = "../polkadot/node/core/pvf/common"

[dependencies.polkadot-node-core-pvf-execute-worker]
default-features = false
optional = true
path = "../polkadot/node/core/pvf/execute-worker"

[dependencies.polkadot-node-core-pvf-prepare-worker]
default-features = false
optional = true
path = "../polkadot/node/core/pvf/prepare-worker"

[dependencies.polkadot-node-core-runtime-api]
default-features = false
optional = true
Expand Down
10 changes: 0 additions & 10 deletions umbrella/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -942,16 +942,6 @@ pub use polkadot_node_core_pvf_checker;
#[cfg(feature = "polkadot-node-core-pvf-common")]
pub use polkadot_node_core_pvf_common;

/// Polkadot crate that contains the logic for executing PVFs. Used by the
/// polkadot-execute-worker binary.
#[cfg(feature = "polkadot-node-core-pvf-execute-worker")]
pub use polkadot_node_core_pvf_execute_worker;

/// Polkadot crate that contains the logic for preparing PVFs. Used by the
/// polkadot-prepare-worker binary.
#[cfg(feature = "polkadot-node-core-pvf-prepare-worker")]
pub use polkadot_node_core_pvf_prepare_worker;

/// Wrapper around the parachain-related runtime APIs.
#[cfg(feature = "polkadot-node-core-runtime-api")]
pub use polkadot_node_core_runtime_api;
Expand Down
Loading