Add bounds on max oom_score_adj value for AdjustOOMScore
oom_score_adj must be in the range -1000 to 1000. In AdjustOOMScore if containerd's score is already at the maximum value we should set that value for the shim instead of trying to set 1001 which is invalid. Signed-off-by: Simon Kaegi <simon_kaegi@ca.ibm.com>
This commit is contained in:
@@ -53,6 +53,7 @@ func SetScore(pid int) error {
|
||||
|
||||
// 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
|
||||
// if not already at the maximum OOM Score
|
||||
func AdjustOOMScore(pid int) error {
|
||||
parent := os.Getppid()
|
||||
score, err := sys.GetOOMScoreAdj(parent)
|
||||
@@ -60,6 +61,9 @@ 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 {
|
||||
return errors.Wrap(err, "set shim OOM score")
|
||||
}
|
||||
|
Reference in New Issue
Block a user