systemd: fix setting kernel memory limit
since commit df3fa115f9
it is not
possible to set a kernel memory limit when using the systemd cgroups
backend as we use cgroup.Apply twice.
Skip enabling kernel memory if there are already tasks in the cgroup.
Without this patch, runc fails with:
container_linux.go:344: starting container process caused
"process_linux.go:311: applying cgroup configuration for process
caused \"failed to set memory.kmem.limit_in_bytes, because either
tasks have already joined this cgroup or it has children\""
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
parent
bbb17efcb4
commit
f01923376d
|
@ -5,6 +5,7 @@ package systemd
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -590,6 +591,15 @@ func setKernelMemory(c *configs.Cgroup) error {
|
||||||
if err := os.MkdirAll(path, 0755); err != nil {
|
if err := os.MkdirAll(path, 0755); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// do not try to enable the kernel memory if we already have
|
||||||
|
// tasks in the cgroup.
|
||||||
|
content, err := ioutil.ReadFile(filepath.Join(path, "tasks"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if len(content) > 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fs.EnableKernelMemoryAccounting(path)
|
return fs.EnableKernelMemoryAccounting(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue