Skip to content

Commit

Permalink
fix: enable jemalloc-based memory control on macOS as well (#12625)
Browse files Browse the repository at this point in the history
  • Loading branch information
fuyufjh authored Oct 5, 2023
1 parent 8195963 commit e53c9f7
Show file tree
Hide file tree
Showing 25 changed files with 48 additions and 66 deletions.
3 changes: 3 additions & 0 deletions .config/hakari.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ workspace-members = [
]
third-party = [
{ name = "opendal" },
# For some reasons, tikv-jemalloc-sys would be compiled twice if being added into `workspace-hack`
{ name = "tikv-jemalloc-sys", git = "https://github.com/risingwavelabs/jemallocator.git", rev = "64a2d9" },
{ name = "tikv-jemallocator", git = "https://github.com/risingwavelabs/jemallocator.git", rev = "64a2d9" },
# These are solely dev-dependencies. Unifying them may slow down build.
{ name = "criterion" },
{ name = "console" },
Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ arrow-buffer = "46"
arrow-flight = "46"
arrow-select = "46"
arrow-ord = "46"
tikv-jemalloc-ctl = { git = "https://github.com/risingwavelabs/jemallocator.git", rev = "64a2d9" }
tikv-jemallocator = { git = "https://github.com/risingwavelabs/jemallocator.git", features = [
"profiling",
"stats",
Expand Down
2 changes: 0 additions & 2 deletions src/batch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ criterion = { workspace = true, features = ["async_tokio", "async"] }
rand = "0.8"
risingwave_expr_impl = { workspace = true }
tempfile = "3"

[target.'cfg(unix)'.dev-dependencies]
tikv-jemallocator = { workspace = true }

[[bench]]
Expand Down
4 changes: 2 additions & 2 deletions src/batch/benches/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ pub mod utils;

use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion};
use risingwave_batch::executor::{BoxedExecutor, ExpandExecutor};
use risingwave_common::enable_jemalloc_on_unix;
use risingwave_common::enable_jemalloc;
use risingwave_common::types::DataType;
use tokio::runtime::Runtime;
use utils::{create_input, execute_executor};

enable_jemalloc_on_unix!();
enable_jemalloc!();

fn create_expand_executor(
column_subsets: Vec<Vec<usize>>,
Expand Down
4 changes: 2 additions & 2 deletions src/batch/benches/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ pub mod utils;

use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion};
use risingwave_batch::executor::{BoxedExecutor, FilterExecutor};
use risingwave_common::enable_jemalloc_on_unix;
use risingwave_common::enable_jemalloc;
use risingwave_common::types::DataType;
use risingwave_expr::expr::build_from_pretty;
use tokio::runtime::Runtime;
use utils::{create_input, execute_executor};

enable_jemalloc_on_unix!();
enable_jemalloc!();

fn create_filter_executor(chunk_size: usize, chunk_num: usize) -> BoxedExecutor {
const CHUNK_SIZE: usize = 1024;
Expand Down
4 changes: 2 additions & 2 deletions src/batch/benches/hash_agg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ use risingwave_batch::task::ShutdownToken;
use risingwave_common::catalog::{Field, Schema};
use risingwave_common::memory::MemoryContext;
use risingwave_common::types::DataType;
use risingwave_common::{enable_jemalloc_on_unix, hash};
use risingwave_common::{enable_jemalloc, hash};
use risingwave_expr::aggregate::{AggCall, AggKind};
use risingwave_pb::expr::{PbAggCall, PbInputRef};
use tokio::runtime::Runtime;
use utils::{create_input, execute_executor};

enable_jemalloc_on_unix!();
enable_jemalloc!();

fn create_agg_call(
input_schema: &Schema,
Expand Down
4 changes: 2 additions & 2 deletions src/batch/benches/hash_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ use risingwave_batch::task::ShutdownToken;
use risingwave_common::catalog::schema_test_utils::field_n;
use risingwave_common::memory::MemoryContext;
use risingwave_common::types::DataType;
use risingwave_common::{enable_jemalloc_on_unix, hash};
use risingwave_common::{enable_jemalloc, hash};
use risingwave_expr::expr::build_from_pretty;
use utils::bench_join;

enable_jemalloc_on_unix!();
enable_jemalloc!();

fn create_hash_join_executor(
join_type: JoinType,
Expand Down
4 changes: 2 additions & 2 deletions src/batch/benches/limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ pub mod utils;

use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion};
use risingwave_batch::executor::{BoxedExecutor, LimitExecutor};
use risingwave_common::enable_jemalloc_on_unix;
use risingwave_common::enable_jemalloc;
use risingwave_common::types::DataType;
use tokio::runtime::Runtime;
use utils::{create_input, execute_executor};

enable_jemalloc_on_unix!();
enable_jemalloc!();

fn create_limit_executor(
chunk_size: usize,
Expand Down
4 changes: 2 additions & 2 deletions src/batch/benches/nested_loop_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ pub mod utils;
use criterion::{criterion_group, criterion_main, Criterion};
use risingwave_batch::executor::{BoxedExecutor, JoinType, NestedLoopJoinExecutor};
use risingwave_batch::task::ShutdownToken;
use risingwave_common::enable_jemalloc_on_unix;
use risingwave_common::enable_jemalloc;
use risingwave_common::memory::MemoryContext;
use risingwave_common::types::DataType;
use risingwave_expr::expr::build_from_pretty;
use utils::{bench_join, create_input};

enable_jemalloc_on_unix!();
enable_jemalloc!();

fn create_nested_loop_join_executor(
join_type: JoinType,
Expand Down
4 changes: 2 additions & 2 deletions src/batch/benches/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ pub mod utils;

use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion};
use risingwave_batch::executor::{BoxedExecutor, SortExecutor};
use risingwave_common::enable_jemalloc_on_unix;
use risingwave_common::enable_jemalloc;
use risingwave_common::memory::MemoryContext;
use risingwave_common::types::DataType;
use risingwave_common::util::sort_util::{ColumnOrder, OrderType};
use tokio::runtime::Runtime;
use utils::{create_input, execute_executor};

enable_jemalloc_on_unix!();
enable_jemalloc!();

fn create_order_by_executor(
chunk_size: usize,
Expand Down
4 changes: 2 additions & 2 deletions src/batch/benches/top_n.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ pub mod utils;

use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion};
use risingwave_batch::executor::{BoxedExecutor, TopNExecutor};
use risingwave_common::enable_jemalloc_on_unix;
use risingwave_common::enable_jemalloc;
use risingwave_common::memory::MemoryContext;
use risingwave_common::types::DataType;
use risingwave_common::util::sort_util::{ColumnOrder, OrderType};
use tokio::runtime::Runtime;
use utils::{create_input, execute_executor};

enable_jemalloc_on_unix!();
enable_jemalloc!();

fn create_top_n_executor(
chunk_size: usize,
Expand Down
8 changes: 3 additions & 5 deletions src/cmd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ risingwave_expr_impl = { workspace = true }
risingwave_frontend = { workspace = true }
risingwave_meta = { workspace = true }
risingwave_rt = { workspace = true }
tikv-jemallocator = { workspace = true, features = [
"unprefixed_malloc_on_supported_platforms",
] }
tokio = { version = "0.2", package = "madsim-tokio", features = [
"rt",
"rt-multi-thread",
Expand All @@ -46,11 +49,6 @@ workspace-hack = { path = "../workspace-hack" }
[target.'cfg(enable_task_local_alloc)'.dependencies]
task_stats_alloc = { path = "../utils/task_stats_alloc" }

[target.'cfg(unix)'.dependencies]
tikv-jemallocator = { workspace = true, features = [
"unprefixed_malloc_on_supported_platforms",
] }

[[bin]]
name = "frontend"
path = "src/bin/frontend_node.rs"
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ use risingwave_rt::{init_risingwave_logger, main_okk, LoggerSettings};
macro_rules! main {
($component:ident) => {
#[cfg(enable_task_local_alloc)]
risingwave_common::enable_task_local_jemalloc_on_unix!();
risingwave_common::enable_task_local_jemalloc!();

#[cfg(not(enable_task_local_alloc))]
risingwave_common::enable_jemalloc_on_unix!();
risingwave_common::enable_jemalloc!();

#[cfg_attr(coverage, no_coverage)]
fn main() {
Expand Down
8 changes: 3 additions & 5 deletions src/cmd_all/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ shell-words = "1.1.0"
strum = "0.25"
strum_macros = "0.25"
tempfile = "3"
tikv-jemallocator = { workspace = true, features = [
"unprefixed_malloc_on_supported_platforms",
] }
tokio = { version = "0.2", package = "madsim-tokio", features = [
"rt",
"rt-multi-thread",
Expand All @@ -63,11 +66,6 @@ vergen = { version = "8", default-features = false, features = [
[target.'cfg(enable_task_local_alloc)'.dependencies]
task_stats_alloc = { path = "../utils/task_stats_alloc" }

[target.'cfg(unix)'.dependencies]
tikv-jemallocator = { workspace = true, features = [
"unprefixed_malloc_on_supported_platforms",
] }

[[bin]]
name = "risingwave"
path = "src/bin/risingwave.rs"
Expand Down
4 changes: 2 additions & 2 deletions src/cmd_all/src/bin/risingwave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ use strum_macros::{Display, EnumIter, EnumString, IntoStaticStr};
use tracing::Level;

#[cfg(enable_task_local_alloc)]
risingwave_common::enable_task_local_jemalloc_on_unix!();
risingwave_common::enable_task_local_jemalloc!();

#[cfg(not(enable_task_local_alloc))]
risingwave_common::enable_jemalloc_on_unix!();
risingwave_common::enable_jemalloc!();

const BINARY_NAME: &str = "risingwave";
const VERSION: &str = {
Expand Down
1 change: 0 additions & 1 deletion src/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ strum = "0.25"
strum_macros = "0.25"
sysinfo = { version = "0.29", default-features = false }
thiserror = "1"
tikv-jemalloc-ctl = { git = "https://github.com/risingwavelabs/jemallocator.git", rev = "64a2d9" }
tinyvec = { version = "1", features = ["rustc_1_55", "grab_spare_slice"] }
tokio = { version = "0.2", package = "madsim-tokio", features = [
"rt",
Expand Down
5 changes: 2 additions & 3 deletions src/common/src/jemalloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

/// If <https://github.com/tikv/jemallocator/issues/22> is resolved, we may inline this
#[macro_export]
macro_rules! enable_jemalloc_on_unix {
macro_rules! enable_jemalloc {
() => {
#[cfg(unix)]
#[global_allocator]
Expand All @@ -23,9 +23,8 @@ macro_rules! enable_jemalloc_on_unix {
}

#[macro_export]
macro_rules! enable_task_local_jemalloc_on_unix {
macro_rules! enable_task_local_jemalloc {
() => {
#[cfg(unix)]
#[global_allocator]
static GLOBAL: task_stats_alloc::TaskLocalAlloc<tikv_jemallocator::Jemalloc> =
task_stats_alloc::TaskLocalAlloc(tikv_jemallocator::Jemalloc);
Expand Down
4 changes: 1 addition & 3 deletions src/compute/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ risingwave_storage = { workspace = true }
risingwave_stream = { workspace = true }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tikv-jemalloc-ctl = { workspace = true }
tokio = { version = "0.2", package = "madsim-tokio", features = [
"rt",
"rt-multi-thread",
Expand All @@ -53,9 +54,6 @@ tonic = { workspace = true }
tower = { version = "0.4", features = ["util", "load-shed"] }
tracing = "0.1"

[target.'cfg(unix)'.dependencies]
tikv-jemalloc-ctl = { git = "https://github.com/risingwavelabs/jemallocator.git", rev = "64a2d9" }

[target.'cfg(not(madsim))'.dependencies]
workspace-hack = { path = "../workspace-hack" }

Expand Down
15 changes: 4 additions & 11 deletions src/compute/src/memory_management/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,10 @@ pub fn build_memory_control_policy(
) -> MemoryControlRef {
use self::policy::JemallocMemoryControl;

if cfg!(target_os = "linux") {
Box::new(JemallocMemoryControl::new(
total_memory_bytes,
heap_profiling_config,
))
} else {
// We disable memory control on operating systems other than Linux now because jemalloc
// stats do not work well.
tracing::warn!("memory control is only enabled on Linux now");
Box::new(DummyPolicy)
}
Box::new(JemallocMemoryControl::new(
total_memory_bytes,
heap_profiling_config,
))
}

/// `DummyPolicy` is used for operarting systems other than Linux. It does nothing as memory control
Expand Down
1 change: 1 addition & 0 deletions src/compute/src/rpc/service/monitor_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ impl MonitorService for MonitorServiceImpl {
tracing::warn!("Manually Jemalloc dump heap file failed! {:?}", e);
Err(Status::internal(e.to_string()))
} else {
tracing::info!("Manually Jemalloc dump heap file created: {}", &file_path);
Ok(Response::new(HeapProfilingResponse {}))
};
response
Expand Down
7 changes: 3 additions & 4 deletions src/risedevtool/src/task/compactor_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,9 @@ impl Task for CompactorService {

if crate::util::is_env_set("RISEDEV_ENABLE_HEAP_PROFILE") {
// See https://linux.die.net/man/3/jemalloc for the descriptions of profiling options
cmd.env(
"MALLOC_CONF",
"prof:true,lg_prof_interval:34,lg_prof_sample:19,prof_prefix:compactor",
);
let conf = "prof:true,lg_prof_interval:34,lg_prof_sample:19,prof_prefix:compactor";
cmd.env("_RJEM_MALLOC_CONF", conf); // prefixed for macos
cmd.env("MALLOC_CONF", conf); // unprefixed for linux
}

cmd.arg("--config-path")
Expand Down
7 changes: 3 additions & 4 deletions src/risedevtool/src/task/compute_node_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,9 @@ impl Task for ComputeNodeService {

if crate::util::is_env_set("RISEDEV_ENABLE_HEAP_PROFILE") {
// See https://linux.die.net/man/3/jemalloc for the descriptions of profiling options
cmd.env(
"MALLOC_CONF",
"prof:true,lg_prof_interval:34,lg_prof_sample:19,prof_prefix:compute-node",
);
let conf = "prof:true,lg_prof_interval:34,lg_prof_sample:19,prof_prefix:compute-node";
cmd.env("_RJEM_MALLOC_CONF", conf); // prefixed for macos
cmd.env("MALLOC_CONF", conf); // unprefixed for linux
}

cmd.arg("--config-path")
Expand Down
7 changes: 3 additions & 4 deletions src/risedevtool/src/task/meta_node_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,9 @@ impl Task for MetaNodeService {

if crate::util::is_env_set("RISEDEV_ENABLE_HEAP_PROFILE") {
// See https://linux.die.net/man/3/jemalloc for the descriptions of profiling options
cmd.env(
"MALLOC_CONF",
"prof:true,lg_prof_interval:32,lg_prof_sample:19,prof_prefix:meta-node",
);
let conf = "prof:true,lg_prof_interval:32,lg_prof_sample:19,prof_prefix:meta-node";
cmd.env("_RJEM_MALLOC_CONF", conf); // prefixed for macos
cmd.env("MALLOC_CONF", conf); // unprefixed for linux
}

Self::apply_command_args(&mut cmd, &self.config, HummockInMemoryStrategy::Isolated)?;
Expand Down
4 changes: 1 addition & 3 deletions src/tests/simulation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,12 @@ serde_derive = "1.0.188"
serde_json = "1.0.107"
sqllogictest = "0.17.0"
tempfile = "3"
tikv-jemallocator = { workspace = true }
tokio = { version = "0.2.23", package = "madsim-tokio" }
tokio-postgres = "0.7"
tokio-stream = "0.1"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

[target.'cfg(unix)'.dependencies]
tikv-jemallocator = { workspace = true }

[lints]
workspace = true

0 comments on commit e53c9f7

Please sign in to comment.