From 65825f212612183fbf49a1c0c3ee717090382ba4 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Wed, 11 Jan 2023 04:29:58 +0000 Subject: [PATCH 01/10] Define `enable_jemalloc_on_linux` --- src/common/src/jemalloc.rs | 23 +++++++++++++++++++++++ src/common/src/lib.rs | 2 ++ 2 files changed, 25 insertions(+) create mode 100644 src/common/src/jemalloc.rs diff --git a/src/common/src/jemalloc.rs b/src/common/src/jemalloc.rs new file mode 100644 index 0000000000000..c3f7c386eda17 --- /dev/null +++ b/src/common/src/jemalloc.rs @@ -0,0 +1,23 @@ +// Copyright 2023 Singularity Data +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/// If https://github.com/tikv/jemallocator/issues/22 is resolved, we may inline this +#[macro_export] +macro_rules! enable_jemalloc_on_linux { + () => { + #[cfg(target_os = "linux")] + #[global_allocator] + static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; + }; +} diff --git a/src/common/src/lib.rs b/src/common/src/lib.rs index 80ce2ed4bc127..25d4334daac02 100644 --- a/src/common/src/lib.rs +++ b/src/common/src/lib.rs @@ -34,6 +34,8 @@ #![feature(array_chunks)] #![allow(incomplete_features)] +#[macro_use] +pub mod jemalloc; #[macro_use] pub mod error; #[macro_use] From 90564a22398b9ecaed6bb5e6c16a3e195450195b Mon Sep 17 00:00:00 2001 From: ice1000 Date: Wed, 11 Jan 2023 04:33:22 +0000 Subject: [PATCH 02/10] Linux_only --- Cargo.lock | 1 + src/batch/benches/expand.rs | 6 ++---- src/batch/benches/filter.rs | 5 ++--- src/batch/benches/hash_agg.rs | 6 ++---- src/batch/benches/hash_join.rs | 6 ++---- src/batch/benches/limit.rs | 6 ++---- src/batch/benches/nested_loop_join.rs | 5 ++--- src/batch/benches/sort.rs | 5 ++--- src/batch/benches/top_n.rs | 5 ++--- src/cmd/Cargo.toml | 1 + src/cmd/src/bin/compactor.rs | 5 ++--- src/cmd/src/bin/ctl.rs | 5 ++--- src/cmd/src/bin/meta_node.rs | 5 ++--- 13 files changed, 24 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 88bdc5eebd46c..75325d5601e8f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5380,6 +5380,7 @@ dependencies = [ "global_stats_alloc", "log", "madsim-tokio", + "risingwave_common", "risingwave_compaction_test", "risingwave_compactor", "risingwave_compute", diff --git a/src/batch/benches/expand.rs b/src/batch/benches/expand.rs index 52cb069f48e07..c2faa266fa71e 100644 --- a/src/batch/benches/expand.rs +++ b/src/batch/benches/expand.rs @@ -15,13 +15,11 @@ pub mod utils; use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion}; use risingwave_batch::executor::{BoxedExecutor, ExpandExecutor}; -use risingwave_common::types::DataType; -use tikv_jemallocator::Jemalloc; +use risingwave_common::{types::DataType, enable_jemalloc_on_linux}; use tokio::runtime::Runtime; use utils::{create_input, execute_executor}; -#[global_allocator] -static GLOBAL: Jemalloc = Jemalloc; +enable_jemalloc_on_linux!(); fn create_expand_executor( column_subsets: Vec>, diff --git a/src/batch/benches/filter.rs b/src/batch/benches/filter.rs index 0fd516db7dab4..67ea2032f3922 100644 --- a/src/batch/benches/filter.rs +++ b/src/batch/benches/filter.rs @@ -16,6 +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::types::{DataType, ScalarImpl}; use risingwave_common::util::value_encoding::serialize_datum; use risingwave_expr::expr::build_from_prost; @@ -26,12 +27,10 @@ use risingwave_pb::expr::expr_node::Type::{ ConstantValue as TConstValue, Equal, InputRef, Modulus, }; use risingwave_pb::expr::{ExprNode, FunctionCall, InputRefExpr}; -use tikv_jemallocator::Jemalloc; use tokio::runtime::Runtime; use utils::{create_input, execute_executor}; -#[global_allocator] -static GLOBAL: Jemalloc = Jemalloc; +enable_jemalloc_on_linux!(); fn create_filter_executor(chunk_size: usize, chunk_num: usize) -> BoxedExecutor { const CHUNK_SIZE: usize = 1024; diff --git a/src/batch/benches/hash_agg.rs b/src/batch/benches/hash_agg.rs index 483e27bec9613..951216a41ef91 100644 --- a/src/batch/benches/hash_agg.rs +++ b/src/batch/benches/hash_agg.rs @@ -17,18 +17,16 @@ use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criteri use itertools::Itertools; use risingwave_batch::executor::{BoxedExecutor, HashAggExecutor}; use risingwave_common::catalog::{Field, Schema}; -use risingwave_common::hash; +use risingwave_common::{hash, enable_jemalloc_on_linux}; use risingwave_common::types::DataType; use risingwave_expr::expr::AggKind; use risingwave_expr::vector_op::agg::AggStateFactory; use risingwave_pb::expr::agg_call::Arg; use risingwave_pb::expr::{AggCall, InputRefExpr}; -use tikv_jemallocator::Jemalloc; use tokio::runtime::Runtime; use utils::{create_input, execute_executor}; -#[global_allocator] -static GLOBAL: Jemalloc = Jemalloc; +enable_jemalloc_on_linux!(); fn create_agg_call( input_schema: &Schema, diff --git a/src/batch/benches/hash_join.rs b/src/batch/benches/hash_join.rs index c5dc62cc42604..a03641130fd40 100644 --- a/src/batch/benches/hash_join.rs +++ b/src/batch/benches/hash_join.rs @@ -19,9 +19,9 @@ use risingwave_batch::executor::hash_join::HashJoinExecutor; use risingwave_batch::executor::test_utils::{gen_projected_data, MockExecutor}; use risingwave_batch::executor::{BoxedExecutor, JoinType}; use risingwave_common::catalog::schema_test_utils::field_n; -use risingwave_common::hash; use risingwave_common::types::{DataType, ScalarImpl}; use risingwave_common::util::value_encoding::serialize_datum; +use risingwave_common::{enable_jemalloc_on_linux, hash}; use risingwave_expr::expr::build_from_prost; use risingwave_pb::data::data_type::TypeName; use risingwave_pb::data::Datum as ProstDatum; @@ -30,11 +30,9 @@ use risingwave_pb::expr::expr_node::Type::{ ConstantValue as TConstValue, GreaterThan, InputRef, Modulus, }; use risingwave_pb::expr::{ExprNode, FunctionCall, InputRefExpr}; -use tikv_jemallocator::Jemalloc; use utils::bench_join; -#[global_allocator] -static GLOBAL: Jemalloc = Jemalloc; +enable_jemalloc_on_linux!(); fn create_hash_join_executor( join_type: JoinType, diff --git a/src/batch/benches/limit.rs b/src/batch/benches/limit.rs index ed94ef0d489f9..e35a1bfa7f123 100644 --- a/src/batch/benches/limit.rs +++ b/src/batch/benches/limit.rs @@ -16,13 +16,11 @@ pub mod utils; use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion}; use risingwave_batch::executor::{BoxedExecutor, LimitExecutor}; -use risingwave_common::types::DataType; -use tikv_jemallocator::Jemalloc; +use risingwave_common::{types::DataType, enable_jemalloc_on_linux}; use tokio::runtime::Runtime; use utils::{create_input, execute_executor}; -#[global_allocator] -static GLOBAL: Jemalloc = Jemalloc; +enable_jemalloc_on_linux!(); fn create_limit_executor( chunk_size: usize, diff --git a/src/batch/benches/nested_loop_join.rs b/src/batch/benches/nested_loop_join.rs index 7000bcf468d24..9bf833c1d65db 100644 --- a/src/batch/benches/nested_loop_join.rs +++ b/src/batch/benches/nested_loop_join.rs @@ -15,6 +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::types::{DataType, ScalarImpl}; use risingwave_common::util::value_encoding::serialize_datum; use risingwave_expr::expr::build_from_prost; @@ -25,11 +26,9 @@ use risingwave_pb::expr::expr_node::Type::{ ConstantValue as TConstValue, Equal, InputRef, Modulus, }; use risingwave_pb::expr::{ExprNode, FunctionCall, InputRefExpr}; -use tikv_jemallocator::Jemalloc; use utils::{bench_join, create_input}; -#[global_allocator] -static GLOBAL: Jemalloc = Jemalloc; +enable_jemalloc_on_linux!(); fn create_nested_loop_join_executor( join_type: JoinType, diff --git a/src/batch/benches/sort.rs b/src/batch/benches/sort.rs index a00326a80dee4..7665473e1c7dd 100644 --- a/src/batch/benches/sort.rs +++ b/src/batch/benches/sort.rs @@ -16,14 +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::types::DataType; use risingwave_common::util::sort_util::{OrderPair, OrderType}; -use tikv_jemallocator::Jemalloc; use tokio::runtime::Runtime; use utils::{create_input, execute_executor}; -#[global_allocator] -static GLOBAL: Jemalloc = Jemalloc; +enable_jemalloc_on_linux!(); fn create_order_by_executor( chunk_size: usize, diff --git a/src/batch/benches/top_n.rs b/src/batch/benches/top_n.rs index b2f842979f4e5..977b8b3788f3b 100644 --- a/src/batch/benches/top_n.rs +++ b/src/batch/benches/top_n.rs @@ -16,14 +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::types::DataType; use risingwave_common::util::sort_util::{OrderPair, OrderType}; -use tikv_jemallocator::Jemalloc; use tokio::runtime::Runtime; use utils::{create_input, execute_executor}; -#[global_allocator] -static GLOBAL: Jemalloc = Jemalloc; +enable_jemalloc_on_linux!(); fn create_top_n_executor( chunk_size: usize, diff --git a/src/cmd/Cargo.toml b/src/cmd/Cargo.toml index d490be790d1f9..2f744adef78cd 100644 --- a/src/cmd/Cargo.toml +++ b/src/cmd/Cargo.toml @@ -18,6 +18,7 @@ global_stats_alloc = { path = "../utils/global_stats_alloc" } log = { version = "0.4" } risingwave_compaction_test = { path = "../tests/compaction_test" } risingwave_compactor = { path = "../storage/compactor" } +risingwave_common = { path = "../common" } risingwave_compute = { path = "../compute" } risingwave_ctl = { path = "../ctl" } risingwave_frontend = { path = "../frontend" } diff --git a/src/cmd/src/bin/compactor.rs b/src/cmd/src/bin/compactor.rs index 197026b086dbe..0d4eb83749042 100644 --- a/src/cmd/src/bin/compactor.rs +++ b/src/cmd/src/bin/compactor.rs @@ -14,10 +14,9 @@ #![cfg_attr(coverage, feature(no_coverage))] -use tikv_jemallocator::Jemalloc; +use risingwave_common::enable_jemalloc_on_linux; -#[global_allocator] -static GLOBAL: Jemalloc = Jemalloc; +enable_jemalloc_on_linux!(); #[cfg_attr(coverage, no_coverage)] fn main() { diff --git a/src/cmd/src/bin/ctl.rs b/src/cmd/src/bin/ctl.rs index 1b8dcd3af837f..2ed47be73bca0 100644 --- a/src/cmd/src/bin/ctl.rs +++ b/src/cmd/src/bin/ctl.rs @@ -15,10 +15,9 @@ #![cfg_attr(coverage, feature(no_coverage))] use anyhow::Result; -use tikv_jemallocator::Jemalloc; +use risingwave_common::enable_jemalloc_on_linux; -#[global_allocator] -static GLOBAL: Jemalloc = Jemalloc; +enable_jemalloc_on_linux!(); #[cfg_attr(coverage, no_coverage)] fn main() -> Result<()> { diff --git a/src/cmd/src/bin/meta_node.rs b/src/cmd/src/bin/meta_node.rs index 85c9a8a43e588..8c71639bfe31e 100644 --- a/src/cmd/src/bin/meta_node.rs +++ b/src/cmd/src/bin/meta_node.rs @@ -14,10 +14,9 @@ #![cfg_attr(coverage, feature(no_coverage))] -use tikv_jemallocator::Jemalloc; +use risingwave_common::enable_jemalloc_on_linux; -#[global_allocator] -static GLOBAL: Jemalloc = Jemalloc; +enable_jemalloc_on_linux!(); #[cfg_attr(coverage, no_coverage)] fn main() { From 9be7499d3daf22557dc8b5da6ff82187a5eb9377 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Wed, 11 Jan 2023 04:33:46 +0000 Subject: [PATCH 03/10] Fmt --- src/batch/benches/expand.rs | 3 ++- src/batch/benches/hash_agg.rs | 2 +- src/batch/benches/limit.rs | 3 ++- src/cmd/Cargo.toml | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/batch/benches/expand.rs b/src/batch/benches/expand.rs index c2faa266fa71e..af0a5abea8fda 100644 --- a/src/batch/benches/expand.rs +++ b/src/batch/benches/expand.rs @@ -15,7 +15,8 @@ pub mod utils; use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion}; use risingwave_batch::executor::{BoxedExecutor, ExpandExecutor}; -use risingwave_common::{types::DataType, enable_jemalloc_on_linux}; +use risingwave_common::enable_jemalloc_on_linux; +use risingwave_common::types::DataType; use tokio::runtime::Runtime; use utils::{create_input, execute_executor}; diff --git a/src/batch/benches/hash_agg.rs b/src/batch/benches/hash_agg.rs index 951216a41ef91..8d307ba1e4cac 100644 --- a/src/batch/benches/hash_agg.rs +++ b/src/batch/benches/hash_agg.rs @@ -17,8 +17,8 @@ use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criteri use itertools::Itertools; use risingwave_batch::executor::{BoxedExecutor, HashAggExecutor}; use risingwave_common::catalog::{Field, Schema}; -use risingwave_common::{hash, enable_jemalloc_on_linux}; use risingwave_common::types::DataType; +use risingwave_common::{enable_jemalloc_on_linux, hash}; use risingwave_expr::expr::AggKind; use risingwave_expr::vector_op::agg::AggStateFactory; use risingwave_pb::expr::agg_call::Arg; diff --git a/src/batch/benches/limit.rs b/src/batch/benches/limit.rs index e35a1bfa7f123..c3a16add5a2d4 100644 --- a/src/batch/benches/limit.rs +++ b/src/batch/benches/limit.rs @@ -16,7 +16,8 @@ pub mod utils; use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion}; use risingwave_batch::executor::{BoxedExecutor, LimitExecutor}; -use risingwave_common::{types::DataType, enable_jemalloc_on_linux}; +use risingwave_common::enable_jemalloc_on_linux; +use risingwave_common::types::DataType; use tokio::runtime::Runtime; use utils::{create_input, execute_executor}; diff --git a/src/cmd/Cargo.toml b/src/cmd/Cargo.toml index 2f744adef78cd..12c9ccd4fae3b 100644 --- a/src/cmd/Cargo.toml +++ b/src/cmd/Cargo.toml @@ -16,9 +16,9 @@ anyhow = "1" clap = { version = "3", features = ["derive"] } global_stats_alloc = { path = "../utils/global_stats_alloc" } log = { version = "0.4" } +risingwave_common = { path = "../common" } risingwave_compaction_test = { path = "../tests/compaction_test" } risingwave_compactor = { path = "../storage/compactor" } -risingwave_common = { path = "../common" } risingwave_compute = { path = "../compute" } risingwave_ctl = { path = "../ctl" } risingwave_frontend = { path = "../frontend" } From 319203c005657005c443b1e8d9534384acbeb901 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Wed, 11 Jan 2023 04:47:49 +0000 Subject: [PATCH 04/10] lol --- src/batch/benches/sort_merge_join.rs | 5 ++--- src/cmd/src/bin/frontend_node.rs | 5 ++--- src/cmd_all/src/bin/risingwave.rs | 9 +++------ src/common/src/jemalloc.rs | 10 ++++++++++ src/compute/src/memory_management/memory_manager.rs | 6 ++++++ src/utils/global_stats_alloc/src/lib.rs | 8 ++++---- 6 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/batch/benches/sort_merge_join.rs b/src/batch/benches/sort_merge_join.rs index 50d771f37a034..94b2c0b0bc26c 100644 --- a/src/batch/benches/sort_merge_join.rs +++ b/src/batch/benches/sort_merge_join.rs @@ -18,13 +18,12 @@ use criterion::{criterion_group, criterion_main, Criterion}; use risingwave_batch::executor::test_utils::{gen_sorted_data, MockExecutor}; use risingwave_batch::executor::{BoxedExecutor, JoinType, SortMergeJoinExecutor}; use risingwave_common::catalog::schema_test_utils::field_n; +use risingwave_common::enable_jemalloc_on_linux; use risingwave_common::types::DataType; use risingwave_common::util::sort_util::OrderType; -use tikv_jemallocator::Jemalloc; use utils::bench_join; -#[global_allocator] -static GLOBAL: Jemalloc = Jemalloc; +enable_jemalloc_on_linux!(); fn create_sort_merge_join_executor( join_type: JoinType, diff --git a/src/cmd/src/bin/frontend_node.rs b/src/cmd/src/bin/frontend_node.rs index 000ba7380674d..d130c0a7f4b57 100644 --- a/src/cmd/src/bin/frontend_node.rs +++ b/src/cmd/src/bin/frontend_node.rs @@ -14,10 +14,9 @@ #![cfg_attr(coverage, feature(no_coverage))] -use tikv_jemallocator::Jemalloc; +use risingwave_common::enable_jemalloc_on_linux; -#[global_allocator] -static GLOBAL: Jemalloc = Jemalloc; +enable_jemalloc_on_linux!(); #[cfg_attr(coverage, no_coverage)] fn main() { diff --git a/src/cmd_all/src/bin/risingwave.rs b/src/cmd_all/src/bin/risingwave.rs index 390d5730fdaf8..6e279782d7a57 100644 --- a/src/cmd_all/src/bin/risingwave.rs +++ b/src/cmd_all/src/bin/risingwave.rs @@ -15,18 +15,15 @@ #![cfg_attr(coverage, feature(no_coverage))] #![feature(let_chains)] -use task_stats_alloc::TaskLocalAlloc; -use tikv_jemallocator::Jemalloc; - -#[global_allocator] -static GLOBAL: TaskLocalAlloc = TaskLocalAlloc(Jemalloc); - use std::collections::HashMap; use std::env; use anyhow::{bail, Result}; use clap::StructOpt; use risingwave_cmd_all::playground; +use risingwave_common::enable_sys_jemalloc_on_linux; + +enable_sys_jemalloc_on_linux!(); type RwFns = HashMap<&'static str, Box) -> Result<()>>>; diff --git a/src/common/src/jemalloc.rs b/src/common/src/jemalloc.rs index c3f7c386eda17..a51ec5931a2aa 100644 --- a/src/common/src/jemalloc.rs +++ b/src/common/src/jemalloc.rs @@ -21,3 +21,13 @@ macro_rules! enable_jemalloc_on_linux { static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; }; } + +#[macro_export] +macro_rules! enable_sys_jemalloc_on_linux { + () => { + #[cfg(target_os = "linux")] + #[global_allocator] + static GLOBAL: task_stats_alloc::TaskLocalAlloc = + task_stats_alloc::TaskLocalAlloc(tikv_jemallocator::Jemalloc); + }; +} diff --git a/src/compute/src/memory_management/memory_manager.rs b/src/compute/src/memory_management/memory_manager.rs index 63fb51605cc37..f431995d5aa8b 100644 --- a/src/compute/src/memory_management/memory_manager.rs +++ b/src/compute/src/memory_management/memory_manager.rs @@ -68,9 +68,15 @@ impl GlobalMemoryManager { watermark_epoch.store(epoch, Ordering::Relaxed); } + /// Jemalloc is not supported on non-Linux OSs, because tikv-jemalloc is not available. + /// See the comments for the macro enable_jemalloc_on_linux!(); + #[cfg(not(target_os = "linux"))] + pub async fn run(self: Arc, _: Arc, _: Arc) {} + /// Memory manager will get memory usage from batch and streaming, and do some actions. /// 1. if batch exceeds, kill running query. /// 2. if streaming exceeds, evict cache by watermark. + #[cfg(target_os = "linux")] pub async fn run( self: Arc, _batch_mgr: Arc, diff --git a/src/utils/global_stats_alloc/src/lib.rs b/src/utils/global_stats_alloc/src/lib.rs index 7713f55241643..7cb8a9f4ef905 100644 --- a/src/utils/global_stats_alloc/src/lib.rs +++ b/src/utils/global_stats_alloc/src/lib.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use stats_alloc::StatsAlloc; -use tikv_jemallocator::Jemalloc; - -pub static INSTRUMENTED_JEMALLOC: StatsAlloc = StatsAlloc::new(Jemalloc); +/// Tesla, 2023/1/10: did not see any usages. Remove? +#[cfg(target_os = "linux")] +pub static INSTRUMENTED_JEMALLOC: stats_alloc::StatsAlloc = + stats_alloc::StatsAlloc::new(tikv_jemallocator::Jemalloc); From 92a28c91bfe5eba7a205457676cc9c1e1fae69bb Mon Sep 17 00:00:00 2001 From: ice1000 Date: Wed, 11 Jan 2023 04:48:52 +0000 Subject: [PATCH 05/10] Removal --- Cargo.lock | 18 ------------------ docs/index.md | 1 - src/cmd/Cargo.toml | 1 - src/cmd_all/Cargo.toml | 1 - src/stream/Cargo.toml | 1 - src/utils/global_stats_alloc/Cargo.toml | 17 ----------------- src/utils/global_stats_alloc/src/lib.rs | 18 ------------------ 7 files changed, 57 deletions(-) delete mode 100644 src/utils/global_stats_alloc/Cargo.toml delete mode 100644 src/utils/global_stats_alloc/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 88bdc5eebd46c..044e502d9eef5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2466,15 +2466,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" -[[package]] -name = "global_stats_alloc" -version = "0.2.0-alpha" -dependencies = [ - "stats_alloc", - "tikv-jemallocator", - "workspace-hack", -] - [[package]] name = "globset" version = "0.4.9" @@ -5377,7 +5368,6 @@ version = "0.2.0-alpha" dependencies = [ "anyhow", "clap 3.2.23", - "global_stats_alloc", "log", "madsim-tokio", "risingwave_compaction_test", @@ -5401,7 +5391,6 @@ dependencies = [ "anyhow", "clap 3.2.23", "console", - "global_stats_alloc", "log", "madsim-tokio", "risedev", @@ -6287,7 +6276,6 @@ dependencies = [ "futures", "futures-async-stream", "gen-iter", - "global_stats_alloc", "hyper", "iter-chunks", "itertools", @@ -6993,12 +6981,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" -[[package]] -name = "stats_alloc" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c0e04424e733e69714ca1bbb9204c1a57f09f5493439520f9f68c132ad25eec" - [[package]] name = "str_stack" version = "0.1.0" diff --git a/docs/index.md b/docs/index.md index e25086c2cb726..35e54ec0979a6 100644 --- a/docs/index.md +++ b/docs/index.md @@ -49,7 +49,6 @@ Common functionalities shared inside RisingWave. The crates under `src/utils` are several independent util crates which helps to simplify development. We plan to publish them to [crates.io](https://crates.io/) in future when they are more mature. - [async_stack_trace](async_stack_trace/index.html) -- [global_stats_alloc](global_stats_alloc/index.html) - [local_stats_alloc](local_stats_alloc/index.html) - [memcomparable](memcomparable/index.html) - [pgwire](pgwire/index.html) diff --git a/src/cmd/Cargo.toml b/src/cmd/Cargo.toml index d490be790d1f9..6444171ad14aa 100644 --- a/src/cmd/Cargo.toml +++ b/src/cmd/Cargo.toml @@ -14,7 +14,6 @@ static-log-level = ["workspace-config/enable-static-log-level"] [dependencies] anyhow = "1" clap = { version = "3", features = ["derive"] } -global_stats_alloc = { path = "../utils/global_stats_alloc" } log = { version = "0.4" } risingwave_compaction_test = { path = "../tests/compaction_test" } risingwave_compactor = { path = "../storage/compactor" } diff --git a/src/cmd_all/Cargo.toml b/src/cmd_all/Cargo.toml index 579c15b814119..713f40424fde2 100644 --- a/src/cmd_all/Cargo.toml +++ b/src/cmd_all/Cargo.toml @@ -15,7 +15,6 @@ static-log-level = ["workspace-config/enable-static-log-level"] anyhow = "1" clap = { version = "3", features = ["derive"] } console = "0.15.2" -global_stats_alloc = { path = "../utils/global_stats_alloc" } log = { version = "0.4" } risedev = { path = "../risedevtool" } risingwave_common = { path = "../common" } diff --git a/src/stream/Cargo.toml b/src/stream/Cargo.toml index 9e2688468d423..15940d4c69c28 100644 --- a/src/stream/Cargo.toml +++ b/src/stream/Cargo.toml @@ -27,7 +27,6 @@ fixedbitset = { version = "0.4", features = ["std"] } futures = { version = "0.3", default-features = false, features = ["alloc"] } futures-async-stream = "0.2" gen-iter = "0.3" -global_stats_alloc = { path = "../utils/global_stats_alloc" } hyper = "0.14" iter-chunks = "0.1" itertools = "0.10" diff --git a/src/utils/global_stats_alloc/Cargo.toml b/src/utils/global_stats_alloc/Cargo.toml deleted file mode 100644 index 7cea6d3eefaf5..0000000000000 --- a/src/utils/global_stats_alloc/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "global_stats_alloc" -version = { workspace = true } -edition = { workspace = true } -homepage = { workspace = true } -keywords = { workspace = true } -license = { workspace = true } -repository = { workspace = true } -description = "Global allocator with statistics" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[target.'cfg(not(madsim))'.dependencies] -workspace-hack = { path = "../../workspace-hack" } - -[dependencies] -stats_alloc = { version = "0.1", features = ["nightly"]} -tikv-jemallocator = { version = "0.5", features = ["background_threads_runtime_support", "profiling", "stats"] } diff --git a/src/utils/global_stats_alloc/src/lib.rs b/src/utils/global_stats_alloc/src/lib.rs deleted file mode 100644 index 7713f55241643..0000000000000 --- a/src/utils/global_stats_alloc/src/lib.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2023 Singularity Data -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use stats_alloc::StatsAlloc; -use tikv_jemallocator::Jemalloc; - -pub static INSTRUMENTED_JEMALLOC: StatsAlloc = StatsAlloc::new(Jemalloc); From ee357e6b8fb7d1093d49acbaa4c3d165333611a1 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Wed, 11 Jan 2023 05:13:14 +0000 Subject: [PATCH 06/10] Linux-only --- docs/memory-profiling.md | 4 +++- src/batch/Cargo.toml | 2 ++ src/cmd/Cargo.toml | 4 +++- src/compute/Cargo.toml | 4 +++- src/compute/src/memory_management/memory_manager.rs | 4 +++- src/stream/Cargo.toml | 4 +++- 6 files changed, 17 insertions(+), 5 deletions(-) diff --git a/docs/memory-profiling.md b/docs/memory-profiling.md index 954db12f64cbc..e65a1185c52ca 100644 --- a/docs/memory-profiling.md +++ b/docs/memory-profiling.md @@ -1,12 +1,14 @@ # Memory (Heap) Profiling Guide +Note that the content below is Linux-exclusive. + ## What is Heap Profile? A heap profiler records the **stack trace of the allocation** of each **live** object, so it’s possible that function A allocates something and then hand over it to struct B, in this case, the allocation will still be counted on A. ## Internals -RisingWave uses [tikv-jemallocator](https://crates.io/crates/tikv-jemallocator), which is a Rust wrapper of [jemalloc](https://github.com/jemalloc/jemalloc), as its memory allocator. +RisingWave uses [tikv-jemallocator](https://crates.io/crates/tikv-jemallocator) on Linux, which is a Rust wrapper of [jemalloc](https://github.com/jemalloc/jemalloc), as its memory allocator. On other platforms, RisingWave uses the default allocator. Luckily, jemalloc provides built-in profiling support ([official wiki](https://github.com/jemalloc/jemalloc/wiki/Use-Case%3A-Heap-Profiling)). jemallocator exposes the feature via a cargo feature ‘profiling’. [Here](https://gist.github.com/ordian/928dc2bd45022cddd547528f64db9174) is a simple guide to profiling with jemallocator. diff --git a/src/batch/Cargo.toml b/src/batch/Cargo.toml index 6ac856bac8045..7d6683db41f67 100644 --- a/src/batch/Cargo.toml +++ b/src/batch/Cargo.toml @@ -71,6 +71,8 @@ workspace-hack = { path = "../workspace-hack" } criterion = { version = "0.4", features = ["async_tokio", "async"] } rand = "0.8" tempfile = "3" + +[target.'cfg(target_os = "linux")'.dev-dependencies] tikv-jemallocator = "0.5" [[bench]] diff --git a/src/cmd/Cargo.toml b/src/cmd/Cargo.toml index c03c9d7a7421e..e7eff00e37130 100644 --- a/src/cmd/Cargo.toml +++ b/src/cmd/Cargo.toml @@ -24,7 +24,6 @@ risingwave_frontend = { path = "../frontend" } risingwave_meta = { path = "../meta" } risingwave_rt = { path = "../utils/runtime" } task_stats_alloc = { path = "../utils/task_stats_alloc" } -tikv-jemallocator = { version = "0.5", features = ["profiling", "stats"] } tokio = { version = "0.2", package = "madsim-tokio", features = [ "rt", "rt-multi-thread", @@ -40,6 +39,9 @@ tracing = { version = "0.1" } workspace-config = { path = "../utils/workspace-config", optional = true } workspace-hack = { path = "../workspace-hack" } +[target.'cfg(target_os = "linux")'.dependencies] +tikv-jemallocator = { version = "0.5", features = ["profiling", "stats"] } + [[bin]] name = "frontend" path = "src/bin/frontend_node.rs" diff --git a/src/compute/Cargo.toml b/src/compute/Cargo.toml index aec0aa8833987..9731fb96ab248 100644 --- a/src/compute/Cargo.toml +++ b/src/compute/Cargo.toml @@ -53,7 +53,6 @@ smallvec = "1" static_assertions = "1" sysinfo = "0.26" thiserror = "1" -tikv-jemalloc-ctl = "0.5" tokio = { version = "0.2", package = "madsim-tokio", features = [ "rt", "rt-multi-thread", @@ -71,6 +70,9 @@ tracing = "0.1" twox-hash = "1" url = "2" +[target.'cfg(target_os = "linux")'.dependencies] +tikv-jemalloc-ctl = "0.5" + [target.'cfg(not(madsim))'.dependencies] workspace-hack = { path = "../workspace-hack" } diff --git a/src/compute/src/memory_management/memory_manager.rs b/src/compute/src/memory_management/memory_manager.rs index f431995d5aa8b..3e1e24903c732 100644 --- a/src/compute/src/memory_management/memory_manager.rs +++ b/src/compute/src/memory_management/memory_manager.rs @@ -20,9 +20,11 @@ use risingwave_batch::task::BatchManager; use risingwave_common::util::epoch::Epoch; use risingwave_stream::executor::monitor::StreamingMetrics; use risingwave_stream::task::LocalStreamManager; -use tikv_jemalloc_ctl::{epoch as jemalloc_epoch, stats as jemalloc_stats}; use tracing; +#[cfg(target_os = "linux")] +use tikv_jemalloc_ctl::{epoch as jemalloc_epoch, stats as jemalloc_stats}; + /// When `enable_managed_cache` is set, compute node will launch a [`GlobalMemoryManager`] to limit /// the memory usage. pub struct GlobalMemoryManager { diff --git a/src/stream/Cargo.toml b/src/stream/Cargo.toml index 15940d4c69c28..4bd76915b713e 100644 --- a/src/stream/Cargo.toml +++ b/src/stream/Cargo.toml @@ -59,7 +59,6 @@ smallvec = "1" static_assertions = "1" task_stats_alloc = { path = "../utils/task_stats_alloc" } thiserror = "1" -tikv-jemalloc-ctl = "0.5" tokio = { version = "0.2", package = "madsim-tokio", features = [ "rt", "rt-multi-thread", @@ -78,6 +77,9 @@ tracing-futures = "0.2" twox-hash = "1" url = "2" +[target.'cfg(target_os = "linux")'.dependencies] +tikv-jemalloc-ctl = "0.5" + [target.'cfg(not(madsim))'.dependencies] workspace-hack = { path = "../workspace-hack" } From 6cd34b05d6c3261cbc93a5317c692c729d30dd01 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Wed, 11 Jan 2023 05:29:46 +0000 Subject: [PATCH 07/10] Really Linux-only --- src/cmd/src/bin/compute_node.rs | 6 ++---- src/cmd_all/src/bin/risingwave.rs | 4 ++-- src/common/src/jemalloc.rs | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/cmd/src/bin/compute_node.rs b/src/cmd/src/bin/compute_node.rs index 883fc6b947c07..49309d563e21d 100644 --- a/src/cmd/src/bin/compute_node.rs +++ b/src/cmd/src/bin/compute_node.rs @@ -14,11 +14,9 @@ #![cfg_attr(coverage, feature(no_coverage))] -use task_stats_alloc::TaskLocalAlloc; -use tikv_jemallocator::Jemalloc; +use risingwave_common::enable_task_local_jemalloc_on_linux; -#[global_allocator] -static GLOBAL: TaskLocalAlloc = TaskLocalAlloc(Jemalloc); +enable_task_local_jemalloc_on_linux!(); #[cfg_attr(coverage, no_coverage)] fn main() { diff --git a/src/cmd_all/src/bin/risingwave.rs b/src/cmd_all/src/bin/risingwave.rs index 6e279782d7a57..6fd7627abd89d 100644 --- a/src/cmd_all/src/bin/risingwave.rs +++ b/src/cmd_all/src/bin/risingwave.rs @@ -21,9 +21,9 @@ use std::env; use anyhow::{bail, Result}; use clap::StructOpt; use risingwave_cmd_all::playground; -use risingwave_common::enable_sys_jemalloc_on_linux; +use risingwave_common::enable_task_local_jemalloc_on_linux; -enable_sys_jemalloc_on_linux!(); +enable_task_local_jemalloc_on_linux!(); type RwFns = HashMap<&'static str, Box) -> Result<()>>>; diff --git a/src/common/src/jemalloc.rs b/src/common/src/jemalloc.rs index a51ec5931a2aa..80ee5908a3587 100644 --- a/src/common/src/jemalloc.rs +++ b/src/common/src/jemalloc.rs @@ -23,7 +23,7 @@ macro_rules! enable_jemalloc_on_linux { } #[macro_export] -macro_rules! enable_sys_jemalloc_on_linux { +macro_rules! enable_task_local_jemalloc_on_linux { () => { #[cfg(target_os = "linux")] #[global_allocator] From 7d7e82d0323f3a2d83cfab4c4b5a9a8c3761b25b Mon Sep 17 00:00:00 2001 From: ice1000 Date: Wed, 11 Jan 2023 05:42:18 +0000 Subject: [PATCH 08/10] Hakari --- src/compute/src/memory_management/memory_manager.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/compute/src/memory_management/memory_manager.rs b/src/compute/src/memory_management/memory_manager.rs index 3e1e24903c732..795a1a25c6683 100644 --- a/src/compute/src/memory_management/memory_manager.rs +++ b/src/compute/src/memory_management/memory_manager.rs @@ -20,10 +20,9 @@ use risingwave_batch::task::BatchManager; use risingwave_common::util::epoch::Epoch; use risingwave_stream::executor::monitor::StreamingMetrics; use risingwave_stream::task::LocalStreamManager; -use tracing; - #[cfg(target_os = "linux")] use tikv_jemalloc_ctl::{epoch as jemalloc_epoch, stats as jemalloc_stats}; +use tracing; /// When `enable_managed_cache` is set, compute node will launch a [`GlobalMemoryManager`] to limit /// the memory usage. From c3f0e5868b7150e73965585ec1c0fb6eb01e5fd1 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Wed, 11 Jan 2023 05:49:00 +0000 Subject: [PATCH 09/10] Wow --- Cargo.lock | 2 -- src/common/src/jemalloc.rs | 2 +- src/workspace-hack/Cargo.toml | 4 ---- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5bff3479fbc4d..1b8246066c707 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8360,8 +8360,6 @@ dependencies = [ "stable_deref_trait", "strum", "syn", - "tikv-jemalloc-sys", - "tikv-jemallocator", "time 0.3.15", "tokio", "tokio-stream", diff --git a/src/common/src/jemalloc.rs b/src/common/src/jemalloc.rs index 80ee5908a3587..22be75c3d82cc 100644 --- a/src/common/src/jemalloc.rs +++ b/src/common/src/jemalloc.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -/// If https://github.com/tikv/jemallocator/issues/22 is resolved, we may inline this +/// If is resolved, we may inline this #[macro_export] macro_rules! enable_jemalloc_on_linux { () => { diff --git a/src/workspace-hack/Cargo.toml b/src/workspace-hack/Cargo.toml index 1cfc9f801fd94..6a90a9e5357fa 100644 --- a/src/workspace-hack/Cargo.toml +++ b/src/workspace-hack/Cargo.toml @@ -84,8 +84,6 @@ smallvec = { version = "1", default-features = false, features = ["serde", "unio socket2 = { version = "0.4", default-features = false, features = ["all"] } stable_deref_trait = { version = "1", features = ["alloc", "std"] } strum = { version = "0.24", features = ["derive", "std", "strum_macros"] } -tikv-jemalloc-sys = { version = "0.5", features = ["background_threads_runtime_support", "profiling", "stats"] } -tikv-jemallocator = { version = "0.5", features = ["background_threads_runtime_support", "profiling", "stats"] } time = { version = "0.3", features = ["alloc", "formatting", "itoa", "local-offset", "macros", "parsing", "std", "time-macros"] } tokio = { version = "1", features = ["bytes", "fs", "io-std", "io-util", "libc", "macros", "memchr", "mio", "net", "num_cpus", "parking_lot", "process", "rt", "rt-multi-thread", "signal", "signal-hook-registry", "socket2", "stats", "sync", "time", "tokio-macros", "tracing"] } tokio-stream = { version = "0.1", features = ["net", "time"] } @@ -170,8 +168,6 @@ socket2 = { version = "0.4", default-features = false, features = ["all"] } stable_deref_trait = { version = "1", features = ["alloc", "std"] } strum = { version = "0.24", features = ["derive", "std", "strum_macros"] } syn = { version = "1", features = ["clone-impls", "derive", "extra-traits", "full", "parsing", "printing", "proc-macro", "quote", "visit", "visit-mut"] } -tikv-jemalloc-sys = { version = "0.5", features = ["background_threads_runtime_support", "profiling", "stats"] } -tikv-jemallocator = { version = "0.5", features = ["background_threads_runtime_support", "profiling", "stats"] } time = { version = "0.3", features = ["alloc", "formatting", "itoa", "local-offset", "macros", "parsing", "std", "time-macros"] } tokio = { version = "1", features = ["bytes", "fs", "io-std", "io-util", "libc", "macros", "memchr", "mio", "net", "num_cpus", "parking_lot", "process", "rt", "rt-multi-thread", "signal", "signal-hook-registry", "socket2", "stats", "sync", "time", "tokio-macros", "tracing"] } tokio-stream = { version = "0.1", features = ["net", "time"] } From 31906c8babfb00be81dab14ddff1215e11f6c6f0 Mon Sep 17 00:00:00 2001 From: Eric Fu Date: Wed, 11 Jan 2023 18:32:49 +0800 Subject: [PATCH 10/10] add a FIXME there --- src/compute/src/memory_management/memory_manager.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/compute/src/memory_management/memory_manager.rs b/src/compute/src/memory_management/memory_manager.rs index 795a1a25c6683..e13f9eff89095 100644 --- a/src/compute/src/memory_management/memory_manager.rs +++ b/src/compute/src/memory_management/memory_manager.rs @@ -71,6 +71,7 @@ impl GlobalMemoryManager { /// Jemalloc is not supported on non-Linux OSs, because tikv-jemalloc is not available. /// See the comments for the macro enable_jemalloc_on_linux!(); + // FIXME: remove such limitation after #7180 #[cfg(not(target_os = "linux"))] pub async fn run(self: Arc, _: Arc, _: Arc) {}