Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Commit

Permalink
Merge pull request #417 from HuKeping/master
Browse files Browse the repository at this point in the history
cgroups: add support for oom control
  • Loading branch information
vmarmol committed Mar 6, 2015
2 parents 334b196 + 4332ffc commit dd3cb88
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cgroups/fs/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
27 changes: 27 additions & 0 deletions cgroups/fs/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
}
3 changes: 3 additions & 0 deletions configs/cgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

0 comments on commit dd3cb88

Please sign in to comment.