diff --git a/libcontainer/cgroups/systemd/apply_systemd.go b/libcontainer/cgroups/systemd/apply_systemd.go index 0452a8ef..f7f7ca2b 100644 --- a/libcontainer/cgroups/systemd/apply_systemd.go +++ b/libcontainer/cgroups/systemd/apply_systemd.go @@ -177,7 +177,6 @@ func (m *Manager) Apply(pid int) error { properties = append(properties, newProp("MemoryLimit", uint64(c.Memory))) } - // TODO: MemoryReservation and MemorySwap not available in systemd if c.CpuShares != 0 { properties = append(properties, @@ -213,6 +212,7 @@ func (m *Manager) Apply(pid int) error { return err } + // TODO: MemoryReservation and MemorySwap not available in systemd if err := joinMemory(c, pid); err != nil { return err } @@ -510,6 +510,12 @@ func joinMemory(c *configs.Cgroup, pid int) error { return err } } + if c.MemoryReservation > 0 { + err = writeFile(path, "memory.soft_limit_in_bytes", strconv.FormatInt(c.MemoryReservation, 10)) + if err != nil { + return err + } + } if c.OomKillDisable { if err := writeFile(path, "memory.oom_control", "1"); err != nil { return err