runc/libcontainer/cgroups
Kir Kolyshkin 6905b72154 cgroupv2: use "max" for negative values
Cgroup v1 kernel doc [1] says:

> We can write "-1" to reset the ``*.limit_in_bytes(unlimited)``.

and cgroup v2 kernel documentation [2] says:

> - If a controller implements an absolute resource guarantee and/or
>  limit, the interface files should be named "min" and "max"
>  respectively.  If a controller implements best effort resource
>  guarantee and/or limit, the interface files should be named "low"
>  and "high" respectively.
>
>  In the above four control files, the special token "max" should be
>  used to represent upward infinity for both reading and writing.

Allow -1 value to still be used for v2, converting it to "max"
where it makes sense to do so.

This fixes the following issue:

> runc update test_update --memory-swap -1:
> error while setting cgroup v2: [write /sys/fs/cgroup/machine.slice/runc-cgroups-integration-test.scope/memory.swap.max: invalid argument
> failed to write "-1" to "/sys/fs/cgroup/machine.slice/runc-cgroups-integration-test.scope/memory.swap.max"
> github.com/opencontainers/runc/libcontainer/cgroups/fscommon.WriteFile
> 	/home/kir/go/src/github.com/opencontainers/runc/libcontainer/cgroups/fscommon/fscommon.go:21
> github.com/opencontainers/runc/libcontainer/cgroups/fs2.setMemory
> 	/home/kir/go/src/github.com/opencontainers/runc/libcontainer/cgroups/fs2/memory.go:20
> github.com/opencontainers/runc/libcontainer/cgroups/fs2.(*manager).Set
> 	/home/kir/go/src/github.com/opencontainers/runc/libcontainer/cgroups/fs2/fs2.go:175
> github.com/opencontainers/runc/libcontainer/cgroups/systemd.(*UnifiedManager).Set
> 	/home/kir/go/src/github.com/opencontainers/runc/libcontainer/cgroups/systemd/unified_hierarchy.go:290
> github.com/opencontainers/runc/libcontainer.(*linuxContainer).Set
> 	/home/kir/go/src/github.com/opencontainers/runc/libcontainer/container_linux.go:211

[1] linux/Documentation/admin-guide/cgroup-v1/memory.rst
[2] linux/Documentation/admin-guide/cgroup-v2.rst

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-03-26 11:14:32 -07:00
..
ebpf cgroup2: ebpf: increase RLIM_MEMLOCK to avoid BPF_PROG_LOAD error 2019-11-07 15:43:27 +09:00
fs Fix skip message for cgroupv2 2020-02-03 14:27:12 +02:00
fs2 cgroupv2: use "max" for negative values 2020-03-26 11:14:32 -07:00
fscommon cgroup2: split fs2 from fs 2019-12-06 15:42:10 +09:00
systemd cgroupv2: don't try to set kmem for systemd case 2020-03-25 20:00:23 -07:00
cgroups.go libcontainer: add method to get cgroup config from cgroup Manager 2019-12-17 22:46:03 +00:00
cgroups_test.go .travis.yml: add Fedora 31 vagrant box (for cgroup2) 2019-10-31 16:53:01 +09:00
cgroups_unsupported.go Move libcontainer into subdirectory 2015-06-21 19:29:15 -07:00
stats.go Expose memory.use_hierarchy in MemoryStats 2017-03-31 13:40:34 -04:00
utils.go libcontainer/cgroups: GetAllPids: optimize 2020-03-20 12:27:36 -07:00
utils_test.go cgroup2: add CpuMax conversion 2020-03-13 02:58:39 +09:00