Skip to content

Commit

Permalink
Change OomKillDisable to be pointer
Browse files Browse the repository at this point in the history
It's like `MemorySwappiness`, the default value has specific
meaning (default false means enable oom kill).

We need to change it to pointer so we can update it after
container is created.

Signed-off-by: Qiang Huang <[email protected]>
(cherry picked from commit 9c2ea42)

Conflicts:
	vendor/src/github.com/docker/engine-api/types/container/host_config.go
  • Loading branch information
hqhq authored and calavera committed Jan 12, 2016
1 parent 0627bf1 commit f4a6873
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion api/client/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (cli *DockerCli) CmdRun(args ...string) error {
os.Exit(125)
}

if hostConfig.OomKillDisable && hostConfig.Memory == 0 {
if hostConfig.OomKillDisable != nil && *hostConfig.OomKillDisable && hostConfig.Memory == 0 {
fmt.Fprintf(cli.err, "WARNING: Dangerous only disable the OOM Killer on containers but not set the '-m/--memory' option\n")
}

Expand Down
2 changes: 1 addition & 1 deletion daemon/container_operations_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (daemon *Daemon) populateCommand(c *container.Container, env []string) erro
BlkioThrottleWriteBpsDevice: writeBpsDevice,
BlkioThrottleReadIOpsDevice: readIOpsDevice,
BlkioThrottleWriteIOpsDevice: writeIOpsDevice,
OomKillDisable: c.HostConfig.OomKillDisable,
OomKillDisable: *c.HostConfig.OomKillDisable,
MemorySwappiness: -1,
}

Expand Down
8 changes: 6 additions & 2 deletions daemon/daemon_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ func (daemon *Daemon) adaptContainerSettings(hostConfig *containertypes.HostConf
defaultSwappiness := int64(-1)
hostConfig.MemorySwappiness = &defaultSwappiness
}
if hostConfig.OomKillDisable == nil {
defaultOomKillDisable := false
hostConfig.OomKillDisable = &defaultOomKillDisable
}

return nil
}
Expand Down Expand Up @@ -270,8 +274,8 @@ func verifyContainerResources(resources *containertypes.Resources) ([]string, er
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.")
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.")
}
if resources.OomKillDisable && !sysInfo.OomKillDisable {
resources.OomKillDisable = false
if resources.OomKillDisable != nil && !sysInfo.OomKillDisable {
resources.OomKillDisable = nil
return warnings, fmt.Errorf("Your kernel does not support oom kill disable.")
}

Expand Down
2 changes: 1 addition & 1 deletion runconfig/opts/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*container.Config, *container.Host
MemorySwap: memorySwap,
MemorySwappiness: flSwappiness,
KernelMemory: KernelMemory,
OomKillDisable: *flOomKillDisable,
OomKillDisable: flOomKillDisable,
CPUShares: *flCPUShares,
CPUPeriod: *flCPUPeriod,
CpusetCpus: *flCpusetCpus,
Expand Down

0 comments on commit f4a6873

Please sign in to comment.