Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix jemalloc memory measurements. #4917

Merged
merged 1 commit into from Feb 13, 2015
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Fix jemalloc memory measurements.

It turns out you need to send an "epoch" request to jemalloc before
asking for a measurement otherwise you get stale data! Heavens.
  • Loading branch information
nnethercote committed Feb 13, 2015
commit eaee46de7cd2fc3958b2f7eb9bdd95ae48a62d96
@@ -198,17 +198,31 @@ extern {
newp: *mut c_void, newlen: size_t) -> c_int;
}

fn get_jemalloc_stat(name: &'static str) -> Option<u64> {
let mut old: size_t = 0;
let c_name = CString::from_slice(name.as_bytes());
let oldp = &mut old as *mut _ as *mut c_void;
let mut oldlen = size_of::<size_t>() as size_t;
let rv: c_int;
fn get_jemalloc_stat(value_name: &str) -> Option<u64> {
// Before we request the measurement of interest, we first send an "epoch"
// request. Without that jemalloc gives cached statistics(!) which can be
// highly inaccurate.
let epoch_name = "epoch";
let epoch_c_name = CString::from_slice(epoch_name.as_bytes());
let mut epoch: u64 = 0;
let epoch_ptr = &mut epoch as *mut _ as *mut c_void;
let mut epoch_len = size_of::<u64>() as size_t;

let value_c_name = CString::from_slice(value_name.as_bytes());
let mut value: size_t = 0;
let value_ptr = &mut value as *mut _ as *mut c_void;
let mut value_len = size_of::<size_t>() as size_t;

let mut rv: c_int;
unsafe {
rv = je_mallctl(c_name.as_ptr(), oldp, &mut oldlen, null_mut(), 0);
mem::forget(c_name); // XXX correct?
// Using the same values for the `old` and `new` parameters is enough
// to get the statistics updated.
rv = je_mallctl(epoch_c_name.as_ptr(), epoch_ptr, &mut epoch_len, epoch_ptr, epoch_len);
if rv == 0 {
rv = je_mallctl(value_c_name.as_ptr(), value_ptr, &mut value_len, null_mut(), 0);
}
}
if rv == 0 { Some(old as u64) } else { None }
if rv == 0 { Some(value as u64) } else { None }
}

// Like std::macros::try!, but for Option<>.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.