Set oom_score_adj for kubelet and kube-proxy to a low value to help them survive system memory pressure.
This commit is contained in:
@@ -19,8 +19,10 @@ package util
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
@@ -134,3 +136,16 @@ func CompileRegexps(regexpStrings []string) ([]*regexp.Regexp, error) {
|
||||
}
|
||||
return regexps, nil
|
||||
}
|
||||
|
||||
// Writes 'value' to /proc/self/oom_score_adj.
|
||||
func ApplyOomScoreAdj(value int) error {
|
||||
if value < -1000 || value > 1000 {
|
||||
return fmt.Errorf("invalid value(%d) specified for oom_score_adj. Values must be within the range [-1000, 1000]")
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile("/proc/self/oom_score_adj", []byte(strconv.Itoa(value)), 0700); err != nil {
|
||||
fmt.Errorf("failed to set oom_score_adj to %s - %q", value, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user