1. It's a cgroup api, fit the general defination that we take
cgroup options as kind of resource options.
2. It's common usage and very helpful as explained here:
https://github.com/docker/docker/pull/18270#issuecomment-160561316
3. It's already in `Resource` struct in
daemon/execdriver/driver_unix.go
Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
| ... | ... |
@@ -265,6 +265,10 @@ func verifyContainerResources(resources *runconfig.Resources) ([]string, error) |
| 265 | 265 |
warnings = append(warnings, "You specified a kernel memory limit on a kernel older than 4.0. Kernel memory limits are experimental on older kernels, it won't work as expected and can cause your system to be unstable.") |
| 266 | 266 |
logrus.Warnf("You specified a kernel memory limit on a kernel older than 4.0. Kernel memory limits are experimental on older kernels, it won't work as expected and can cause your system to be unstable.")
|
| 267 | 267 |
} |
| 268 |
+ if resources.OomKillDisable && !sysInfo.OomKillDisable {
|
|
| 269 |
+ resources.OomKillDisable = false |
|
| 270 |
+ return warnings, fmt.Errorf("Your kernel does not support oom kill disable.")
|
|
| 271 |
+ } |
|
| 268 | 272 |
|
| 269 | 273 |
// cpu subsystem checks and adjustments |
| 270 | 274 |
if resources.CPUShares > 0 && !sysInfo.CPUShares {
|
| ... | ... |
@@ -364,10 +368,6 @@ func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *runconfig.HostC |
| 364 | 364 |
return warnings, fmt.Errorf("SHM size must be greater then 0")
|
| 365 | 365 |
} |
| 366 | 366 |
|
| 367 |
- if hostConfig.OomKillDisable && !sysInfo.OomKillDisable {
|
|
| 368 |
- hostConfig.OomKillDisable = false |
|
| 369 |
- return warnings, fmt.Errorf("Your kernel does not support oom kill disable.")
|
|
| 370 |
- } |
|
| 371 | 367 |
if hostConfig.OomScoreAdj < -1000 || hostConfig.OomScoreAdj > 1000 {
|
| 372 | 368 |
return warnings, fmt.Errorf("Invalid value %d, range for oom score adj is [-1000, 1000].", hostConfig.OomScoreAdj)
|
| 373 | 369 |
} |
| ... | ... |
@@ -188,6 +188,7 @@ type Resources struct {
|
| 188 | 188 |
MemoryReservation int64 // Memory soft limit (in bytes) |
| 189 | 189 |
MemorySwap int64 // Total memory usage (memory + swap); set `-1` to disable swap |
| 190 | 190 |
MemorySwappiness *int64 // Tuning container memory swappiness behaviour |
| 191 |
+ OomKillDisable bool // Whether to disable OOM Killer or not |
|
| 191 | 192 |
Ulimits []*ulimit.Ulimit // List of ulimits to be set in the container |
| 192 | 193 |
} |
| 193 | 194 |
|
| ... | ... |
@@ -216,7 +217,6 @@ type HostConfig struct {
|
| 216 | 216 |
IpcMode IpcMode // IPC namespace to use for the container |
| 217 | 217 |
Links []string // List of links (in the name:alias form) |
| 218 | 218 |
OomScoreAdj int // Container preference for OOM-killing |
| 219 |
- OomKillDisable bool // Whether to disable OOM Killer or not |
|
| 220 | 219 |
PidMode PidMode // PID namespace to use for the container |
| 221 | 220 |
Privileged bool // Is the container in privileged mode |
| 222 | 221 |
PublishAllPorts bool // Should docker publish all exposed port for the container |
| ... | ... |
@@ -353,6 +353,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSe |
| 353 | 353 |
MemorySwap: memorySwap, |
| 354 | 354 |
MemorySwappiness: flSwappiness, |
| 355 | 355 |
KernelMemory: KernelMemory, |
| 356 |
+ OomKillDisable: *flOomKillDisable, |
|
| 356 | 357 |
CPUShares: *flCPUShares, |
| 357 | 358 |
CPUPeriod: *flCPUPeriod, |
| 358 | 359 |
CpusetCpus: *flCpusetCpus, |
| ... | ... |
@@ -397,7 +398,6 @@ func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSe |
| 397 | 397 |
Binds: binds, |
| 398 | 398 |
ContainerIDFile: *flContainerIDFile, |
| 399 | 399 |
OomScoreAdj: *flOomScoreAdj, |
| 400 |
- OomKillDisable: *flOomKillDisable, |
|
| 401 | 400 |
Privileged: *flPrivileged, |
| 402 | 401 |
PortBindings: portBindings, |
| 403 | 402 |
Links: flLinks.GetAll(), |