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 <h.huangqiang@huawei.com>
This commit is contained in:
parent
cf883a87e7
commit
fe898e7862
|
@ -33,14 +33,18 @@ func (s *MemoryGroup) Apply(d *cgroupData) (err error) {
|
|||
path, err := d.path("memory")
|
||||
if err != nil && !cgroups.IsNotFound(err) {
|
||||
return err
|
||||
} else if path == "" {
|
||||
return nil
|
||||
}
|
||||
if memoryAssigned(d.config) {
|
||||
if path != "" {
|
||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||
if err := os.MkdirAll(path, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if d.config.KernelMemory != 0 {
|
||||
// Only enable kernel memory accouting when this cgroup
|
||||
// is created by libcontainer, otherwise we might get
|
||||
// error when people use `cgroupsPath` to join an existed
|
||||
// cgroup whose kernel memory is not initialized.
|
||||
if err := EnableKernelMemoryAccounting(path); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue