Merge pull request #4845 from skaegi/oom_score-max
Add bounds on max oom_score_adj value for AdjustOOMScore
This commit is contained in:
commit
070b698449
@ -2043,6 +2043,10 @@ func TestShimOOMScore(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
expectedScore := containerdScore + 1
|
expectedScore := containerdScore + 1
|
||||||
|
if expectedScore > sys.OOMScoreAdjMax {
|
||||||
|
expectedScore = sys.OOMScoreAdjMax
|
||||||
|
}
|
||||||
|
|
||||||
// find the shim's pid
|
// find the shim's pid
|
||||||
if cgroups.Mode() == cgroups.Unified {
|
if cgroups.Mode() == cgroups.Unified {
|
||||||
processes, err := cg2.Procs(false)
|
processes, err := cg2.Procs(false)
|
||||||
|
@ -174,6 +174,7 @@ func eaddrinuse(err error) bool {
|
|||||||
|
|
||||||
// setupOOMScore gets containerd's oom score and adds +1 to it
|
// setupOOMScore gets containerd's oom score and adds +1 to it
|
||||||
// to ensure a shim has a lower* score than the daemons
|
// to ensure a shim has a lower* score than the daemons
|
||||||
|
// if not already at the maximum OOM Score
|
||||||
func setupOOMScore(shimPid int) error {
|
func setupOOMScore(shimPid int) error {
|
||||||
pid := os.Getpid()
|
pid := os.Getpid()
|
||||||
score, err := sys.GetOOMScoreAdj(pid)
|
score, err := sys.GetOOMScoreAdj(pid)
|
||||||
@ -181,6 +182,9 @@ func setupOOMScore(shimPid int) error {
|
|||||||
return errors.Wrap(err, "get daemon OOM score")
|
return errors.Wrap(err, "get daemon OOM score")
|
||||||
}
|
}
|
||||||
shimScore := score + 1
|
shimScore := score + 1
|
||||||
|
if shimScore > sys.OOMScoreAdjMax {
|
||||||
|
shimScore = sys.OOMScoreAdjMax
|
||||||
|
}
|
||||||
if err := sys.SetOOMScore(shimPid, shimScore); err != nil {
|
if err := sys.SetOOMScore(shimPid, shimScore); err != nil {
|
||||||
return errors.Wrap(err, "set shim OOM score")
|
return errors.Wrap(err, "set shim OOM score")
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,7 @@ func SetScore(pid int) error {
|
|||||||
|
|
||||||
// AdjustOOMScore sets the OOM score for the process to the parents OOM score +1
|
// AdjustOOMScore sets the OOM score for the process to the parents OOM score +1
|
||||||
// to ensure that they parent has a lower* score than the shim
|
// to ensure that they parent has a lower* score than the shim
|
||||||
|
// if not already at the maximum OOM Score
|
||||||
func AdjustOOMScore(pid int) error {
|
func AdjustOOMScore(pid int) error {
|
||||||
parent := os.Getppid()
|
parent := os.Getppid()
|
||||||
score, err := sys.GetOOMScoreAdj(parent)
|
score, err := sys.GetOOMScoreAdj(parent)
|
||||||
@ -60,6 +61,9 @@ func AdjustOOMScore(pid int) error {
|
|||||||
return errors.Wrap(err, "get parent OOM score")
|
return errors.Wrap(err, "get parent OOM score")
|
||||||
}
|
}
|
||||||
shimScore := score + 1
|
shimScore := score + 1
|
||||||
|
if shimScore > sys.OOMScoreAdjMax {
|
||||||
|
shimScore = sys.OOMScoreAdjMax
|
||||||
|
}
|
||||||
if err := sys.SetOOMScore(pid, shimScore); err != nil {
|
if err := sys.SetOOMScore(pid, shimScore); err != nil {
|
||||||
return errors.Wrap(err, "set shim OOM score")
|
return errors.Wrap(err, "set shim OOM score")
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,12 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// OOMScoreMaxKillable is the maximum score keeping the process killable by the oom killer
|
const (
|
||||||
const OOMScoreMaxKillable = -999
|
// OOMScoreMaxKillable is the maximum score keeping the process killable by the oom killer
|
||||||
|
OOMScoreMaxKillable = -999
|
||||||
|
// OOMScoreAdjMax is from OOM_SCORE_ADJ_MAX https://github.com/torvalds/linux/blob/master/include/uapi/linux/oom.h
|
||||||
|
OOMScoreAdjMax = 1000
|
||||||
|
)
|
||||||
|
|
||||||
// SetOOMScore sets the oom score for the provided pid
|
// SetOOMScore sets the oom score for the provided pid
|
||||||
func SetOOMScore(pid, score int) error {
|
func SetOOMScore(pid, score int) error {
|
||||||
|
@ -16,6 +16,11 @@
|
|||||||
|
|
||||||
package sys
|
package sys
|
||||||
|
|
||||||
|
const (
|
||||||
|
// OOMScoreAdjMax is not implemented on Windows
|
||||||
|
OOMScoreAdjMax = 0
|
||||||
|
)
|
||||||
|
|
||||||
// SetOOMScore sets the oom score for the process
|
// SetOOMScore sets the oom score for the process
|
||||||
//
|
//
|
||||||
// Not implemented on Windows
|
// Not implemented on Windows
|
||||||
|
Loading…
Reference in New Issue
Block a user