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>
This commit is contained in:
Qiang Huang 2015-07-13 15:17:43 +08:00
parent b58565e9d6
commit 7e0dfbf4cd
3 changed files with 15 additions and 0 deletions

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

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

View File

@ -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