Fix cgroups swap issue when it is not supported

Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
Upstream-commit: 6016126c71272f7943458bbb8392dfd1f5877269
Component: engine
This commit is contained in:
Michael Crosby
2014-02-25 19:45:57 -08:00
parent 514380823f
commit f364b90f27

View File

@ -223,8 +223,10 @@ func (c *Cgroup) setupMemory(cgroupRoot string, pid int) (err error) {
return err
}
}
if c.MemorySwap != 0 {
if err := writeFile(dir, "memory.memsw.limit_in_bytes", strconv.FormatInt(c.MemorySwap, 10)); err != nil {
// By default, MemorySwap is set to twice the size of RAM.
// If you want to omit MemorySwap, set it to `-1'.
if c.MemorySwap != -1 {
if err := writeFile(dir, "memory.memsw.limit_in_bytes", strconv.FormatInt(c.Memory*2, 10)); err != nil {
return err
}
}