Skip to content

Commit

Permalink
Use jemalloc (#1321)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
olix0r authored Oct 22, 2021
1 parent 23be602 commit 0ac4f3f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
47 changes: 28 additions & 19 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ dependencies = [
"percent-encoding",
]

[[package]]
name = "fs_extra"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394"

[[package]]
name = "futures"
version = "0.3.17"
Expand Down Expand Up @@ -549,6 +555,27 @@ version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"

[[package]]
name = "jemalloc-sys"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d3b9f3f5c9b31aa0f5ed3260385ac205db665baa41d49bb8338008ae94ede45"
dependencies = [
"cc",
"fs_extra",
"libc",
]

[[package]]
name = "jemallocator"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43ae63fcfc45e99ab3d1b29a46782ad679e98436c3169d15a167a1108a724b69"
dependencies = [
"jemalloc-sys",
"libc",
]

[[package]]
name = "js-sys"
version = "0.3.55"
Expand Down Expand Up @@ -581,15 +608,6 @@ dependencies = [
"once_cell",
]

[[package]]
name = "libmimalloc-sys"
version = "0.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d1b8479c593dba88c2741fc50b92e13dbabbbe0bd504d979f244ccc1a5b1c01"
dependencies = [
"cc",
]

[[package]]
name = "linked-hash-map"
version = "0.5.4"
Expand Down Expand Up @@ -1469,9 +1487,9 @@ name = "linkerd2-proxy"
version = "0.1.0"
dependencies = [
"futures",
"jemallocator",
"linkerd-app",
"linkerd-signal",
"mimalloc",
"num_cpus",
"tokio",
"tracing",
Expand Down Expand Up @@ -1548,15 +1566,6 @@ version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"

[[package]]
name = "mimalloc"
version = "0.1.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb74897ce508e6c49156fd1476fc5922cbc6e75183c65e399c765a09122e5130"
dependencies = [
"libmimalloc-sys",
]

[[package]]
name = "miniz_oxide"
version = "0.4.4"
Expand Down
4 changes: 3 additions & 1 deletion linkerd2-proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ multicore = ["tokio/rt-multi-thread", "num_cpus"]

[dependencies]
futures = { version = "0.3", default-features = false }
mimalloc = { version = "0.1.26", optional = true }
num_cpus = { version = "1", optional = true }
linkerd-app = { path = "../linkerd/app" }
linkerd-signal = { path = "../linkerd/signal" }
tokio = { version = "1", features = ["rt", "time", "net"] }
tracing = "0.1.29"

[target.x86_64-unknown-linux-gnu.dependencies]
jemallocator = { version = "0.3" }
4 changes: 2 additions & 2 deletions linkerd2-proxy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use linkerd_signal as signal;
use tokio::sync::mpsc;
pub use tracing::{debug, error, info, warn};

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

mod rt;

Expand Down

0 comments on commit 0ac4f3f

Please sign in to comment.