Skip to content

Commit

Permalink
Jemalloc by default
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhauner committed Feb 24, 2021
1 parent 88e54ab commit 345802f
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ BUILD_PATH_AARCH64 = "target/$(AARCH64_TAG)/release"
# Binaries will most likely be found in `./target/release`
install:
ifeq ($(PORTABLE), true)
cargo install --path lighthouse --force --locked --features portable,jemalloc
cargo install --path lighthouse --force --locked --features portable
else
cargo install --path lighthouse --force --locked --features jemalloc
cargo install --path lighthouse --force --locked
endif

# Builds the lcli binary in release (optimized).
Expand Down
3 changes: 2 additions & 1 deletion beacon_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ node_test_rig = { path = "../testing/node_test_rig" }

[features]
write_ssz_files = ["beacon_chain/write_ssz_files"] # Writes debugging .ssz files to /tmp during block processing.
jemalloc = ["client/jemalloc"]
# Use the system allocator instead of jemalloc. This replicates default Rust behaviour.
sysalloc = ["client/sysalloc"]

[dependencies]
eth2_config = { path = "../common/eth2_config" }
Expand Down
3 changes: 2 additions & 1 deletion beacon_node/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ slasher = { path = "../../slasher" }
slasher_service = { path = "../../slasher/service" }

[features]
jemalloc = ["http_metrics/jemalloc"]
# Use the system allocator instead of jemalloc. This replicates default Rust behaviour.
sysalloc = ["http_metrics/sysalloc"]
3 changes: 2 additions & 1 deletion beacon_node/http_metrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ environment = { path = "../../lighthouse/environment" }
types = { path = "../../consensus/types" }

[features]
jemalloc = ["warp_utils/jemalloc"]
# Use the system allocator instead of jemalloc. This replicates default Rust behaviour.
sysalloc = ["warp_utils/sysalloc"]
5 changes: 3 additions & 2 deletions common/warp_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ tokio = { version = "1.1.0", features = ["sync"] }
headers = "0.3.2"
lighthouse_metrics = { path = "../lighthouse_metrics" }
lazy_static = "1.4.0"
jemalloc-ctl = { version = "0.3.3", optional = true }
jemalloc-ctl = { version = "0.3.3" }

[features]
jemalloc = ["jemalloc-ctl"]
# Use the system allocator instead of jemalloc. This replicates default Rust behaviour.
sysalloc = []
6 changes: 3 additions & 3 deletions common/warp_utils/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use eth2::lighthouse::Health;
use lighthouse_metrics::*;

#[cfg(feature = "jemalloc")]
#[cfg(not(feature = "sysalloc"))]
use jemalloc_ctl::{arenas, epoch, stats};

lazy_static::lazy_static! {
Expand Down Expand Up @@ -83,7 +83,7 @@ pub fn scrape_health_metrics() {
scrape_jemalloc_metrics();
}

#[cfg(feature = "jemalloc")]
#[cfg(not(feature = "sysalloc"))]
pub fn scrape_jemalloc_metrics() {
if epoch::advance().is_ok() {
if let Ok(allocated) = stats::allocated::read() {
Expand All @@ -110,7 +110,7 @@ pub fn scrape_jemalloc_metrics() {
}
}

#[cfg(not(feature = "jemalloc"))]
#[cfg(feature = "sysalloc")]
pub fn scrape_jemalloc_metrics() {
// NO OP
}
11 changes: 5 additions & 6 deletions lighthouse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ authors = ["Sigma Prime <[email protected]>"]
edition = "2018"

[features]
default = ["jemalloc"]
# Writes debugging .ssz files to /tmp during block processing.
write_ssz_files = ["beacon_node/write_ssz_files"]
# Compiles the BLS crypto code so that the binary is portable across machines.
Expand All @@ -18,8 +17,8 @@ milagro = ["bls/milagro"]
spec-minimal = []
# Support spec v0.12 (used by Medalla testnet).
spec-v12 = []
# Use jemalloc as the global allocator
jemalloc = ["beacon_node/jemalloc", "jemallocator", "libc", "jemalloc-sys"]
# Use the system allocator instead of jemalloc. This replicates default Rust behaviour.
sysalloc = ["beacon_node/sysalloc"]

[dependencies]
beacon_node = { "path" = "../beacon_node" }
Expand All @@ -44,9 +43,9 @@ directory = { path = "../common/directory" }
lighthouse_version = { path = "../common/lighthouse_version" }
account_utils = { path = "../common/account_utils" }
remote_signer = { "path" = "../remote_signer" }
jemallocator = { version = "0.3.2", optional = true }
jemalloc-sys = { version = "0.3.2", optional = true }
libc = { version = "0.2.86", optional = true }
jemallocator = { version = "0.3.2" }
jemalloc-sys = { version = "0.3.2" }
libc = { version = "0.2.86" }

[dev-dependencies]
tempfile = "3.1.0"
Expand Down
5 changes: 3 additions & 2 deletions lighthouse/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ use types::{EthSpec, EthSpecId};
use validator_client::ProductionValidatorClient;

/// Global allocator
#[cfg(feature = "jemalloc")]
#[cfg(not(feature = "sysalloc"))]
#[global_allocator]
pub static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;

#[cfg(not(feature = "sysalloc"))]
union U {
x: &'static u8,
y: &'static libc::c_char,
}

#[cfg(feature = "jemalloc")]
#[cfg(not(feature = "sysalloc"))]
#[allow(non_upper_case_globals)]
#[export_name = "_rjem_malloc_conf"]
pub static malloc_conf: Option<&'static libc::c_char> = Some(unsafe {
Expand Down

0 comments on commit 345802f

Please sign in to comment.