Skip to content

Commit

Permalink
enable jemalloc on macOS
Browse files Browse the repository at this point in the history
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
  • Loading branch information
BugenZhao committed Mar 21, 2023
1 parent 8c5489e commit 5901b96
Show file tree
Hide file tree
Showing 19 changed files with 38 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/batch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ criterion = { version = "0.4", features = ["async_tokio", "async"] }
rand = "0.8"
tempfile = "3"

[target.'cfg(target_os = "linux")'.dev-dependencies]
[target.'cfg(unix)'.dev-dependencies]
tikv-jemallocator = "0.5"

[[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_linux;
use risingwave_common::enable_jemalloc_on_unix;
use risingwave_common::types::DataType;
use tokio::runtime::Runtime;
use utils::{create_input, execute_executor};

enable_jemalloc_on_linux!();
enable_jemalloc_on_unix!();

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,7 +16,7 @@ pub mod utils;

use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion};
use risingwave_batch::executor::{BoxedExecutor, FilterExecutor};
use risingwave_common::enable_jemalloc_on_linux;
use risingwave_common::enable_jemalloc_on_unix;
use risingwave_common::types::{DataType, ScalarImpl};
use risingwave_common::util::value_encoding::serialize_datum;
use risingwave_expr::expr::build_from_prost;
Expand All @@ -30,7 +30,7 @@ use risingwave_pb::expr::{ExprNode, FunctionCall};
use tokio::runtime::Runtime;
use utils::{create_input, execute_executor};

enable_jemalloc_on_linux!();
enable_jemalloc_on_unix!();

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 @@ -18,14 +18,14 @@ use itertools::Itertools;
use risingwave_batch::executor::{BoxedExecutor, HashAggExecutor};
use risingwave_common::catalog::{Field, Schema};
use risingwave_common::types::DataType;
use risingwave_common::{enable_jemalloc_on_linux, hash};
use risingwave_common::{enable_jemalloc_on_unix, hash};
use risingwave_expr::expr::AggKind;
use risingwave_expr::vector_op::agg::AggStateFactory;
use risingwave_pb::expr::{AggCall, InputRef};
use tokio::runtime::Runtime;
use utils::{create_input, execute_executor};

enable_jemalloc_on_linux!();
enable_jemalloc_on_unix!();

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 @@ -21,7 +21,7 @@ use risingwave_batch::executor::{BoxedExecutor, JoinType};
use risingwave_common::catalog::schema_test_utils::field_n;
use risingwave_common::types::{DataType, ScalarImpl};
use risingwave_common::util::value_encoding::serialize_datum;
use risingwave_common::{enable_jemalloc_on_linux, hash};
use risingwave_common::{enable_jemalloc_on_unix, hash};
use risingwave_expr::expr::build_from_prost;
use risingwave_pb::data::data_type::TypeName;
use risingwave_pb::data::PbDatum;
Expand All @@ -32,7 +32,7 @@ use risingwave_pb::expr::expr_node::Type::{
use risingwave_pb::expr::{ExprNode, FunctionCall};
use utils::bench_join;

enable_jemalloc_on_linux!();
enable_jemalloc_on_unix!();

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_linux;
use risingwave_common::enable_jemalloc_on_unix;
use risingwave_common::types::DataType;
use tokio::runtime::Runtime;
use utils::{create_input, execute_executor};

enable_jemalloc_on_linux!();
enable_jemalloc_on_unix!();

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 @@ -15,7 +15,7 @@ pub mod utils;

use criterion::{criterion_group, criterion_main, Criterion};
use risingwave_batch::executor::{BoxedExecutor, JoinType, NestedLoopJoinExecutor};
use risingwave_common::enable_jemalloc_on_linux;
use risingwave_common::enable_jemalloc_on_unix;
use risingwave_common::types::{DataType, ScalarImpl};
use risingwave_common::util::value_encoding::serialize_datum;
use risingwave_expr::expr::build_from_prost;
Expand All @@ -28,7 +28,7 @@ use risingwave_pb::expr::expr_node::Type::{
use risingwave_pb::expr::{ExprNode, FunctionCall};
use utils::{bench_join, create_input};

enable_jemalloc_on_linux!();
enable_jemalloc_on_unix!();

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,13 +16,13 @@ pub mod utils;

use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion};
use risingwave_batch::executor::{BoxedExecutor, SortExecutor};
use risingwave_common::enable_jemalloc_on_linux;
use risingwave_common::enable_jemalloc_on_unix;
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_linux!();
enable_jemalloc_on_unix!();

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,13 +16,13 @@ pub mod utils;

use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion};
use risingwave_batch::executor::{BoxedExecutor, TopNExecutor};
use risingwave_common::enable_jemalloc_on_linux;
use risingwave_common::enable_jemalloc_on_unix;
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_linux!();
enable_jemalloc_on_unix!();

fn create_top_n_executor(
chunk_size: usize,
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ tokio = { version = "0.2", package = "madsim-tokio", features = [
workspace-config = { path = "../utils/workspace-config", optional = true }
workspace-hack = { path = "../workspace-hack" }

[target.'cfg(target_os = "linux")'.dependencies]
[target.'cfg(unix)'.dependencies]
tikv-jemallocator = { version = "0.5", features = ["profiling", "stats"] }

[[bin]]
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/src/bin/compactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

#![cfg_attr(coverage, feature(no_coverage))]

use risingwave_common::enable_jemalloc_on_linux;
use risingwave_common::enable_jemalloc_on_unix;

enable_jemalloc_on_linux!();
enable_jemalloc_on_unix!();

#[cfg_attr(coverage, no_coverage)]
fn main() {
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/src/bin/compute_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

#![cfg_attr(coverage, feature(no_coverage))]

use risingwave_common::enable_task_local_jemalloc_on_linux;
use risingwave_common::enable_task_local_jemalloc_on_unix;

enable_task_local_jemalloc_on_linux!();
enable_task_local_jemalloc_on_unix!();

#[cfg_attr(coverage, no_coverage)]
fn main() {
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/src/bin/ctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
#![cfg_attr(coverage, feature(no_coverage))]

use anyhow::Result;
use risingwave_common::enable_jemalloc_on_linux;
use risingwave_common::enable_jemalloc_on_unix;

enable_jemalloc_on_linux!();
enable_jemalloc_on_unix!();

#[cfg_attr(coverage, no_coverage)]
fn main() -> Result<()> {
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/src/bin/frontend_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

#![cfg_attr(coverage, feature(no_coverage))]

use risingwave_common::enable_jemalloc_on_linux;
use risingwave_common::enable_jemalloc_on_unix;

enable_jemalloc_on_linux!();
enable_jemalloc_on_unix!();

#[cfg_attr(coverage, no_coverage)]
fn main() {
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/src/bin/meta_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

#![cfg_attr(coverage, feature(no_coverage))]

use risingwave_common::enable_jemalloc_on_linux;
use risingwave_common::enable_jemalloc_on_unix;

enable_jemalloc_on_linux!();
enable_jemalloc_on_unix!();

#[cfg_attr(coverage, no_coverage)]
fn main() {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd_all/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ tracing = { version = "0.1" }
workspace-config = { path = "../utils/workspace-config", optional = true }
workspace-hack = { path = "../workspace-hack" }

[target.'cfg(target_os = "linux")'.dependencies]
[target.'cfg(unix)'.dependencies]
tikv-jemallocator = { version = "0.5", features = ["profiling", "stats"] }

[[bin]]
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 @@ -21,10 +21,10 @@ use std::env;
use anyhow::{bail, Result};
use clap::Parser;
use risingwave_cmd_all::playground;
use risingwave_common::enable_task_local_jemalloc_on_linux;
use risingwave_common::enable_task_local_jemalloc_on_unix;
use tracing::Level;

enable_task_local_jemalloc_on_linux!();
enable_task_local_jemalloc_on_unix!();

type RwFns = HashMap<&'static str, Box<dyn Fn(Vec<String>) -> Result<()>>>;

Expand Down
8 changes: 4 additions & 4 deletions src/common/src/jemalloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@

/// If <https://github.com/tikv/jemallocator/issues/22> is resolved, we may inline this
#[macro_export]
macro_rules! enable_jemalloc_on_linux {
macro_rules! enable_jemalloc_on_unix {
() => {
#[cfg(target_os = "linux")]
#[cfg(unix)]
#[global_allocator]
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
};
}

#[macro_export]
macro_rules! enable_task_local_jemalloc_on_linux {
macro_rules! enable_task_local_jemalloc_on_unix {
() => {
#[cfg(target_os = "linux")]
#[cfg(unix)]
#[global_allocator]
static GLOBAL: task_stats_alloc::TaskLocalAlloc<tikv_jemallocator::Jemalloc> =
task_stats_alloc::TaskLocalAlloc(tikv_jemallocator::Jemalloc);
Expand Down
3 changes: 3 additions & 0 deletions src/compute/src/memory_management/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
// limitations under the License.

pub mod memory_manager;

// Only enable the non-trivial policies on Linux as it relies on statistics from `jemalloc-ctl`
// which might be inaccurate on other platforms.
#[cfg(target_os = "linux")]
pub mod policy;

Expand Down

0 comments on commit 5901b96

Please sign in to comment.