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,
|
Rlimits: rlimits,
|
||||||
BlkioWeightDevice: weightDevices,
|
BlkioWeightDevice: weightDevices,
|
||||||
OomKillDisable: c.hostConfig.OomKillDisable,
|
OomKillDisable: c.hostConfig.OomKillDisable,
|
||||||
MemorySwappiness: -1,
|
MemorySwappiness: *c.hostConfig.MemorySwappiness,
|
||||||
}
|
|
||||||
|
|
||||||
if c.hostConfig.MemorySwappiness != nil {
|
|
||||||
resources.MemorySwappiness = *c.hostConfig.MemorySwappiness
|
|
||||||
}
|
}
|
||||||
|
|
||||||
processConfig := execdriver.ProcessConfig{
|
processConfig := execdriver.ProcessConfig{
|
||||||
|
|
|
@ -138,6 +138,10 @@ func (daemon *Daemon) adaptContainerSettings(hostConfig *runconfig.HostConfig, a
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if hostConfig.MemorySwappiness == nil {
|
||||||
|
defaultSwappiness := int64(-1)
|
||||||
|
hostConfig.MemorySwappiness = &defaultSwappiness
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,9 +48,9 @@ func checkKernel() error {
|
||||||
|
|
||||||
// adaptContainerSettings is called during container creation to modify any
|
// adaptContainerSettings is called during container creation to modify any
|
||||||
// settings necessary in the HostConfig structure.
|
// 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 {
|
if hostConfig == nil {
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if hostConfig.CPUShares < 0 {
|
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)
|
logrus.Warnf("Changing requested CPUShares of %d to maximum allowed of %d", hostConfig.CPUShares, windowsMaxCPUShares)
|
||||||
hostConfig.CPUShares = windowsMaxCPUShares
|
hostConfig.CPUShares = windowsMaxCPUShares
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// verifyPlatformContainerSettings performs platform-specific validation of the
|
// verifyPlatformContainerSettings performs platform-specific validation of the
|
||||||
|
|
|
@ -36,6 +36,9 @@ func (daemon *Daemon) ContainerStart(name string, hostConfig *runconfig.HostConf
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
container.Unlock()
|
container.Unlock()
|
||||||
|
if err := daemon.adaptContainerSettings(hostConfig, false); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if err := daemon.setHostConfig(container, hostConfig); err != nil {
|
if err := daemon.setHostConfig(container, hostConfig); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -1434,7 +1434,7 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeHostConfigOmitted(c *check.
|
||||||
var containerJSON types.ContainerJSON
|
var containerJSON types.ContainerJSON
|
||||||
c.Assert(json.Unmarshal(body, &containerJSON), check.IsNil)
|
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)
|
out, _ := dockerCmd(c, "start", "-i", containerJSON.ID)
|
||||||
shmRegexp := regexp.MustCompile(`shm on /dev/shm type tmpfs(.*)size=65536k`)
|
shmRegexp := regexp.MustCompile(`shm on /dev/shm type tmpfs(.*)size=65536k`)
|
||||||
|
@ -1522,5 +1522,5 @@ func (s *DockerSuite) TestPostContainersCreateMemorySwappinessHostConfigOmitted(
|
||||||
var containerJSON types.ContainerJSON
|
var containerJSON types.ContainerJSON
|
||||||
c.Assert(json.Unmarshal(body, &containerJSON), check.IsNil)
|
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