MCPcopy Index your code
hub / github.com/containerd/containerd / SetOOMScore

Function SetOOMScore

pkg/sys/oom_linux.go:48–65  ·  view source on GitHub ↗

SetOOMScore sets the oom score for the provided pid

(pid, score int)

Source from the content-addressed store, hash-verified

46
47// SetOOMScore sets the oom score for the provided pid
48func SetOOMScore(pid, score int) error {
49 if score > OOMScoreAdjMax || score < OOMScoreAdjMin {
50 return fmt.Errorf("value out of range (%d): OOM score must be between %d and %d", score, OOMScoreAdjMin, OOMScoreAdjMax)
51 }
52 path := fmt.Sprintf("/proc/%d/oom_score_adj", pid)
53 f, err := os.OpenFile(path, os.O_WRONLY, 0)
54 if err != nil {
55 return err
56 }
57 defer f.Close()
58 if _, err = f.WriteString(strconv.Itoa(score)); err != nil {
59 if os.IsPermission(err) && (!runningPrivileged() || userns.RunningInUserNS()) {
60 return nil
61 }
62 return err
63 }
64 return nil
65}
66
67// GetOOMScoreAdj gets the oom score for a process. It returns 0 (zero) if either
68// no oom score is set, or a sore is set to 0.

Callers 3

adjustOomFunction · 0.70
AdjustOOMScoreFunction · 0.70

Calls 2

runningPrivilegedFunction · 0.85
CloseMethod · 0.65

Tested by 2

adjustOomFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…