Skip to content

Commit

Permalink
Use jemalloc allocator
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Volodkin <vladvolodkin@gmail.com>
  • Loading branch information
vladem committed Aug 30, 2024
1 parent 23f8fdc commit fdd49f4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
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 fdd49f4

Please sign in to comment.