Skip to content

Commit f4bb825

Browse files
authored
Add feature to use jemalloc as memory allocator (#4571)
## Motivation jemalloc is more performant than the system allocator (and was even the Rust default for a while) ## Proposal Add a feature that when enabled will use jemalloc as the allocator. We might decide to have this feature on by default eventually, but for now it'll be used for memory profiling, which is coming in the following PRs. ## Test Plan Deployed a network with this featured turned on, saw a slight performance improvement, and tested with the profiling code. ## Release Plan - Nothing to do / These changes follow the usual release cycle.
1 parent a85ca4e commit f4bb825

File tree

6 files changed

+39
-0
lines changed

6 files changed

+39
-0
lines changed

Cargo.lock

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ test-log = { version = "0.2.15", default-features = false, features = [
234234
test-strategy = "0.3.1"
235235
thiserror = "1.0.65"
236236
thiserror-context = "0.1.1"
237+
tikv-jemallocator = "0.6.0"
237238
tokio = "1.36.0"
238239
tokio-stream = "0.1.14"
239240
tokio-test = "0.4.3"

linera-service/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ metrics = [
5252
"linera-faucet-server/metrics",
5353
"linera-metrics",
5454
]
55+
jemalloc = ["tikv-jemallocator"]
5556
storage-service = ["linera-storage-service"]
5657

5758
[dependencies]
@@ -119,6 +120,10 @@ serde_json.workspace = true
119120
stdext = { workspace = true, optional = true }
120121
tempfile.workspace = true
121122
thiserror.workspace = true
123+
tikv-jemallocator = { workspace = true, features = [
124+
"profiling",
125+
"unprefixed_malloc_on_supported_platforms",
126+
], optional = true }
122127
tokio = { workspace = true, features = ["full"] }
123128
tokio-stream.workspace = true
124129
tokio-util.workspace = true

linera-service/src/cli/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
#![recursion_limit = "256"]
66

7+
#[cfg(feature = "jemalloc")]
8+
#[global_allocator]
9+
static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
10+
711
use std::{
812
collections::{BTreeMap, BTreeSet},
913
env,

linera-service/src/proxy/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Copyright (c) Zefchain Labs, Inc.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
#[cfg(feature = "jemalloc")]
5+
#[global_allocator]
6+
static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
7+
48
use std::{net::SocketAddr, path::PathBuf, time::Duration};
59

610
use anyhow::{anyhow, bail, ensure, Result};

linera-service/src/server.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// Copyright (c) Zefchain Labs, Inc.
33
// SPDX-License-Identifier: Apache-2.0
44

5+
#[cfg(feature = "jemalloc")]
6+
#[global_allocator]
7+
static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
8+
59
use std::{
610
borrow::Cow,
711
num::NonZeroU16,

0 commit comments

Comments
 (0)