Skip to content

Commit

Permalink
Don't enable kernel mem if not set
Browse files Browse the repository at this point in the history
Don't enable the kmem limit if it is not specified in the config.

Fixes #1083

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
  • Loading branch information
crosbymichael committed Oct 7, 2016
1 parent b1eb19b commit 11222ee
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions libcontainer/cgroups/fs/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import (
"github.com/opencontainers/runc/libcontainer/configs"
)

const (
cgroupKernelMemoryLimit = "memory.kmem.limit_in_bytes"
)
const cgroupKernelMemoryLimit = "memory.kmem.limit_in_bytes"

type MemoryGroup struct {
}
Expand All @@ -38,8 +36,10 @@ func (s *MemoryGroup) Apply(d *cgroupData) (err error) {
return err
}
}
if err := EnableKernelMemoryAccounting(path); err != nil {
return err
if d.config.KernelMemory != 0 {
if err := EnableKernelMemoryAccounting(path); err != nil {
return err
}
}
}
defer func() {
Expand All @@ -62,13 +62,10 @@ func EnableKernelMemoryAccounting(path string) error {
// We have to limit the kernel memory here as it won't be accounted at all
// until a limit is set on the cgroup and limit cannot be set once the
// cgroup has children, or if there are already tasks in the cgroup.
kernelMemoryLimit := int64(1)
if err := setKernelMemory(path, kernelMemoryLimit); err != nil {
return err
}
kernelMemoryLimit = int64(-1)
if err := setKernelMemory(path, kernelMemoryLimit); err != nil {
return err
for _, i := range []int64{1, -1} {
if err := setKernelMemory(path, i); err != nil {
return err
}
}
return nil
}
Expand Down

0 comments on commit 11222ee

Please sign in to comment.