diff --git a/runtime/v1/shim/client/client.go b/runtime/v1/shim/client/client.go index 9211c0052..a8afb0e48 100644 --- a/runtime/v1/shim/client/client.go +++ b/runtime/v1/shim/client/client.go @@ -182,10 +182,7 @@ func setupOOMScore(shimPid int) error { return errors.Wrap(err, "get daemon OOM score") } shimScore := score + 1 - if shimScore > sys.OOMScoreAdjMax { - shimScore = sys.OOMScoreAdjMax - } - if err := sys.SetOOMScore(shimPid, shimScore); err != nil { + if err := sys.AdjustOOMScore(shimPid, shimScore); err != nil { return errors.Wrap(err, "set shim OOM score") } return nil diff --git a/runtime/v2/shim/util_unix.go b/runtime/v2/shim/util_unix.go index f4c7cfa55..9c505707e 100644 --- a/runtime/v2/shim/util_unix.go +++ b/runtime/v2/shim/util_unix.go @@ -61,10 +61,7 @@ func AdjustOOMScore(pid int) error { return errors.Wrap(err, "get parent OOM score") } shimScore := score + 1 - if shimScore > sys.OOMScoreAdjMax { - shimScore = sys.OOMScoreAdjMax - } - if err := sys.SetOOMScore(pid, shimScore); err != nil { + if err := sys.AdjustOOMScore(pid, shimScore); err != nil { return errors.Wrap(err, "set shim OOM score") } return nil diff --git a/sys/oom_linux.go b/sys/oom_linux.go index 9f9586580..8e1e3f2f9 100644 --- a/sys/oom_linux.go +++ b/sys/oom_linux.go @@ -36,6 +36,17 @@ const ( OOMScoreAdjMax = 1000 ) +// AdjustOOMScore sets the oom score for the provided pid. If the provided score +// is out of range (-1000 - 1000), it is clipped to the min/max value. +func AdjustOOMScore(pid, score int) error { + if score > OOMScoreAdjMax { + score = OOMScoreAdjMax + } else if score < OOMScoreAdjMin { + score = OOMScoreAdjMin + } + return SetOOMScore(pid, score) +} + // SetOOMScore sets the oom score for the provided pid func SetOOMScore(pid, score int) error { if score > OOMScoreAdjMax || score < OOMScoreAdjMin { diff --git a/sys/oom_unsupported.go b/sys/oom_unsupported.go index 558340790..f5d7e9786 100644 --- a/sys/oom_unsupported.go +++ b/sys/oom_unsupported.go @@ -25,6 +25,14 @@ const ( OOMScoreAdjMax = 0 ) +// AdjustOOMScore sets the oom score for the provided pid. If the provided score +// is out of range (-1000 - 1000), it is clipped to the min/max value. +// +// Not implemented on Windows +func AdjustOOMScore(pid, score int) error { + return nil +} + // SetOOMScore sets the oom score for the process // // Not implemented on Windows