Skip to content

Commit 5a922dc

Browse files
committed
daemon: deprecate --oom-score-adjust for the daemon
The `oom-score-adjust` option was added in a894aec, to prevent the daemon from being OOM-killed before other processes. This option was mostly added as a "convenience", as running the daemon as a systemd unit was not yet common. Having the daemon set its own limits is not best-practice, and something better handled by the process-manager starting the daemon. Commit cf7a5be fixed this option to allow disabling it, and 2b8e68e removed the default score adjust. This patch deprecates the option altogether, recommending users to set these limits through the process manager used, such as the "OOMScoreAdjust" option in systemd units. With this patch: dockerd --oom-score-adjust=-500 --validate Flag --oom-score-adjust has been deprecated, and will be removed in the next release. configuration OK echo '{"oom-score-adjust":-500}' > /etc/docker/daemon.json dockerd INFO[2023-04-12T21:34:51.133389627Z] Starting up INFO[2023-04-12T21:34:51.135607544Z] containerd not running, starting managed containerd WARN[2023-04-12T21:34:51.135629086Z] DEPRECATED: The "oom-score-adjust" config parameter and the dockerd "--oom-score-adjust" option will be removed in the next release. docker info Client: Context: default Debug Mode: false ... DEPRECATED: The "oom-score-adjust" config parameter and the dockerd "--oom-score-adjust" option will be removed in the next release Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 49fa3d8 commit 5a922dc

5 files changed

Lines changed: 12 additions & 4 deletions

File tree

cmd/dockerd/config_unix.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ func installConfigFlags(conf *config.Config, flags *pflag.FlagSet) error {
4646
flags.StringVar(&conf.CgroupParent, "cgroup-parent", "", "Set parent cgroup for all containers")
4747
flags.StringVar(&conf.RemappedRoot, "userns-remap", "", "User/Group setting for user namespaces")
4848
flags.BoolVar(&conf.LiveRestoreEnabled, "live-restore", false, "Enable live restore of docker when containers are still running")
49-
flags.IntVar(&conf.OOMScoreAdjust, "oom-score-adjust", 0, "Set the oom_score_adj for the daemon")
49+
flags.IntVar(&conf.OOMScoreAdjust, "oom-score-adjust", 0, "Set the oom_score_adj for the daemon (deprecated)")
50+
_ = flags.MarkDeprecated("oom-score-adjust", "and will be removed in the next release.")
5051
flags.BoolVar(&conf.Init, "init", false, "Run an init in the container to forward signals and reap processes")
5152
flags.StringVar(&conf.InitPath, "init-path", "", "Path to the docker-init binary")
5253
flags.Int64Var(&conf.CPURealtimePeriod, "cpu-rt-period", 0, "Limit the CPU real-time period in microseconds for the parent cgroup for all containers (not supported with cgroups v2)")

cmd/dockerd/daemon_unix.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ func (cli *DaemonCli) getPlatformContainerdDaemonOpts() ([]supervisor.DaemonOpt,
6161
// TODO(thaJeztah) change this to use /proc/self/oom_score_adj instead,
6262
// which would allow us to set the correct score even if dockerd's score
6363
// was set through other means (such as systemd or "manually").
64-
supervisor.WithOOMScore(cli.Config.OOMScoreAdjust),
64+
supervisor.WithOOMScore(cli.Config.OOMScoreAdjust), //nolint:staticcheck // ignore SA1019 (WithOOMScore is deprecated); will be removed in the next release.
65+
}
66+
if cli.Config.OOMScoreAdjust != 0 {
67+
logrus.Warn(`DEPRECATED: The "oom-score-adjust" config parameter and the dockerd "--oom-score-adjust" option will be removed in the next release.`)
6568
}
66-
6769
return opts, nil
6870
}
6971

daemon/config/config_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ type Config struct {
6868
Ulimits map[string]*units.Ulimit `json:"default-ulimits,omitempty"`
6969
CPURealtimePeriod int64 `json:"cpu-rt-period,omitempty"`
7070
CPURealtimeRuntime int64 `json:"cpu-rt-runtime,omitempty"`
71-
OOMScoreAdjust int `json:"oom-score-adjust,omitempty"`
71+
OOMScoreAdjust int `json:"oom-score-adjust,omitempty"` // Deprecated: configure the daemon's oom-score-adjust using a process manager instead.
7272
Init bool `json:"init,omitempty"`
7373
InitPath string `json:"init-path,omitempty"`
7474
SeccompProfile string `json:"seccomp-profile,omitempty"`

daemon/info_unix.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ func (daemon *Daemon) fillPlatformInfo(v *types.Info, sysInfo *sysinfo.SysInfo)
164164
if !v.BridgeNfIP6tables {
165165
v.Warnings = append(v.Warnings, "WARNING: bridge-nf-call-ip6tables is disabled")
166166
}
167+
if daemon.configStore.OOMScoreAdjust != 0 {
168+
v.Warnings = append(v.Warnings, `DEPRECATED: The "oom-score-adjust" config parameter and the dockerd "--oom-score-adjust" option will be removed in the next release`)
169+
}
167170
}
168171

169172
func (daemon *Daemon) fillPlatformVersion(v *types.Version) {

libcontainerd/supervisor/remote_daemon_options_linux.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package supervisor // import "github.com/docker/docker/libcontainerd/supervisor"
22

33
// WithOOMScore defines the oom_score_adj to set for the containerd process.
4+
//
5+
// Deprecated: setting the oom-score-adjust from the daemon itself is deprecated, and should be handled by the process-manager starting the daemon instead.
46
func WithOOMScore(score int) DaemonOpt {
57
return func(r *remote) error {
68
r.oomScore = score

0 commit comments

Comments
 (0)