diff --git a/sys/oom_linux.go b/sys/oom_linux.go index 6e759a0b1..82a347c6f 100644 --- a/sys/oom_linux.go +++ b/sys/oom_linux.go @@ -65,7 +65,8 @@ func SetOOMScore(pid, score int) error { return nil } -// GetOOMScoreAdj gets the oom score for a process +// GetOOMScoreAdj gets the oom score for a process. It returns 0 (zero) if either +// no oom score is set, or a sore is set to 0. func GetOOMScoreAdj(pid int) (int, error) { path := fmt.Sprintf("/proc/%d/oom_score_adj", pid) data, err := ioutil.ReadFile(path) diff --git a/sys/oom_linux_test.go b/sys/oom_linux_test.go index bcbb1bc04..3cea56a75 100644 --- a/sys/oom_linux_test.go +++ b/sys/oom_linux_test.go @@ -71,9 +71,11 @@ func TestSetOOMScoreBoundaries(t *testing.T) { score, err := GetOOMScoreAdj(os.Getpid()) assert.NilError(t, err) - if score == 0 || score == OOMScoreAdjMin { - // we won't be able to set the score lower than the parent process, - // so only test if parent process does not have a oom-score-adj + if score == OOMScoreAdjMin { + // We won't be able to set the score lower than the parent process. This + // could also be tested if the parent process does not have a oom-score-adj + // set, but GetOOMScoreAdj does not distinguish between "not set" and + // "score is set, but zero". _, adjustment, err = adjustOom(OOMScoreAdjMin) assert.NilError(t, err) assert.Check(t, is.Equal(adjustment, OOMScoreAdjMin))