Skip to content

Commit ea63098

Browse files
committed
Add support for updating oom_score_adj
rebase
1 parent 2f93d66 commit ea63098

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

libcontainer/container_linux.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,16 @@ func (c *Container) Set(config configs.Config) error {
171171
if status == Stopped {
172172
return ErrNotRunning
173173
}
174+
175+
// Set the oom_score_adj value
176+
if config.OomScoreAdj != nil && *config.OomScoreAdj != 0 {
177+
if c.hasInit() {
178+
if err := os.WriteFile(fmt.Sprintf("/proc/%d/oom_score_adj", c.initProcess.pid()), []byte(strconv.Itoa(*config.OomScoreAdj)), unix.O_WRONLY); err != nil {
179+
return err
180+
}
181+
}
182+
}
183+
174184
if err := c.cgroupManager.Set(config.Cgroups.Resources); err != nil {
175185
// Set configs back
176186
if err2 := c.cgroupManager.Set(c.config.Cgroups.Resources); err2 != nil {

update.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ other options are ignored.
136136
Name: "mem-bw-schema",
137137
Usage: "The string of Intel RDT/MBA memory bandwidth schema",
138138
},
139+
cli.StringFlag{
140+
Name: "oom-score-adj",
141+
Usage: "oom score adj value",
142+
},
139143
},
140144
Action: func(context *cli.Context) error {
141145
if err := checkArgs(context, 1, exactArgs); err != nil {
@@ -255,6 +259,10 @@ other options are ignored.
255259
r.Pids.Limit = int64(context.Int("pids-limit"))
256260
}
257261

262+
if oomScoreAdj := context.Int("oom-score-adj"); oomScoreAdj != 0 {
263+
config.OomScoreAdj = &oomScoreAdj
264+
}
265+
258266
// Fix up values
259267
if r.Memory.Limit != nil && *r.Memory.Limit == -1 && r.Memory.Swap == nil {
260268
// To avoid error "unable to set swap limit without memory limit"

0 commit comments

Comments
 (0)