kata-containers / cgroups-rs

Native Rust library for managing control groups under Linux
https://crates.io/crates/cgroups-rs
Other
114 stars 45 forks source link

Setting "-1" to memory.max/memory.swap.max get an "invalid argument" error in cgroup v2 #128

Closed mzweilz closed 11 months ago

mzweilz commented 11 months ago

Describe the bug When setting memory.max/memory.swap.max in cgroup v2, Linux uses "max" instead of "-1" to indicate no restriction on memory usage. The set_limit and set_memswap_limit functions of the memory controller accept i64 as a parameter. In cgroupv2, if the parameter is -1, "max" should be written into the cgroup file.

Expected behavior Setting "-1" to memory.max/memory.swap.max using memory_container.set_limit(-1) and memory_controller.set_memswap_limit(-1) should success in cgroup v2 instead of return an "invalid argument" error.

Additional context https://facebookmicrosites.github.io/cgroup2/docs/memory-controller.html