cgroupv2: set mem+swap to max if memory is set to max#2285
Conversation
In cgroupv1, command `runc update $ID --memory -1` sets both memory and memory+swap to -1 (aka unlimited). This was introduced by commit 18ebc51 (Reset Swap when memory is set to unlimited, Oct 19 2016). This is not the case for cgroupv2. Fix it. References: - opencontainers#1127 - moby/moby#22578 Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
|
The motivation for this PR is to make cgroupv2 behavior in this regard compatible with v1. Whether this v1 behavior is good or not I can't yet assess. Even after reading all the discussions linked above, I still do not understand whether it is useful to have unlimited RAM but limited RAM+swap. Probably not, but I'm not quite sure. |
|
Do we need this for systemd driver as well? |
|
cc @giuseppe |
@AkihiroSuda well, systemd driver
I found both of these items today, and they both probably need to be taken care of (and I will file issues and try to fix this), but as of now, this PR fixes the issue for both fs2 and systemd drivers. |
| } | ||
|
|
||
| if memSwap != "" { | ||
| if err := fscommon.WriteFile(dirPath, "memory.swap.max", memSwap); err != nil { |
There was a problem hiding this comment.
to keep the same cgroup v1 behaviour (as the config.json file is configured for), we need to set the memory swap to requested_memory_limit - requested_swap_limit. Since on cgroup v1 the swap limit accounts also for the memory
There was a problem hiding this comment.
Hmm, in this case maybe we don't need to touch swap at all, and this PR should be closed, right?
There was a problem hiding this comment.
yes setting the memory.max should be enough on cgroup v2 as the swap max should not have any effect on it.
There was a problem hiding this comment.
but since the PR is open, I think we could use it for setting the swap limit as it is expected to work on cgroup v1
|
This PR is wrong. Closed in favor of #2288 |
In cgroupv1, command
runc update $ID --memory -1sets bothmemory and memory+swap to -1 (aka unlimited). This was introduced
by commit 18ebc51 (Reset Swap when memory is set to unlimited,
Oct 19 2016).
This is not the case for cgroupv2. Fix it.
References: