diff --git a/Cargo.lock b/Cargo.lock index 7659f5670a3..d2b13985de2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2292,6 +2292,12 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "fs_extra" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394" + [[package]] name = "fuchsia-zircon" version = "0.3.3" @@ -3174,6 +3180,38 @@ version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" +[[package]] +name = "jemalloc-ctl" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c502a5ff9dd2924f1ed32ba96e3b65735d837b4bfd978d3161b1702e66aca4b7" +dependencies = [ + "jemalloc-sys", + "libc", + "paste", +] + +[[package]] +name = "jemalloc-sys" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d3b9f3f5c9b31aa0f5ed3260385ac205db665baa41d49bb8338008ae94ede45" +dependencies = [ + "cc", + "fs_extra", + "libc", +] + +[[package]] +name = "jemallocator" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43ae63fcfc45e99ab3d1b29a46782ad679e98436c3169d15a167a1108a724b69" +dependencies = [ + "jemalloc-sys", + "libc", +] + [[package]] name = "js-sys" version = "0.3.46" @@ -3338,9 +3376,9 @@ checksum = "66189c12161c65c0023ceb53e2fccc0013311bcb36a7cbd0f9c5e938b408ac96" [[package]] name = "libc" -version = "0.2.82" +version = "0.2.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89203f3fba0a3795506acaad8ebce3c80c0af93f994d5a1d7a0b1eeb23271929" +checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c" [[package]] name = "libflate" @@ -3662,6 +3700,9 @@ dependencies = [ "environment", "eth2_network_config", "futures 0.3.12", + "jemalloc-sys", + "jemallocator", + "libc", "lighthouse_version", "logging", "remote_signer", @@ -4402,6 +4443,25 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "paste" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45ca20c77d80be666aef2b45486da86238fabe33e38306bd3118fe4af33fa880" +dependencies = [ + "paste-impl", + "proc-macro-hack", +] + +[[package]] +name = "paste-impl" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d95a7db200b97ef370c8e6de0088252f7e0dfff7d047a28528e47456c0fc98b6" +dependencies = [ + "proc-macro-hack", +] + [[package]] name = "pbkdf2" version = "0.4.0" @@ -7114,6 +7174,7 @@ dependencies = [ "beacon_chain", "eth2", "headers", + "jemalloc-ctl", "lazy_static", "lighthouse_metrics", "safe_arith", diff --git a/lighthouse/Cargo.toml b/lighthouse/Cargo.toml index c0daf4455dd..09bf5246de4 100644 --- a/lighthouse/Cargo.toml +++ b/lighthouse/Cargo.toml @@ -5,6 +5,7 @@ authors = ["Sigma Prime "] 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. @@ -18,7 +19,7 @@ spec-minimal = [] # Support spec v0.12 (used by Medalla testnet). spec-v12 = [] # Use jemalloc as the global allocator -jemalloc = ["environment/jemalloc", "beacon_node/jemalloc"] +jemalloc = ["beacon_node/jemalloc", "jemallocator", "libc", "jemalloc-sys"] [dependencies] beacon_node = { "path" = "../beacon_node" } @@ -43,6 +44,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 } [dev-dependencies] tempfile = "3.1.0" diff --git a/lighthouse/environment/Cargo.toml b/lighthouse/environment/Cargo.toml index ed866a000c1..6e0556a6d2d 100644 --- a/lighthouse/environment/Cargo.toml +++ b/lighthouse/environment/Cargo.toml @@ -20,7 +20,3 @@ futures = "0.3.7" parking_lot = "0.11.0" slog-json = "2.3.0" exit-future = "0.2.0" -jemallocator = { version = "0.3.2", optional = true } - -[features] -jemalloc = ["jemallocator"] diff --git a/lighthouse/environment/src/lib.rs b/lighthouse/environment/src/lib.rs index 69ea757de53..fee7369ac39 100644 --- a/lighthouse/environment/src/lib.rs +++ b/lighthouse/environment/src/lib.rs @@ -27,11 +27,6 @@ use task_executor::TaskExecutor; use tokio::runtime::{Builder as RuntimeBuilder, Runtime}; use types::{EthSpec, MainnetEthSpec, MinimalEthSpec, V012LegacyEthSpec}; -/// Global allocator -#[cfg(feature = "jemalloc")] -#[global_allocator] -pub static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; - pub const ETH2_CONFIG_FILENAME: &str = "eth2-spec.toml"; const LOG_CHANNEL_SIZE: usize = 2048; /// The maximum time in seconds the client will wait for all internal tasks to shutdown. diff --git a/lighthouse/src/main.rs b/lighthouse/src/main.rs index 53f3f2c1058..75e806e8a35 100644 --- a/lighthouse/src/main.rs +++ b/lighthouse/src/main.rs @@ -10,6 +10,27 @@ use std::process::exit; use types::{EthSpec, EthSpecId}; use validator_client::ProductionValidatorClient; +/// Global allocator +#[cfg(feature = "jemalloc")] +#[global_allocator] +pub static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; + +union U { + x: &'static u8, + y: &'static libc::c_char, +} + +#[cfg(feature = "jemalloc")] +#[allow(non_upper_case_globals)] +#[cfg_attr(prefixed, export_name = "_rjem_malloc_conf")] +#[cfg_attr(not(prefixed), no_mangle)] +pub static malloc_conf: Option<&'static libc::c_char> = Some(unsafe { + U { + x: &b"narenas:1\0"[0], + } + .y +}); + pub const ETH2_CONFIG_FILENAME: &str = "eth2-spec.toml"; fn bls_library_name() -> &'static str {