From 88104a44444cd23427745d1bc495e7327ed27b44 Mon Sep 17 00:00:00 2001 From: Raghavendra K T Date: Fri, 3 Jul 2015 18:19:45 +0530 Subject: [PATCH] Treat -1 as default value for memory swappiness. In some older kernels setting swappiness fails. This happens even when nobody tries to configure swappiness from docker UI because we would still get some default value from host config. With this we treat -1 value as default value (set implicitly) and skip the enforcement of swappiness. However from the docker UI setting an invalid value anything other than 0-100 including -1 should fail. This patch enables that fix in docker UI. without this fix container creation with invalid value succeeds with a default value (60) which in incorrect. Signed-off-by: Raghavendra K T --- libcontainer/cgroups/fs/memory.go | 4 ++++ libcontainer/cgroups/systemd/apply_systemd.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/libcontainer/cgroups/fs/memory.go b/libcontainer/cgroups/fs/memory.go index 55ab56f4..a40e39d8 100644 --- a/libcontainer/cgroups/fs/memory.go +++ b/libcontainer/cgroups/fs/memory.go @@ -75,6 +75,10 @@ func (s *MemoryGroup) Set(path string, cgroup *configs.Cgroup) error { if err := writeFile(path, "memory.swappiness", strconv.FormatInt(cgroup.MemorySwappiness, 10)); err != nil { return err } + } else if cgroup.MemorySwappiness == -1 { + return nil + } else { + return fmt.Errorf("invalid value:%d. valid memory swappiness range is 0-100", cgroup.MemorySwappiness) } return nil diff --git a/libcontainer/cgroups/systemd/apply_systemd.go b/libcontainer/cgroups/systemd/apply_systemd.go index 2c669b4b..b72242fb 100644 --- a/libcontainer/cgroups/systemd/apply_systemd.go +++ b/libcontainer/cgroups/systemd/apply_systemd.go @@ -511,6 +511,10 @@ func joinMemory(c *configs.Cgroup, pid int) error { if err != nil { return err } + } else if c.MemorySwappiness == -1 { + return nil + } else { + return fmt.Errorf("invalid value:%d. valid memory swappiness range is 0-100", c.MemorySwappiness) } return nil