From 295c70865d10d7c57ba13cbef45c1d276ebfa83e Mon Sep 17 00:00:00 2001 From: HuKeping Date: Sat, 7 Mar 2015 02:37:56 +0800 Subject: [PATCH 1/2] cgroups: add support for oom control This patch add support for diable OOM Killer. Signed-off-by: Hu Keping --- cgroups/fs/memory.go | 6 ++++++ configs/cgroup.go | 3 +++ 2 files changed, 9 insertions(+) diff --git a/cgroups/fs/memory.go b/cgroups/fs/memory.go index a2e4f33db9c..b99f81687a6 100644 --- a/cgroups/fs/memory.go +++ b/cgroups/fs/memory.go @@ -56,6 +56,12 @@ func (s *MemoryGroup) Set(path string, cgroup *configs.Cgroup) error { } } + if cgroup.OomKillDisable { + if err := writeFile(path, "memory.oom_control", "1"); err != nil { + return err + } + } + return nil } diff --git a/configs/cgroup.go b/configs/cgroup.go index 92b9286a9ee..8bf174c195f 100644 --- a/configs/cgroup.go +++ b/configs/cgroup.go @@ -51,4 +51,7 @@ type Cgroup struct { // Parent slice to use for systemd TODO: remove in favor or parent Slice string `json:"slice"` + + // Whether to disable OOM Killer + OomKillDisable bool `json:"oom_kill_disable"` } From 4332ffcfc6765245e8e9151a2907b0e4b76f218f Mon Sep 17 00:00:00 2001 From: HuKeping Date: Sat, 7 Mar 2015 02:30:55 +0800 Subject: [PATCH 2/2] cgroups: add test for disable oom killer Signed-off-by: Hu Keping --- cgroups/fs/memory_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/cgroups/fs/memory_test.go b/cgroups/fs/memory_test.go index 70f17a70c2b..f1c7dda8d87 100644 --- a/cgroups/fs/memory_test.go +++ b/cgroups/fs/memory_test.go @@ -173,3 +173,30 @@ func TestMemoryStatsBadMaxUsageFile(t *testing.T) { t.Fatal("Expected failure") } } + +func TestMemorySetOomControl(t *testing.T) { + helper := NewCgroupTestUtil("memory", t) + defer helper.cleanup() + + const ( + oom_kill_disable = 1 // disable oom killer, default is 0 + ) + + helper.writeFileContents(map[string]string{ + "memory.oom_control": strconv.Itoa(oom_kill_disable), + }) + + memory := &MemoryGroup{} + if err := memory.Set(helper.CgroupPath, helper.CgroupData.c); err != nil { + t.Fatal(err) + } + + value, err := getCgroupParamUint(helper.CgroupPath, "memory.oom_control") + if err != nil { + t.Fatalf("Failed to parse memory.oom_control - %s", err) + } + + if value != oom_kill_disable { + t.Fatalf("Got the wrong value, set memory.oom_control failed.") + } +}