File tree Expand file tree Collapse file tree 1 file changed +9
-12
lines changed Expand file tree Collapse file tree 1 file changed +9
-12
lines changed Original file line number Diff line number Diff line change @@ -16,9 +16,7 @@ import (
1616 "github.com/opencontainers/runc/libcontainer/configs"
1717)
1818
19- const (
20- cgroupKernelMemoryLimit = "memory.kmem.limit_in_bytes"
21- )
19+ const cgroupKernelMemoryLimit = "memory.kmem.limit_in_bytes"
2220
2321type MemoryGroup struct {
2422}
@@ -38,8 +36,10 @@ func (s *MemoryGroup) Apply(d *cgroupData) (err error) {
3836 return err
3937 }
4038 }
41- if err := EnableKernelMemoryAccounting (path ); err != nil {
42- return err
39+ if d .config .KernelMemory != 0 {
40+ if err := EnableKernelMemoryAccounting (path ); err != nil {
41+ return err
42+ }
4343 }
4444 }
4545 defer func () {
@@ -62,13 +62,10 @@ func EnableKernelMemoryAccounting(path string) error {
6262 // We have to limit the kernel memory here as it won't be accounted at all
6363 // until a limit is set on the cgroup and limit cannot be set once the
6464 // cgroup has children, or if there are already tasks in the cgroup.
65- kernelMemoryLimit := int64 (1 )
66- if err := setKernelMemory (path , kernelMemoryLimit ); err != nil {
67- return err
68- }
69- kernelMemoryLimit = int64 (- 1 )
70- if err := setKernelMemory (path , kernelMemoryLimit ); err != nil {
71- return err
65+ for _ , i := range []int64 {1 , - 1 } {
66+ if err := setKernelMemory (path , i ); err != nil {
67+ return err
68+ }
7269 }
7370 return nil
7471}
You can’t perform that action at this time.
0 commit comments