Skip to content

Commit f019233

Browse files
committed
systemd: fix setting kernel memory limit
since commit df3fa11 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 <[email protected]>
1 parent bbb17ef commit f019233

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

libcontainer/cgroups/systemd/apply_systemd.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package systemd
55
import (
66
"errors"
77
"fmt"
8+
"io/ioutil"
89
"math"
910
"os"
1011
"path/filepath"
@@ -590,6 +591,15 @@ func setKernelMemory(c *configs.Cgroup) error {
590591
if err := os.MkdirAll(path, 0755); err != nil {
591592
return err
592593
}
594+
// do not try to enable the kernel memory if we already have
595+
// tasks in the cgroup.
596+
content, err := ioutil.ReadFile(filepath.Join(path, "tasks"))
597+
if err != nil {
598+
return err
599+
}
600+
if len(content) > 0 {
601+
return nil
602+
}
593603
return fs.EnableKernelMemoryAccounting(path)
594604
}
595605

0 commit comments

Comments
 (0)