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:
Vishnu Kannan
2014-12-24 00:03:26 +00:00
parent 8824e46340
commit 6f53f33fda
3 changed files with 25 additions and 0 deletions

View File

@@ -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
}