Skip to content

Commit 757a2d0

Browse files
committed
alloc: add force-jemalloc-macos feature
1 parent 2fc8dd7 commit 757a2d0

File tree

8 files changed

+57
-22
lines changed

8 files changed

+57
-22
lines changed

ci/test/lint-deps/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,5 @@ However, note the specifics for `jemalloc` below.
2828

2929
### Specifics for `jemalloc`
3030

31-
We enable `jemalloc` by default on all non-mac platforms, unless `--no-default-features` is enabled.
32-
In this case, `jemalloc` should be disabled on all platforms.
33-
To quickly determine the validity of changes, check that only the file `x86_64-unknown-linux-gnu-default` mentions the `tikv-jemallocator` dependency, and all others don't.
31+
We enable `jemalloc` by default on all non-mac platforms, unless `--no-default-features` is enabled. However,
32+
because of cargo limitations, its built on macos as well.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
11
# generated by ci/test/lint-deps.sh -- see ci/test/lint-deps/README.md for details
2+
tikv_jemalloc_ctl
3+
0:mz_alloc:default,jemalloc,tikv-jemallocator,workspace-hack
4+
1:mz_prof:default,jemalloc,tikv-jemalloc-ctl,workspace-hack
5+
2:tikv_jemalloc_ctl:default,use_std
6+
tikv_jemallocator
7+
0:mz_alloc:default,jemalloc,tikv-jemallocator,workspace-hack
8+
1:tikv_jemallocator:background_threads,background_threads_runtime_support,default,profiling,stats,unprefixed_malloc_on_supported_platforms
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
11
# generated by ci/test/lint-deps.sh -- see ci/test/lint-deps/README.md for details
2+
tikv_jemalloc_ctl
3+
0:mz_alloc:default,jemalloc,tikv-jemallocator,workspace-hack
4+
1:mz_prof:default,jemalloc,tikv-jemalloc-ctl,workspace-hack
5+
2:tikv_jemalloc_ctl:default,use_std
6+
tikv_jemallocator
7+
0:mz_alloc:default,jemalloc,tikv-jemallocator,workspace-hack
8+
1:tikv_jemallocator:background_threads,background_threads_runtime_support,default,profiling,stats,unprefixed_malloc_on_supported_platforms

src/alloc/Cargo.toml

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,7 @@ workspace = true
1212
[dependencies]
1313
mz-ore = { path = "../ore", default-features = false }
1414
workspace-hack = { version = "0.0.0", path = "../workspace-hack", optional = true }
15-
16-
# Disable jemalloc on macOS, as it is not well supported [0][1][2]. The issues
17-
# present as runaway latency on load test workloads that are comfortably handled
18-
# by the macOS system allocator. Consider re-evaluating if jemalloc's macOS
19-
# support improves.
20-
#
21-
# [0]: https://github.com/jemalloc/jemalloc/issues/26
22-
# [1]: https://github.com/jemalloc/jemalloc/issues/843
23-
# [2]: https://github.com/jemalloc/jemalloc/issues/1467
24-
#
25-
# Furthermore, as of August 2022, some engineers are using profiling tools, e.g.
26-
# `heaptrack`, that only work with the system allocator.
27-
[target.'cfg(not(target_os = "macos"))'.dependencies]
2815
mz-prof = { path = "../prof", default-features = false }
29-
mz-prof-http = { path = "../prof-http", default-features = false }
3016
# According to jemalloc developers, `background_threads` should always be
3117
# enabled, except in "esoteric" situations that don't apply to Materialize
3218
# (namely, if the application relies on new threads not being created for
@@ -35,10 +21,32 @@ mz-prof-http = { path = "../prof-http", default-features = false }
3521
# See: https://github.com/jemalloc/jemalloc/issues/956#issuecomment-316224733
3622
tikv-jemallocator = { version = "0.5.0", features = ["profiling", "stats", "unprefixed_malloc_on_supported_platforms", "background_threads"], optional = true }
3723

24+
[target.'cfg(not(target_os = "macos"))'.dependencies]
25+
mz-prof-http = { path = "../prof-http", default-features = false }
26+
3827
[features]
3928
default = ["workspace-hack"]
4029
# Whether to enable the use of jemalloc on platforms that support it.
4130
jemalloc = ["tikv-jemallocator", "mz-prof/jemalloc", "mz-prof-http/jemalloc"]
31+
# By default disable jemalloc on macOS, as it is not well supported [0][1]. The issues
32+
# present as runaway latency on load test workloads that are comfortably handled
33+
# by the macOS system allocator. Consider re-evaluating if jemalloc's macOS
34+
# support improves.
35+
#
36+
# [0]: https://github.com/jemalloc/jemalloc/issues/26
37+
# [1]: https://github.com/jemalloc/jemalloc/issues/843
38+
#
39+
# Furthermore, as of August 2022, some engineers are using profiling tools, e.g.
40+
# `heaptrack`, that only work with the system allocator.
41+
#
42+
# Note that profiling as provided by `mz-prof-http` is not enabled for macos, as it
43+
# appears to not work at all.
44+
#
45+
# Unfortunately, there doesn't appear to be a way to tell cargo to only include the
46+
# tikv-jemallocator dependency if `force-jemalloc-macos` is enabled AND the platform
47+
# is macos (Cargo doesn't support all(feature, platform) in the `target.cfg()` fields. This
48+
# means mac users have to build one more dep :(.
49+
force-jemalloc-macos = []
4250

4351
[package.metadata.cargo-udeps.ignore]
4452
# The only reason we depend on mz-prof-http

src/alloc/src/lib.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,23 @@
99

1010
use mz_ore::metrics::MetricsRegistry;
1111

12-
#[cfg(all(not(target_os = "macos"), feature = "jemalloc", not(miri)))]
12+
#[cfg(all(
13+
any(feature = "force-jemalloc-macos", not(target_os = "macos")),
14+
feature = "jemalloc",
15+
not(miri)
16+
))]
1317
#[global_allocator]
1418
static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
1519

1620
/// Registers metrics for the global allocator into the provided registry.
1721
///
1822
/// What metrics are registered varies by platform. Not all platforms use
1923
/// allocators that support metrics.
20-
#[cfg(any(target_os = "macos", not(feature = "jemalloc"), miri))]
24+
#[cfg(any(
25+
all(not(feature = "force-jemalloc-macos"), target_os = "macos"),
26+
not(feature = "jemalloc"),
27+
miri
28+
))]
2129
#[allow(clippy::unused_async)]
2230
pub async fn register_metrics_into(_: &MetricsRegistry) {
2331
// No-op on platforms that don't use jemalloc.
@@ -27,7 +35,11 @@ pub async fn register_metrics_into(_: &MetricsRegistry) {
2735
///
2836
/// What metrics are registered varies by platform. Not all platforms use
2937
/// allocators that support metrics.
30-
#[cfg(all(not(target_os = "macos"), feature = "jemalloc", not(miri)))]
38+
#[cfg(all(
39+
any(feature = "force-jemalloc-macos", not(target_os = "macos")),
40+
feature = "jemalloc",
41+
not(miri)
42+
))]
3143
pub async fn register_metrics_into(registry: &MetricsRegistry) {
3244
mz_prof::jemalloc::JemallocMetrics::register_into(registry).await;
3345
}

src/clusterd/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ workspace-hack = { version = "0.0.0", path = "../workspace-hack" }
4444
[features]
4545
default = ["tokio-console", "jemalloc"]
4646
jemalloc = ["mz-alloc/jemalloc"]
47+
force-jemalloc-macos = ["mz-alloc/force-jemalloc-macos"]
4748
tokio-console = ["mz-ore/tokio-console"]
4849

4950
[package.metadata.cargo-udeps.ignore]

src/environmentd/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ default = ["tokio-console", "jemalloc"]
168168
# access to the file system.
169169
dev-web = []
170170
jemalloc = ["mz-alloc/jemalloc"]
171+
force-jemalloc-macos = ["mz-alloc/force-jemalloc-macos"]
171172
test = [
172173
"postgres",
173174
"regex",

src/workspace-hack/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ subtle = { version = "2.4.1" }
110110
syn-dff4ba8e3ae991db = { package = "syn", version = "1.0.107", features = ["extra-traits", "full", "visit", "visit-mut"] }
111111
syn-f595c2ba2a3f28df = { package = "syn", version = "2.0.39", features = ["extra-traits", "full", "visit-mut"] }
112112
textwrap = { version = "0.16.0", default-features = false, features = ["terminal_size"] }
113+
tikv-jemalloc-sys = { version = "0.5.2", features = ["background_threads", "profiling", "stats", "unprefixed_malloc_on_supported_platforms"] }
113114
time = { version = "0.3.17", features = ["macros", "quickcheck", "serde-well-known"] }
114115
tokio = { version = "1.32.0", features = ["full", "stats", "test-util", "tracing"] }
115116
tokio-postgres = { git = "https://github.com/MaterializeInc/rust-postgres", features = ["serde", "with-chrono-0_4", "with-serde_json-1", "with-uuid-1"] }
@@ -233,6 +234,7 @@ subtle = { version = "2.4.1" }
233234
syn-dff4ba8e3ae991db = { package = "syn", version = "1.0.107", features = ["extra-traits", "full", "visit", "visit-mut"] }
234235
syn-f595c2ba2a3f28df = { package = "syn", version = "2.0.39", features = ["extra-traits", "full", "visit-mut"] }
235236
textwrap = { version = "0.16.0", default-features = false, features = ["terminal_size"] }
237+
tikv-jemalloc-sys = { version = "0.5.2", features = ["background_threads", "profiling", "stats", "unprefixed_malloc_on_supported_platforms"] }
236238
time = { version = "0.3.17", features = ["macros", "quickcheck", "serde-well-known"] }
237239
time-macros = { version = "0.2.6", default-features = false, features = ["formatting", "parsing", "serde"] }
238240
tokio = { version = "1.32.0", features = ["full", "stats", "test-util", "tracing"] }
@@ -264,14 +266,12 @@ bitflags = { version = "2.4.1", default-features = false, features = ["std"] }
264266
native-tls = { version = "0.2.11", default-features = false, features = ["vendored"] }
265267
openssl-sys = { version = "0.9.90", default-features = false, features = ["vendored"] }
266268
ring = { version = "0.17.7", features = ["std"] }
267-
tikv-jemalloc-sys = { version = "0.5.2", features = ["background_threads", "profiling", "stats", "unprefixed_malloc_on_supported_platforms"] }
268269

269270
[target.x86_64-unknown-linux-gnu.build-dependencies]
270271
bitflags = { version = "2.4.1", default-features = false, features = ["std"] }
271272
native-tls = { version = "0.2.11", default-features = false, features = ["vendored"] }
272273
openssl-sys = { version = "0.9.90", default-features = false, features = ["vendored"] }
273274
ring = { version = "0.17.7", features = ["std"] }
274-
tikv-jemalloc-sys = { version = "0.5.2", features = ["background_threads", "profiling", "stats", "unprefixed_malloc_on_supported_platforms"] }
275275

276276
[target.x86_64-apple-darwin.dependencies]
277277
native-tls = { version = "0.2.11", default-features = false, features = ["vendored"] }

0 commit comments

Comments
 (0)