Skip to content

Commit 5479f61

Browse files
committed
Revert to jemalloc allocator
1 parent f28cb49 commit 5479f61

File tree

26 files changed

+74
-170
lines changed

26 files changed

+74
-170
lines changed

.github/workflows/deploy-profiling.yaml

Lines changed: 0 additions & 82 deletions
This file was deleted.

.github/workflows/deploy.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ on:
44
branches: [main]
55
tags: [v*]
66
workflow_dispatch:
7+
inputs:
8+
features:
9+
description: 'Optional cargo features (currently supported: "mimalloc-allocator")'
10+
required: false
11+
default: ''
712

813
jobs:
914
deploy:
@@ -40,6 +45,8 @@ jobs:
4045
push: true
4146
tags: ${{ steps.meta_services.outputs.tags }}
4247
labels: ${{ steps.meta_services.outputs.labels }}
48+
build-args: |
49+
CARGO_BUILD_FEATURES=${{ github.event.inputs.features && format('--features {0}', github.event.inputs.features) || '' }}
4350
4451
- name: Migration image metadata
4552
id: meta_migration

Cargo.lock

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

Dockerfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ ARG CARGO_BUILD_FEATURES=""
1010

1111
# Install dependencies
1212
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked apt-get update && \
13-
apt-get install -y git libssl-dev pkg-config && \
14-
if echo "${CARGO_BUILD_FEATURES}" | grep -q "jemalloc-profiling"; then \
15-
apt-get install -y build-essential; \
16-
fi
13+
apt-get install -y git libssl-dev pkg-config build-essential
1714
# Install Rust toolchain
1815
RUN rustup install stable && rustup default stable
1916

README.md

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,28 +113,22 @@ tokio-console
113113

114114
## Heap Profiling
115115

116-
All binaries support opt-in heap profiling using jemalloc's profiling capabilities. This allows you to analyze memory usage in production environments without restarting services.
116+
All binaries use jemalloc as the default memory allocator with built-in heap profiling support. Profiling is enabled at runtime via the `MALLOC_CONF` environment variable, allowing you to analyze memory usage in production environments without recompiling or restarting services.
117117

118-
### Building with Heap Profiling
118+
**Note:** You can optionally use mimalloc instead of jemalloc by building with `--features mimalloc-allocator`, but this disables heap profiling capability.
119119

120-
Build with the `jemalloc-profiling` feature:
121-
```bash
122-
cargo build --release --features jemalloc-profiling
123-
```
120+
### Enabling Heap Profiling
124121

125-
Or with Docker:
122+
To enable heap profiling, run services with the `MALLOC_CONF` environment variable set:
126123
```bash
127-
docker build --build-arg CARGO_BUILD_FEATURES="--features jemalloc-profiling" .
124+
MALLOC_CONF="prof:true,prof_active:true,lg_prof_sample:22"
128125
```
129126

130-
### Generating Heap Dumps
127+
When profiling is enabled, each binary opens a UNIX socket at `/tmp/heap_dump_<binary_name>.sock`.
131128

132-
When running with the profiling feature enabled, each binary opens a UNIX socket at `/tmp/heap_dump_<binary_name>.sock`. To generate a heap dump, connect to the socket and send the "dump" command:
129+
### Generating Heap Dumps
133130

134-
**Note:** Services must be run with the `MALLOC_CONF` environment variable set:
135-
```bash
136-
MALLOC_CONF="prof:true,prof_active:true,lg_prof_sample:19"
137-
```
131+
Connect to the socket and send the "dump" command:
138132

139133
```bash
140134
# From Kubernetes

crates/alerter/Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ anyhow = { workspace = true }
1111
clap = { workspace = true }
1212
humantime = { workspace = true }
1313
observe = { workspace = true }
14-
mimalloc = { workspace = true }
15-
tikv-jemallocator = { workspace = true, optional = true }
16-
jemalloc_pprof = { workspace = true, optional = true }
14+
mimalloc = { workspace = true, optional = true }
15+
tikv-jemallocator = { workspace = true }
1716
model = { workspace = true }
1817
number = { workspace = true }
1918
prometheus = { workspace = true }
@@ -30,4 +29,4 @@ warp = { workspace = true }
3029
workspace = true
3130

3231
[features]
33-
jemalloc-profiling = ["dep:tikv-jemallocator", "dep:jemalloc_pprof", "observe/jemalloc-profiling"]
32+
mimalloc-allocator = ["dep:mimalloc"]

crates/alerter/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ pub async fn start(args: impl Iterator<Item = String>) {
392392
);
393393
observe::tracing::initialize(&obs_config);
394394
observe::panic_hook::install();
395-
#[cfg(all(unix, feature = "jemalloc-profiling"))]
395+
#[cfg(unix)]
396396
observe::heap_dump_handler::spawn_heap_dump_handler();
397397
observe::metrics::setup_registry(Some("gp_v2_alerter".to_string()), None);
398398
tracing::info!("running alerter with {:#?}", args);

crates/alerter/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#[cfg(feature = "jemalloc-profiling")]
1+
#[cfg(feature = "mimalloc-allocator")]
22
#[global_allocator]
3-
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
3+
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
44

5-
#[cfg(not(feature = "jemalloc-profiling"))]
5+
#[cfg(not(feature = "mimalloc-allocator"))]
66
#[global_allocator]
7-
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
7+
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
88

99
#[tokio::main]
1010
async fn main() {

crates/autopilot/Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ humantime = { workspace = true }
3939
indexmap = { workspace = true }
4040
itertools = { workspace = true }
4141
maplit = { workspace = true }
42-
mimalloc = { workspace = true }
43-
tikv-jemallocator = { workspace = true, optional = true }
44-
jemalloc_pprof = { workspace = true, optional = true }
42+
mimalloc = { workspace = true, optional = true }
43+
tikv-jemallocator = { workspace = true }
4544
model = { workspace = true }
4645
num = { workspace = true }
4746
number = { workspace = true }
@@ -78,4 +77,4 @@ vergen = { workspace = true, features = ["git", "gitcl"] }
7877
workspace = true
7978

8079
[features]
81-
jemalloc-profiling = ["dep:tikv-jemallocator", "dep:jemalloc_pprof", "observe/jemalloc-profiling"]
80+
mimalloc-allocator = ["dep:mimalloc"]

crates/autopilot/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#[cfg(feature = "jemalloc-profiling")]
1+
#[cfg(feature = "mimalloc-allocator")]
22
#[global_allocator]
3-
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
3+
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
44

5-
#[cfg(not(feature = "jemalloc-profiling"))]
5+
#[cfg(not(feature = "mimalloc-allocator"))]
66
#[global_allocator]
7-
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
7+
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
88

99
#[tokio::main]
1010
async fn main() {

0 commit comments

Comments
 (0)