Skip to content

Commit

Permalink
chore: fix cargo feature "jemalloc"
Browse files Browse the repository at this point in the history
Tweaks "feature passing" among dependencies, so that if feature
"jemalloc" is not enabled, binaries will no longer contain symbols of
jemalloc.
  • Loading branch information
dantengsky committed Oct 26, 2024
1 parent 24861ac commit 7cbe9f1
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/binaries/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ memory-profiling = [
]
python-udf = ["databend-query/python-udf"]
simd = ["databend-query/simd"]
jemalloc = ["databend-common-base/jemalloc"]
jemalloc = ["databend-common-base/jemalloc", "databend-query/jemalloc"]
io-uring = [
"databend-query/io-uring",
]
Expand Down
7 changes: 4 additions & 3 deletions src/common/base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ test = true

[features]
tracing = ["tokio/tracing"]
jemalloc = []
jemalloc = ["tikv-jemalloc-sys", "tikv-jemalloc-ctl"]
disable_initial_exec_tls = ["tikv-jemalloc-sys/disable_initial_exec_tls"]
memory-profiling = [
"jemalloc",
"tikv-jemalloc-sys/stats",
"tikv-jemalloc-sys/profiling",
"tikv-jemalloc-sys/unprefixed_malloc_on_supported_platforms",
Expand Down Expand Up @@ -55,8 +56,8 @@ semver = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
state = "0.5"
tikv-jemalloc-ctl = { workspace = true }
tikv-jemalloc-sys = "0.5.2"
tikv-jemalloc-ctl = { workspace = true, optional = true }
tikv-jemalloc-sys = { version = "0.5.2", optional = true }
tokio = { workspace = true }
unicode-segmentation = "1.10.1"
uuid = { workspace = true }
Expand Down
12 changes: 8 additions & 4 deletions src/common/base/src/mem_allocator/mmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,23 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use crate::mem_allocator::JEAllocator;

/// mmap allocator.
/// For better performance, we use jemalloc as the inner allocator.
#[derive(Debug, Clone, Copy, Default)]
pub struct MmapAllocator {
allocator: JEAllocator,
#[cfg(feature = "jemalloc")]
allocator: crate::mem_allocator::JEAllocator,
#[cfg(not(feature = "jemalloc"))]
allocator: crate::mem_allocator::StdAllocator,
}

impl MmapAllocator {
pub fn new() -> Self {
Self {
allocator: JEAllocator,
#[cfg(feature = "jemalloc")]
allocator: crate::mem_allocator::JEAllocator,
#[cfg(not(feature = "jemalloc"))]
allocator: crate::mem_allocator::StdAllocator,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/common/base/src/mem_allocator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
// limitations under the License.

mod global;
#[cfg(feature = "jemalloc")]
mod jemalloc;
mod mmap;
mod std_;

pub use default::DefaultAllocator;
pub use global::GlobalAllocator;
#[cfg(feature = "jemalloc")]
pub use jemalloc::JEAllocator;
pub use mmap::MmapAllocator;
pub use std_::StdAllocator;
Expand Down
2 changes: 1 addition & 1 deletion src/meta/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ doctest = false
test = true

[features]
default = ["simd", "memory-profiling"]
default = ["simd"]
memory-profiling = ["databend-common-base/memory-profiling", "databend-common-http/memory-profiling"]
simd = ["databend-common-arrow/simd"]
io-uring = [
Expand Down
2 changes: 1 addition & 1 deletion src/query/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ default = ["simd"]
simd = ["databend-common-arrow/simd"]
python-udf = ["arrow-udf-python"]
disable_initial_exec_tls = ["databend-common-base/disable_initial_exec_tls"]

jemalloc = ["databend-common-storages-system/jemalloc"]
memory-profiling = ["databend-common-base/memory-profiling", "databend-common-http/memory-profiling"]
storage-hdfs = ["opendal/services-hdfs", "databend-common-storage/storage-hdfs"]
io-uring = [
Expand Down
4 changes: 4 additions & 0 deletions src/query/service/src/databases/system/system_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ use databend_common_storages_system::FullStreamsTable;
use databend_common_storages_system::FunctionsTable;
use databend_common_storages_system::IndexesTable;
use databend_common_storages_system::LocksTable;
#[cfg(feature = "jemalloc")]
use databend_common_storages_system::MallocStatsTable;
#[cfg(feature = "jemalloc")]
use databend_common_storages_system::MallocStatsTotalsTable;
use databend_common_storages_system::MetricsTable;
use databend_common_storages_system::NotificationHistoryTable;
Expand Down Expand Up @@ -107,7 +109,9 @@ impl SystemDatabase {
ProcessesTable::create(sys_db_meta.next_table_id()),
ConfigsTable::create(sys_db_meta.next_table_id()),
MetricsTable::create(sys_db_meta.next_table_id()),
#[cfg(feature = "jemalloc")]
MallocStatsTable::create(sys_db_meta.next_table_id()),
#[cfg(feature = "jemalloc")]
MallocStatsTotalsTable::create(sys_db_meta.next_table_id()),
ColumnsTable::create(sys_db_meta.next_table_id()),
UsersTable::create(sys_db_meta.next_table_id()),
Expand Down
5 changes: 4 additions & 1 deletion src/query/storages/system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ edition = { workspace = true }
doctest = false
test = true

[features]
jemalloc = ["databend-common-base/jemalloc", "tikv-jemalloc-ctl"]

[dependencies]
async-backtrace = { workspace = true }
async-trait = { workspace = true }
Expand Down Expand Up @@ -49,7 +52,7 @@ serde = { workspace = true }
serde_json = { workspace = true }
serde_repr = "0.1.9"
snailquote = "0.3.1"
tikv-jemalloc-ctl = { workspace = true }
tikv-jemalloc-ctl = { workspace = true, optional = true }
typetag = { workspace = true }

[build-dependencies]
Expand Down
4 changes: 4 additions & 0 deletions src/query/storages/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ mod functions_table;
mod indexes_table;
mod locks_table;
mod log_queue;
#[cfg(feature = "jemalloc")]
mod malloc_stats_table;
#[cfg(feature = "jemalloc")]
mod malloc_stats_totals_table;
mod metrics_table;
mod notification_history_table;
Expand Down Expand Up @@ -89,7 +91,9 @@ pub use locks_table::LocksTable;
pub use log_queue::SystemLogElement;
pub use log_queue::SystemLogQueue;
pub use log_queue::SystemLogTable;
#[cfg(feature = "jemalloc")]
pub use malloc_stats_table::MallocStatsTable;
#[cfg(feature = "jemalloc")]
pub use malloc_stats_totals_table::MallocStatsTotalsTable;
pub use metrics_table::MetricsTable;
pub use notification_history_table::NotificationHistoryTable;
Expand Down

0 comments on commit 7cbe9f1

Please sign in to comment.