#allocator #jemalloc

tikv-jemalloc-ctl

A safe wrapper over jemalloc's control and introspection APIs

4 releases

0.5.0 May 24, 2022
0.4.2 Aug 9, 2021
0.4.1 Nov 17, 2020
0.4.0 Jul 21, 2020

#104 in Memory management

Download history 23922/week @ 2023-02-10 22508/week @ 2023-02-17 20763/week @ 2023-02-24 20295/week @ 2023-03-03 24016/week @ 2023-03-10 26046/week @ 2023-03-17 24373/week @ 2023-03-24 23409/week @ 2023-03-31 23377/week @ 2023-04-07 21229/week @ 2023-04-14 22843/week @ 2023-04-21 21095/week @ 2023-04-28 22926/week @ 2023-05-05 26862/week @ 2023-05-12 34029/week @ 2023-05-19 29678/week @ 2023-05-26

118,623 downloads per month
Used in 13 crates (9 directly)

MIT/Apache

2MB
51K SLoC

C 47K SLoC // 0.1% comments Rust 1.5K SLoC // 0.0% comments Visual Studio Project 758 SLoC Shell 380 SLoC // 0.3% comments C++ 371 SLoC // 0.1% comments Python 261 SLoC // 0.3% comments Visual Studio Solution 125 SLoC XSL 9 SLoC

jemalloc-ctl

Travis-CI Status Latest Version docs

A safe wrapper over jemalloc's mallctl*() control and introspection APIs.

Documentation

Platform support

Supported on all platforms supported by the tikv-jemallocator crate.

Example


use std::thread;
use std::time::Duration;
use tikv_jemalloc_ctl::{stats, epoch};

#[global_allocator]
static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;

fn main() {
    // Obtain a MIB for the `epoch`, `stats.allocated`, and
    // `atats.resident` keys:
    let e = epoch::mib().unwrap();
    let allocated = stats::allocated::mib().unwrap();
    let resident = stats::resident::mib().unwrap();
    
    loop {
        // Many statistics are cached and only updated 
        // when the epoch is advanced:
        e.advance().unwrap();
        
        // Read statistics using MIB key:
        let allocated = allocated.read().unwrap();
        let resident = resident.read().unwrap();
        println!("{} bytes allocated/{} bytes resident", allocated, resident);
        thread::sleep(Duration::from_secs(10));
    }
}

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in jemalloc-ctl by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies