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/cgroupand extract:- the cgroup v2 relative path (
0::...) when present, and - the cgroup v1
memorycontroller relative path (...:memory:...) when present.
- the cgroup v2 relative path (
- 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.
- v2: process-specific
- Missing files are treated as unavailable and skipped.
- Unlimited values (
maxin v2, very large sentinel in v1) are treated asNone. - 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.