From fb5a56fb973e90743b50da1774fa8630298693ed Mon Sep 17 00:00:00 2001 From: Qiang Huang Date: Tue, 29 Sep 2015 10:02:12 +0800 Subject: [PATCH] Add memory reservation support for systemd Seems it's missed in the first place. Signed-off-by: Qiang Huang --- libcontainer/cgroups/systemd/apply_systemd.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libcontainer/cgroups/systemd/apply_systemd.go b/libcontainer/cgroups/systemd/apply_systemd.go index 7b523da9b..40a745e93 100644 --- a/libcontainer/cgroups/systemd/apply_systemd.go +++ b/libcontainer/cgroups/systemd/apply_systemd.go @@ -176,7 +176,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, @@ -212,6 +211,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 } @@ -505,6 +505,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