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 <raghavendra.kt@linux.vnet.ibm.com>
This commit is contained in:
Raghavendra K T 2015-07-03 18:19:45 +05:30
parent 00f6b56903
commit 88104a4444
2 changed files with 8 additions and 0 deletions

View File

@ -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

View File

@ -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