From 0bd41f98ed678388f45fc15978b9764888d595c2 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Thu, 21 Nov 2019 19:39:29 -0700 Subject: [PATCH] Avoid jemalloc in windows build (#7089) automerge --- core/Cargo.toml | 2 ++ core/src/cluster_info.rs | 4 +--- core/src/lib.rs | 2 ++ core/src/replay_stage.rs | 4 +--- core/src/thread_mem_usage.rs | 42 ++++++++++++++++++++++++++++++------ 5 files changed, 42 insertions(+), 12 deletions(-) diff --git a/core/Cargo.toml b/core/Cargo.toml index a2dcd9887..c42652c9d 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -70,6 +70,8 @@ tokio-io = "0.1" untrusted = "0.7.0" solana-rayon-threadlimit = { path = "../rayon-threadlimit", version = "0.21.0" } reed-solomon-erasure = { package = "solana-reed-solomon-erasure", version = "4.0.1-3", features = ["simd-accel"] } + +[target."cfg(unix)".dependencies] jemallocator = "0.3.2" jemalloc-ctl = "0.3.2" diff --git a/core/src/cluster_info.rs b/core/src/cluster_info.rs index 2741fff68..11c7f759e 100644 --- a/core/src/cluster_info.rs +++ b/core/src/cluster_info.rs @@ -30,7 +30,6 @@ use crate::{ use bincode::{serialize, serialized_size}; use core::cmp; use itertools::Itertools; -use jemalloc_ctl::thread::allocatedp; use rand::{thread_rng, Rng}; use solana_ledger::{bank_forks::BankForks, blocktree::Blocktree, staking_utils}; use solana_metrics::{datapoint_debug, inc_new_counter_debug, inc_new_counter_error}; @@ -1221,8 +1220,7 @@ impl ClusterInfo { response_sender: &PacketSender, ) { // iter over the packets, collect pulls separately and process everything else - let allocated = allocatedp::mib().unwrap(); - let allocated = allocated.read().unwrap(); + let allocated = thread_mem_usage::Allocatedp::default(); let mut gossip_pull_data: Vec = vec![]; packets.packets.iter().for_each(|packet| { let from_addr = packet.meta.addr(); diff --git a/core/src/lib.rs b/core/src/lib.rs index 068401271..febbb40b6 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -85,7 +85,9 @@ extern crate solana_metrics; #[macro_use] extern crate matches; +#[cfg(unix)] extern crate jemallocator; +#[cfg(unix)] #[global_allocator] static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; diff --git a/core/src/replay_stage.rs b/core/src/replay_stage.rs index a6f61661a..d5a552619 100644 --- a/core/src/replay_stage.rs +++ b/core/src/replay_stage.rs @@ -9,7 +9,6 @@ use crate::{ rpc_subscriptions::RpcSubscriptions, thread_mem_usage, }; -use jemalloc_ctl::thread::allocatedp; use solana_ledger::{ bank_forks::BankForks, block_error::BlockError, @@ -220,8 +219,7 @@ impl ReplayStage { let mut last_reset = Hash::default(); let mut partition = false; loop { - let allocated = allocatedp::mib().unwrap(); - let allocated = allocated.read().unwrap(); + let allocated = thread_mem_usage::Allocatedp::default(); thread_mem_usage::datapoint("solana-replay-stage"); let now = Instant::now(); diff --git a/core/src/thread_mem_usage.rs b/core/src/thread_mem_usage.rs index c1f57e6c1..07ac1a5ec 100644 --- a/core/src/thread_mem_usage.rs +++ b/core/src/thread_mem_usage.rs @@ -1,9 +1,39 @@ +#[cfg(unix)] use jemalloc_ctl::thread; -use solana_metrics::datapoint_debug; -pub fn datapoint(name: &'static str) { - let allocated = thread::allocatedp::mib().unwrap(); - let allocated = allocated.read().unwrap(); - let mem = allocated.get(); - datapoint_debug!("thread-memory", (name, mem as i64, i64)); +pub fn datapoint(_name: &'static str) { + #[cfg(unix)] + { + let allocated = thread::allocatedp::mib().unwrap(); + let allocated = allocated.read().unwrap(); + let mem = allocated.get(); + solana_metrics::datapoint_debug!("thread-memory", (_name, mem as i64, i64)); + } +} + +pub struct Allocatedp { + #[cfg(unix)] + allocated: thread::ThreadLocal, +} + +impl Allocatedp { + pub fn default() -> Self { + #[cfg(unix)] + { + let allocated = thread::allocatedp::mib().unwrap(); + let allocated = allocated.read().unwrap(); + Self { allocated } + } + #[cfg(not(unix))] + Self {} + } + + pub fn get(&self) -> u64 { + #[cfg(unix)] + { + self.allocated.get() + } + #[cfg(not(unix))] + 0 + } }