Skip to content

Commit

Permalink
Use jemalloc allocator
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Volodkin <[email protected]>
  • Loading branch information
vladem committed Sep 2, 2024
1 parent 23f8fdc commit b0ad94d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions mountpoint-s3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ tracing-log = "0.2.0"
tracing-subscriber = { version = "0.3.14", features = ["env-filter"] }
async-stream = "0.3.5"
humansize = "2.1.3"
tikv-jemalloc-ctl = { version = "0.6.0", features = ["profiling", "stats"] }
tikv-jemallocator = "0.6.0"

[target.'cfg(target_os = "linux")'.dependencies]
procfs = { version = "0.16.0", default-features = false }
Expand Down
3 changes: 3 additions & 0 deletions mountpoint-s3/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[global_allocator]
static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;

fn main() -> anyhow::Result<()> {
mountpoint_s3::cli::main(mountpoint_s3::cli::create_s3_client)
}
13 changes: 13 additions & 0 deletions mountpoint-s3/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::time::Duration;
use dashmap::DashMap;
use metrics::{Key, Metadata, Recorder};
use sysinfo::{get_current_pid, MemoryRefreshKind, ProcessRefreshKind, System};
use tikv_jemalloc_ctl::{epoch, stats};

use crate::sync::mpsc::{channel, RecvTimeoutError, Sender};
use crate::sync::Arc;
Expand Down Expand Up @@ -80,6 +81,18 @@ fn poll_process_metrics(sys: &mut System) {
metrics::gauge!("system.available_memory").set(sys.available_memory() as f64);
}
}
epoch::advance().unwrap();

let allocated = stats::allocated::read().unwrap();
let active = stats::active::read().unwrap();
let mapped = stats::mapped::read().unwrap();
let retained = stats::retained::read().unwrap();
let resident = stats::resident::read().unwrap();
metrics::gauge!("process.jemalloc.allocated").set(allocated as f64);
metrics::gauge!("process.jemalloc.active").set(active as f64);
metrics::gauge!("process.jemalloc.mapped").set(mapped as f64);
metrics::gauge!("process.jemalloc.retained").set(retained as f64);
metrics::gauge!("process.jemalloc.resident").set(resident as f64);
}
}

Expand Down

0 comments on commit b0ad94d

Please sign in to comment.