Set default MemorySwap on Docker side

As discussed in docker/libcontainer#616,
we should move this behavior to Docker side.

Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
Upstream-commit: 7e0dfbf4cdbb8694a90818b5cd746b92e11a78c7
Component: engine
This commit is contained in:
Qiang Huang
2015-07-13 15:17:43 +08:00
parent 4fea88f280
commit 46a92117c9
3 changed files with 15 additions and 0 deletions
+1
View File
@@ -19,6 +19,7 @@ func (daemon *Daemon) ContainerCreate(name string, config *runconfig.Config, hos
return "", nil, fmt.Errorf("Config cannot be empty in order to create a container")
}
daemon.adaptContainerSettings(hostConfig)
warnings, err := daemon.verifyContainerSettings(hostConfig, config)
if err != nil {
return "", warnings, err
+10
View File
@@ -114,6 +114,16 @@ func checkKernel() error {
return nil
}
func (daemon *Daemon) adaptContainerSettings(hostConfig *runconfig.HostConfig) {
if hostConfig == nil {
return
}
if hostConfig.Memory > 0 && hostConfig.MemorySwap == 0 {
// By default, MemorySwap is set to twice the size of Memory.
hostConfig.MemorySwap = hostConfig.Memory * 2
}
}
func (daemon *Daemon) verifyContainerSettings(hostConfig *runconfig.HostConfig, config *runconfig.Config) ([]string, error) {
var warnings []string
@@ -72,6 +72,10 @@ func checkKernel() error {
return nil
}
func (daemon *Daemon) adaptContainerSettings(hostConfig *runconfig.HostConfig) {
// TODO Windows.
}
func (daemon *Daemon) verifyContainerSettings(hostConfig *runconfig.HostConfig, config *runconfig.Config) ([]string, error) {
// TODO Windows. Verifications TBC
return nil, nil