You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: sys/oom_linux.go
+25-4Lines changed: 25 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -24,25 +24,40 @@ import (
24
24
"strings"
25
25
26
26
"github.com/containerd/containerd/pkg/userns"
27
+
"golang.org/x/sys/unix"
27
28
)
28
29
29
30
const (
30
-
// OOMScoreMaxKillable is the maximum score keeping the process killable by the oom killer
31
-
OOMScoreMaxKillable=-999
32
-
// OOMScoreAdjMax is from OOM_SCORE_ADJ_MAX https://github.com/torvalds/linux/blob/master/include/uapi/linux/oom.h
31
+
// OOMScoreAdjMin is from OOM_SCORE_ADJ_MIN https://github.com/torvalds/linux/blob/v5.10/include/uapi/linux/oom.h#L9
32
+
OOMScoreAdjMin=-1000
33
+
// OOMScoreAdjMax is from OOM_SCORE_ADJ_MAX https://github.com/torvalds/linux/blob/v5.10/include/uapi/linux/oom.h#L10
33
34
OOMScoreAdjMax=1000
34
35
)
35
36
37
+
// AdjustOOMScore sets the oom score for the provided pid. If the provided score
38
+
// is out of range (-1000 - 1000), it is clipped to the min/max value.
39
+
funcAdjustOOMScore(pid, scoreint) error {
40
+
ifscore>OOMScoreAdjMax {
41
+
score=OOMScoreAdjMax
42
+
} elseifscore<OOMScoreAdjMin {
43
+
score=OOMScoreAdjMin
44
+
}
45
+
returnSetOOMScore(pid, score)
46
+
}
47
+
36
48
// SetOOMScore sets the oom score for the provided pid
37
49
funcSetOOMScore(pid, scoreint) error {
50
+
ifscore>OOMScoreAdjMax||score<OOMScoreAdjMin {
51
+
returnfmt.Errorf("value out of range (%d): OOM score must be between %d and %d", score, OOMScoreAdjMin, OOMScoreAdjMax)
0 commit comments