瀏覽代碼

Merge pull request #13834 from hqhq/hq_memswap_change

Set default MemorySwap on Docker side
Jessie Frazelle 10 年之前
父節點
當前提交
6e1d887722
共有 3 個文件被更改,包括 15 次插入0 次删除
  1. 1 0
      daemon/create.go
  2. 10 0
      daemon/daemon_unix.go
  3. 4 0
      daemon/daemon_windows.go

+ 1 - 0
daemon/create.go

@@ -20,6 +20,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 - 0
daemon/daemon_unix.go

@@ -117,6 +117,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
 

+ 4 - 0
daemon/daemon_windows.go

@@ -73,6 +73,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