cgroupv1: don't ignore MemorySwap if Memory==-1
Commit 18ebc51b3cc3 "Reset Swap when memory is set to unlimited (-1)" added handling of the case when a user updates the container limits to set memory to unlimited (-1) but do not set any other limits. Apparently, in this case, if swap limit was previously set, kernel fails to set memory.limit_in_bytes to -1 if memory.memsw.limit_in_bytes is not set to -1. What the above commit fails to handle correctly is the request when Memory is set to -1 and MemorySwap is set to some specific limit N (where N > 0). In this case, the value of N is silently discarded and MemorySwap is set to -1 instead. This is wrong thing to do, as the limit set, even if incorrectly, should not be ignored. Fix this by only assigning MemorySwap == -1 in case it was not explicitly set. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
parent
21cb2360b6
commit
d57f5bb286
|
@ -74,9 +74,9 @@ func (s *MemoryGroup) Apply(d *cgroupData) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func setMemoryAndSwap(path string, cgroup *configs.Cgroup) error {
|
func setMemoryAndSwap(path string, cgroup *configs.Cgroup) error {
|
||||||
// If the memory update is set to -1 we should also
|
// If the memory update is set to -1 and the swap is not explicitly
|
||||||
// set swap to -1, it means unlimited memory.
|
// set, we should also set swap to -1, it means unlimited memory.
|
||||||
if cgroup.Resources.Memory == -1 {
|
if cgroup.Resources.Memory == -1 && cgroup.Resources.MemorySwap == 0 {
|
||||||
// Only set swap if it's enabled in kernel
|
// Only set swap if it's enabled in kernel
|
||||||
if cgroups.PathExists(filepath.Join(path, cgroupMemorySwapLimit)) {
|
if cgroups.PathExists(filepath.Join(path, cgroupMemorySwapLimit)) {
|
||||||
cgroup.Resources.MemorySwap = -1
|
cgroup.Resources.MemorySwap = -1
|
||||||
|
|
Loading…
Reference in New Issue