sys: add AdjustOOMScore() utility
Handle the limits in this function so that consumers don't have to perform the boundary checks. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
44240116aa
commit
91e7d21ee8
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user