mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Set default MemorySwappiness when adapt
It makes the inspect result consistent between cli and REST api when MemorySwappiness is not set. Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
This commit is contained in:
parent
1415f55cc0
commit
4089b4e440
5 changed files with 14 additions and 9 deletions
|
@ -296,11 +296,7 @@ func (daemon *Daemon) populateCommand(c *Container, env []string) error {
|
|||
Rlimits: rlimits,
|
||||
BlkioWeightDevice: weightDevices,
|
||||
OomKillDisable: c.hostConfig.OomKillDisable,
|
||||
MemorySwappiness: -1,
|
||||
}
|
||||
|
||||
if c.hostConfig.MemorySwappiness != nil {
|
||||
resources.MemorySwappiness = *c.hostConfig.MemorySwappiness
|
||||
MemorySwappiness: *c.hostConfig.MemorySwappiness,
|
||||
}
|
||||
|
||||
processConfig := execdriver.ProcessConfig{
|
||||
|
|
|
@ -138,6 +138,10 @@ func (daemon *Daemon) adaptContainerSettings(hostConfig *runconfig.HostConfig, a
|
|||
return err
|
||||
}
|
||||
}
|
||||
if hostConfig.MemorySwappiness == nil {
|
||||
defaultSwappiness := int64(-1)
|
||||
hostConfig.MemorySwappiness = &defaultSwappiness
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -48,9 +48,9 @@ func checkKernel() error {
|
|||
|
||||
// adaptContainerSettings is called during container creation to modify any
|
||||
// settings necessary in the HostConfig structure.
|
||||
func (daemon *Daemon) adaptContainerSettings(hostConfig *runconfig.HostConfig, adjustCPUShares bool) {
|
||||
func (daemon *Daemon) adaptContainerSettings(hostConfig *runconfig.HostConfig, adjustCPUShares bool) error {
|
||||
if hostConfig == nil {
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
if hostConfig.CPUShares < 0 {
|
||||
|
@ -60,6 +60,8 @@ func (daemon *Daemon) adaptContainerSettings(hostConfig *runconfig.HostConfig, a
|
|||
logrus.Warnf("Changing requested CPUShares of %d to maximum allowed of %d", hostConfig.CPUShares, windowsMaxCPUShares)
|
||||
hostConfig.CPUShares = windowsMaxCPUShares
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// verifyPlatformContainerSettings performs platform-specific validation of the
|
||||
|
|
|
@ -36,6 +36,9 @@ func (daemon *Daemon) ContainerStart(name string, hostConfig *runconfig.HostConf
|
|||
return err
|
||||
}
|
||||
container.Unlock()
|
||||
if err := daemon.adaptContainerSettings(hostConfig, false); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := daemon.setHostConfig(container, hostConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -1434,7 +1434,7 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeHostConfigOmitted(c *check.
|
|||
var containerJSON types.ContainerJSON
|
||||
c.Assert(json.Unmarshal(body, &containerJSON), check.IsNil)
|
||||
|
||||
c.Assert(containerJSON.HostConfig.ShmSize, check.IsNil)
|
||||
c.Assert(*containerJSON.HostConfig.ShmSize, check.Equals, runconfig.DefaultSHMSize)
|
||||
|
||||
out, _ := dockerCmd(c, "start", "-i", containerJSON.ID)
|
||||
shmRegexp := regexp.MustCompile(`shm on /dev/shm type tmpfs(.*)size=65536k`)
|
||||
|
@ -1522,5 +1522,5 @@ func (s *DockerSuite) TestPostContainersCreateMemorySwappinessHostConfigOmitted(
|
|||
var containerJSON types.ContainerJSON
|
||||
c.Assert(json.Unmarshal(body, &containerJSON), check.IsNil)
|
||||
|
||||
c.Assert(containerJSON.HostConfig.MemorySwappiness, check.IsNil)
|
||||
c.Assert(*containerJSON.HostConfig.MemorySwappiness, check.Equals, int64(-1))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue