Skip to content

Commit 40e1a62

Browse files
authored
Add compile-time support for mimalloc (#592)
Microsoft's `mimalloc` is a general purpose allocator with excellent performance characteristics and, furthermore, it implements defensive security features to protect against heap vulnerabilities. See https://github.com/microsoft/mimalloc. In initial tests, it appears that it may improve latency at the cost of ~20% memory overhead. This change primarily enables further testing, since it doesn't seem worth taking the memory overhead at this point.
1 parent 834942d commit 40e1a62

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

Cargo.lock

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,15 @@ dependencies = [
207207
"bitflags",
208208
]
209209

210+
[[package]]
211+
name = "cmake"
212+
version = "0.1.41"
213+
source = "registry+https://github.com/rust-lang/crates.io-index"
214+
checksum = "3c84c596dcf125d6781f58e3f4254677ec2a6d8aa56e8501ac277100990b3229"
215+
dependencies = [
216+
"cc",
217+
]
218+
210219
[[package]]
211220
name = "crc"
212221
version = "1.7.0"
@@ -692,6 +701,15 @@ version = "0.2.65"
692701
source = "registry+https://github.com/rust-lang/crates.io-index"
693702
checksum = "1a31a0627fdf1f6a39ec0dd577e101440b7db22672c0901fe00a9a6fbb5c24e8"
694703

704+
[[package]]
705+
name = "libmimalloc-sys"
706+
version = "0.1.15"
707+
source = "registry+https://github.com/rust-lang/crates.io-index"
708+
checksum = "a27252ec1d0c4e0dd6142cbc572da50b363ab56fc334f7aa8fadf295b2e24e74"
709+
dependencies = [
710+
"cmake",
711+
]
712+
695713
[[package]]
696714
name = "linked-hash-map"
697715
version = "0.5.3"
@@ -1146,6 +1164,7 @@ dependencies = [
11461164
"futures 0.3.5",
11471165
"linkerd2-app",
11481166
"linkerd2-signal",
1167+
"mimalloc",
11491168
"tokio",
11501169
"tracing",
11511170
]
@@ -1566,6 +1585,15 @@ version = "2.3.3"
15661585
source = "registry+https://github.com/rust-lang/crates.io-index"
15671586
checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
15681587

1588+
[[package]]
1589+
name = "mimalloc"
1590+
version = "0.1.19"
1591+
source = "registry+https://github.com/rust-lang/crates.io-index"
1592+
checksum = "6c52de2069999f01bd26436564dbe7de3a87898feeb7a0d0ff9eb20a05bb7ca0"
1593+
dependencies = [
1594+
"libmimalloc-sys",
1595+
]
1596+
15691597
[[package]]
15701598
name = "miniz_oxide"
15711599
version = "0.1.2"

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ ARG PROXY_FEATURES
3737

3838
RUN --mount=type=cache,target=/var/lib/apt/lists \
3939
--mount=type=cache,target=/var/tmp \
40-
apt update && apt install -y time
40+
apt update && apt install -y time cmake
4141

4242
WORKDIR /usr/src/linkerd2-proxy
4343
COPY . .

linkerd2-proxy/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ mock-orig-dst = ["linkerd2-app/mock-orig-dst"]
1111

1212
[dependencies]
1313
futures = { version = "0.3", features = ["compat"] }
14+
mimalloc = { version = "0.1.19", optional = true }
1415
linkerd2-app = { path = "../linkerd/app" }
1516
linkerd2-signal = { path = "../linkerd/signal" }
1617
tokio = { version = "0.2", features = ["rt-core"] }

linkerd2-proxy/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ use linkerd2_app::{trace, Config};
88
use linkerd2_signal as signal;
99
pub use tracing::{debug, error, info, warn};
1010

11+
#[cfg(feature = "mimalloc")]
12+
#[global_allocator]
13+
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
14+
1115
#[tokio::main(basic_scheduler)]
1216
async fn main() {
1317
let trace = trace::init();

0 commit comments

Comments
 (0)