Merge pull request #347 from yanxuean/oomscore

Add a flag to set OOMScore
This commit is contained in:
Lantao Liu 2017-10-12 10:27:01 -07:00 committed by GitHub
commit e71db95d0e
2 changed files with 10 additions and 0 deletions

View File

@ -82,6 +82,8 @@ type Config struct {
StatsCollectPeriod int `toml:"stats_collect_period"`
// SystemdCgroup enables systemd cgroup support.
SystemdCgroup bool `toml:"systemd_cgroup"`
// OOMScore adjust the cri-containerd's oom score
OOMScore int `toml:"oom_score"`
}
// CRIContainerdOptions contains cri-containerd command line and toml options.
@ -143,6 +145,8 @@ func (c *CRIContainerdOptions) AddFlags(fs *pflag.FlagSet) {
false, "Enables systemd cgroup support. By default not enabled.")
fs.BoolVar(&c.PrintDefaultConfig, "default-config",
false, "Print default toml config of cri-containerd and quit.")
fs.IntVar(&c.OOMScore, "oom-score",
-999, "Adjust the cri-containerd's oom score.")
}
// InitFlags must be called after adding all cli options flags are defined and

View File

@ -29,6 +29,7 @@ import (
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/plugin"
"github.com/containerd/containerd/sys"
"github.com/cri-o/ocicni/pkg/ocicni"
"github.com/golang/glog"
runcapparmor "github.com/opencontainers/runc/libcontainer/apparmor"
@ -121,6 +122,11 @@ func NewCRIContainerdService(config options.Config) (CRIContainerdService, error
return nil, fmt.Errorf("failed to load cgroup for cgroup path %v: %v", config.CgroupPath, err)
}
}
if config.OOMScore != 0 {
if err := sys.SetOOMScore(os.Getpid(), config.OOMScore); err != nil {
return nil, fmt.Errorf("failed to set OOMScore to %v: %v", config.OOMScore, err)
}
}
c := &criContainerdService{
config: config,