Skip to content

Commit c3272b0

Browse files
committed
Use jemalloc (#1321)
In load tests, it appears that jemalloc is--perhaps unsurprisingly--more efficient than the alternatives. Specifically, jemalloc uses less memory and is more responsive to memory being released without substantially impacting latency or CPU usage. This is only enabled on `x86_64-unknown-linux-gnu`, as this is the only platform on which all tests pass, etc (per [gnzlbg/jemallocator][readme]). [readme]: https://github.com/gnzlbg/jemallocator/tree/c27a859e98e3cb790dc269773d9da71a1e918458#platform-support
1 parent a3aac7c commit c3272b0

File tree

3 files changed

+33
-22
lines changed

3 files changed

+33
-22
lines changed

Cargo.lock

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,12 @@ dependencies = [
226226
"percent-encoding",
227227
]
228228

229+
[[package]]
230+
name = "fs_extra"
231+
version = "1.2.0"
232+
source = "registry+https://github.com/rust-lang/crates.io-index"
233+
checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394"
234+
229235
[[package]]
230236
name = "futures"
231237
version = "0.3.17"
@@ -549,6 +555,27 @@ version = "0.4.8"
549555
source = "registry+https://github.com/rust-lang/crates.io-index"
550556
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
551557

558+
[[package]]
559+
name = "jemalloc-sys"
560+
version = "0.3.2"
561+
source = "registry+https://github.com/rust-lang/crates.io-index"
562+
checksum = "0d3b9f3f5c9b31aa0f5ed3260385ac205db665baa41d49bb8338008ae94ede45"
563+
dependencies = [
564+
"cc",
565+
"fs_extra",
566+
"libc",
567+
]
568+
569+
[[package]]
570+
name = "jemallocator"
571+
version = "0.3.2"
572+
source = "registry+https://github.com/rust-lang/crates.io-index"
573+
checksum = "43ae63fcfc45e99ab3d1b29a46782ad679e98436c3169d15a167a1108a724b69"
574+
dependencies = [
575+
"jemalloc-sys",
576+
"libc",
577+
]
578+
552579
[[package]]
553580
name = "js-sys"
554581
version = "0.3.55"
@@ -581,15 +608,6 @@ dependencies = [
581608
"once_cell",
582609
]
583610

584-
[[package]]
585-
name = "libmimalloc-sys"
586-
version = "0.1.22"
587-
source = "registry+https://github.com/rust-lang/crates.io-index"
588-
checksum = "1d1b8479c593dba88c2741fc50b92e13dbabbbe0bd504d979f244ccc1a5b1c01"
589-
dependencies = [
590-
"cc",
591-
]
592-
593611
[[package]]
594612
name = "linked-hash-map"
595613
version = "0.5.4"
@@ -1456,9 +1474,9 @@ name = "linkerd2-proxy"
14561474
version = "0.1.0"
14571475
dependencies = [
14581476
"futures",
1477+
"jemallocator",
14591478
"linkerd-app",
14601479
"linkerd-signal",
1461-
"mimalloc",
14621480
"num_cpus",
14631481
"tokio",
14641482
"tracing",
@@ -1535,15 +1553,6 @@ version = "2.4.1"
15351553
source = "registry+https://github.com/rust-lang/crates.io-index"
15361554
checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
15371555

1538-
[[package]]
1539-
name = "mimalloc"
1540-
version = "0.1.26"
1541-
source = "registry+https://github.com/rust-lang/crates.io-index"
1542-
checksum = "fb74897ce508e6c49156fd1476fc5922cbc6e75183c65e399c765a09122e5130"
1543-
dependencies = [
1544-
"libmimalloc-sys",
1545-
]
1546-
15471556
[[package]]
15481557
name = "miniz_oxide"
15491558
version = "0.4.4"

linkerd2-proxy/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ multicore = ["tokio/rt-multi-thread", "num_cpus"]
1313

1414
[dependencies]
1515
futures = { version = "0.3", default-features = false }
16-
mimalloc = { version = "0.1.26", optional = true }
1716
num_cpus = { version = "1", optional = true }
1817
linkerd-app = { path = "../linkerd/app" }
1918
linkerd-signal = { path = "../linkerd/signal" }
2019
tokio = { version = "1", features = ["rt", "time", "net"] }
2120
tracing = "0.1.28"
21+
22+
[target.x86_64-unknown-linux-gnu.dependencies]
23+
jemallocator = { version = "0.3" }

linkerd2-proxy/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use linkerd_signal as signal;
99
use tokio::sync::mpsc;
1010
pub use tracing::{debug, error, info, warn};
1111

12-
#[cfg(feature = "mimalloc")]
12+
#[cfg(all(target_os = "linux", target_arch = "x86_64", target_env = "gnu"))]
1313
#[global_allocator]
14-
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
14+
static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc;
1515

1616
mod rt;
1717

0 commit comments

Comments
 (0)