Skip to content

Commit fe898e7

Browse files
committed
Fix kmem accouting when use with cgroupsPath
Fixes: #1347 Fixes: #1083 The root cause of #1083 is because we're joining an existed cgroup whose kmem accouting is not initialized, and it has child cgroup or tasks in it. Fix it by checking if the cgroup is first time created, and we should enable kmem accouting if the cgroup is craeted by libcontainer with or without kmem limit configed. Otherwise we'll get issue like #1347 Signed-off-by: Qiang Huang <[email protected]>
1 parent cf883a8 commit fe898e7

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

libcontainer/cgroups/fs/memory.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,18 @@ func (s *MemoryGroup) Apply(d *cgroupData) (err error) {
3333
path, err := d.path("memory")
3434
if err != nil && !cgroups.IsNotFound(err) {
3535
return err
36+
} else if path == "" {
37+
return nil
3638
}
3739
if memoryAssigned(d.config) {
38-
if path != "" {
40+
if _, err := os.Stat(path); os.IsNotExist(err) {
3941
if err := os.MkdirAll(path, 0755); err != nil {
4042
return err
4143
}
42-
}
43-
if d.config.KernelMemory != 0 {
44+
// Only enable kernel memory accouting when this cgroup
45+
// is created by libcontainer, otherwise we might get
46+
// error when people use `cgroupsPath` to join an existed
47+
// cgroup whose kernel memory is not initialized.
4448
if err := EnableKernelMemoryAccounting(path); err != nil {
4549
return err
4650
}

0 commit comments

Comments
 (0)