mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Allow ApplyOomScoreAdj to specify what PID to adjust for.
This commit is contained in:
parent
5eb71a1877
commit
2d1a8d0da0
@ -170,7 +170,7 @@ func (s *KubeletServer) Run(_ []string) error {
|
|||||||
s.EtcdServerList = util.StringList{}
|
s.EtcdServerList = util.StringList{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := util.ApplyOomScoreAdj(s.OOMScoreAdj); err != nil {
|
if err := util.ApplyOomScoreAdj(0, s.OOMScoreAdj); err != nil {
|
||||||
glog.Info(err)
|
glog.Info(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ func (s *ProxyServer) AddFlags(fs *pflag.FlagSet) {
|
|||||||
|
|
||||||
// Run runs the specified ProxyServer. This should never exit.
|
// Run runs the specified ProxyServer. This should never exit.
|
||||||
func (s *ProxyServer) Run(_ []string) error {
|
func (s *ProxyServer) Run(_ []string) error {
|
||||||
if err := util.ApplyOomScoreAdj(s.OOMScoreAdj); err != nil {
|
if err := util.ApplyOomScoreAdj(0, s.OOMScoreAdj); err != nil {
|
||||||
glog.Info(err)
|
glog.Info(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,14 +175,24 @@ func CompileRegexps(regexpStrings []string) ([]*regexp.Regexp, error) {
|
|||||||
return regexps, nil
|
return regexps, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Writes 'value' to /proc/self/oom_score_adj.
|
// Writes 'value' to /proc/<pid>/oom_score_adj. PID = 0 means self
|
||||||
func ApplyOomScoreAdj(value int) error {
|
func ApplyOomScoreAdj(pid int, value int) error {
|
||||||
if value < -1000 || value > 1000 {
|
if value < -1000 || value > 1000 {
|
||||||
return fmt.Errorf("invalid value(%d) specified for oom_score_adj. Values must be within the range [-1000, 1000]", value)
|
return fmt.Errorf("invalid value(%d) specified for oom_score_adj. Values must be within the range [-1000, 1000]", value)
|
||||||
}
|
}
|
||||||
|
if pid < 0 {
|
||||||
|
return fmt.Errorf("invalid PID %d specified for oom_score_adj", pid)
|
||||||
|
}
|
||||||
|
|
||||||
if err := ioutil.WriteFile("/proc/self/oom_score_adj", []byte(strconv.Itoa(value)), 0700); err != nil {
|
var pidStr string
|
||||||
fmt.Errorf("failed to set oom_score_adj to %d - %q", value, err)
|
if pid == 0 {
|
||||||
|
pidStr = "self"
|
||||||
|
} else {
|
||||||
|
pidStr = strconv.Itoa(pid)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := ioutil.WriteFile(path.Join("/proc", pidStr, "oom_score_adj"), []byte(strconv.Itoa(value)), 0700); err != nil {
|
||||||
|
fmt.Errorf("failed to set oom_score_adj to %d: %v", value, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user