Skip to main content

cgroup_memory_limit_bytes

Function cgroup_memory_limit_bytes 

Source
fn cgroup_memory_limit_bytes() -> Result<Option<u64>, Report>
Expand description

Returns the effective cgroup memory limit for the current process, in bytes.

Specification:

  • Read /proc/self/cgroup and extract:
    • the cgroup v2 relative path (0::...) when present, and
    • the cgroup v1 memory controller relative path (...:memory:...) when present.
  • Probe candidate limit files in this order:
    • v2: process-specific /sys/fs/cgroup/<path>/memory.max, then root fallback /sys/fs/cgroup/memory.max;
    • v1: process-specific /sys/fs/cgroup/memory/<path>/memory.limit_in_bytes, then root fallback /sys/fs/cgroup/memory/memory.limit_in_bytes.
  • Missing files are treated as unavailable and skipped.
  • Unlimited values (max in v2, very large sentinel in v1) are treated as None.
  • If both v1 and v2 limits are available, return the tighter (min) limit.
  • If only one limit is available, return that limit; if neither is available, return None.