opencontainers / runc

CLI tool for spawning and running containers according to the OCI specification
https://www.opencontainers.org/
Apache License 2.0
11.76k stars 2.09k forks source link

[ci] We should check `memory.swap.max` exists or not for cgroupv2 #4166

Closed lifubang closed 3 months ago

lifubang commented 8 months ago

I think in some old kernel with cgroupv2 enabled, memory.swap.max is not exist. For example:

Linux iZj6cdnzj9sp96xf38htrnZ 5.4.0-169-generic #187-Ubuntu SMP Thu Nov 23 14:52:28 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

root@iZj6cdnzj9sp96xf38htrnZ:~# ls /sys/fs/cgroup/user.slice/user-0.slice/session-1.scope/
cgroup.controllers      cgroup.stat             cpuset.cpus            cpu.uclamp.max   io.stat              memory.low        pids.current
cgroup.events           cgroup.subtree_control  cpuset.cpus.effective  cpu.uclamp.min   io.weight            memory.max        pids.events
cgroup.freeze           cgroup.threads          cpuset.cpus.partition  cpu.weight       memory.current       memory.min        pids.max
cgroup.max.depth        cgroup.type             cpuset.mems            cpu.weight.nice  memory.events        memory.oom.group  rdma.current
cgroup.max.descendants  cpu.max                 cpuset.mems.effective  io.max           memory.events.local  memory.pressure   rdma.max
cgroup.procs            cpu.pressure            cpu.stat               io.pressure      memory.high          memory.stat

Then we will get some errors when setting memory swap limit:

not ok 164 update cgroup v1/v2 common limits
# (in test file tests/integration/update.bats, line 103)
#   `[ "$status" -eq 0 ]' failed
# runc spec (status=0):
#
# runc run -d --console-socket /tmp/bats-run-YCqIW9/runc.6WEppA/tty/sock test_update (status=0):
#
# current 33554432 !? 33554432
# current 25165824 !? 25165824
# current 20 !? 20
# runc update test_update --cpuset-cpus 1 (status=0):
#
# current 1 !? 1
# runc update test_update --memory 67108864 (status=0):
#
# current 67108864 !? 67108864
# runc update test_update --memory 50M (status=0):
#
# current 52428800 !? 52428800
# runc update test_update --memory-reservation 33554432 (status=0):
#
# current 33554432 !? 33554432
# runc update test_update --memory-swap -1 (status=1):
# time="2024-01-08T11:36:37+08:00" level=warning msg="Setting back cgroup configs failed due to error: open /sys/fs/cgroup/runc-cgroups-integration-test/test-cgroup-12193/memory.swap.max: no such file or directory, your state.json and actual configs might be inconsistent."
# time="2024-01-08T11:36:37+08:00" level=error msg="open /sys/fs/cgroup/runc-cgroups-integration-test/test-cgroup-12193/memory.swap.max: no such file or directory"
kolyshkin commented 7 months ago

Should be fixed by #4188.

I think in some old kernel with cgroupv2 enabled, memory.swap.max is not exist.

I think this can just be that CONFIG_SWAP is not set in the kernel config (i.e. any kernel, not just some old one).