Skip to content

Commit

Permalink
Set jemalloc as default, configure arenas
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhauner committed Feb 16, 2021
1 parent 4331ef8 commit 42eb539
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 12 deletions.
65 changes: 63 additions & 2 deletions Cargo.lock

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

6 changes: 5 additions & 1 deletion lighthouse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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,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" }
Expand All @@ -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"
Expand Down
4 changes: 0 additions & 4 deletions lighthouse/environment/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
5 changes: 0 additions & 5 deletions lighthouse/environment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 21 additions & 0 deletions lighthouse/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 42eb539

Please sign in to comment.