cgroup-memory 0.1.0

A library for reading and interpreting `/sys/fs/cgroup` memory statistics.
Documentation
  • Coverage
  • 14.71%
    10 out of 68 items documented4 out of 10 items with examples
  • Size
  • Source code size: 21.74 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 498.3 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • sdtnjung/cgroup-memory
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • sdtnjung

cgroup-memory

A Rust crate for reading and interpreting /sys/fs/cgroup memory statistics.

/sys/fs/cgroup/memory.stat
/sys/fs/cgroup/memory.max

Examples

Read total / max memory

match memory_max() {
    Ok(Some(v)) => println!("Max memory: {v}"),
    Ok(None) => println!("No max memory constraint"),
    Err(e) => println!("Failed to read and parse memory files: {e}"),
}

Calculate available memory

match memory_available() {
    Ok(Some(v)) => println!("Available memory: {v} bytes"),
    Ok(None) => println!("No memory limit set"),
    Err(e) => println!("Failed to read memory information: {}", e),
}

Development

Integration tests

These tests require environments with specific memory attributes. We utilize Docker to create such virtual Linux environments.

Note that memory.max only contains a valid value if the --memory option was specified.

Run

docker build -t cgroup-memory
# Run tests that expect 100mb of total memory
docker run --rm --memory=100m cgroup-memory /usr/local/bin/cargo-nextest ntr --archive-file test_memory_max_100m.tar.zst --workspace-remap . --no-capture