Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Commit e71db95

Browse files
authored
Merge pull request #347 from yanxuean/oomscore
Add a flag to set OOMScore
2 parents 885024f + 3887b0a commit e71db95

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

cmd/cri-containerd/options/options.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ type Config struct {
8282
StatsCollectPeriod int `toml:"stats_collect_period"`
8383
// SystemdCgroup enables systemd cgroup support.
8484
SystemdCgroup bool `toml:"systemd_cgroup"`
85+
// OOMScore adjust the cri-containerd's oom score
86+
OOMScore int `toml:"oom_score"`
8587
}
8688

8789
// CRIContainerdOptions contains cri-containerd command line and toml options.
@@ -143,6 +145,8 @@ func (c *CRIContainerdOptions) AddFlags(fs *pflag.FlagSet) {
143145
false, "Enables systemd cgroup support. By default not enabled.")
144146
fs.BoolVar(&c.PrintDefaultConfig, "default-config",
145147
false, "Print default toml config of cri-containerd and quit.")
148+
fs.IntVar(&c.OOMScore, "oom-score",
149+
-999, "Adjust the cri-containerd's oom score.")
146150
}
147151

148152
// InitFlags must be called after adding all cli options flags are defined and

pkg/server/service.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/containerd/containerd/content"
3030
"github.com/containerd/containerd/images"
3131
"github.com/containerd/containerd/plugin"
32+
"github.com/containerd/containerd/sys"
3233
"github.com/cri-o/ocicni/pkg/ocicni"
3334
"github.com/golang/glog"
3435
runcapparmor "github.com/opencontainers/runc/libcontainer/apparmor"
@@ -121,6 +122,11 @@ func NewCRIContainerdService(config options.Config) (CRIContainerdService, error
121122
return nil, fmt.Errorf("failed to load cgroup for cgroup path %v: %v", config.CgroupPath, err)
122123
}
123124
}
125+
if config.OOMScore != 0 {
126+
if err := sys.SetOOMScore(os.Getpid(), config.OOMScore); err != nil {
127+
return nil, fmt.Errorf("failed to set OOMScore to %v: %v", config.OOMScore, err)
128+
}
129+
}
124130

125131
c := &criContainerdService{
126132
config: config,

0 commit comments

Comments
 (0)