Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
13 changes: 12 additions & 1 deletion 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
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
28 changes: 28 additions & 0 deletions polkadot/jemalloc-shim/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "polkadot-jemalloc-shim"
version = "1.0.0"
description = "Shim crate to enable jemalloc-allocator feature for polkadot crates"
license.workspace = true
authors.workspace = true
edition.workspace = true
homepage.workspace = true
repository.workspace = true

[lints]
workspace = 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;
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
Loading