mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #18285 from hqhq/hq_fix_swappiness
Set default MemorySwappiness when adapt
This commit is contained in:
commit
f411b101ac
6 changed files with 31 additions and 24 deletions
|
@ -301,11 +301,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{
|
||||
|
|
|
@ -31,7 +31,13 @@ func (daemon *Daemon) ContainerCreate(params *ContainerCreateConfig) (types.Cont
|
|||
return types.ContainerCreateResponse{ID: "", Warnings: warnings}, err
|
||||
}
|
||||
|
||||
daemon.adaptContainerSettings(params.HostConfig, params.AdjustCPUShares)
|
||||
if params.HostConfig == nil {
|
||||
params.HostConfig = &runconfig.HostConfig{}
|
||||
}
|
||||
err = daemon.adaptContainerSettings(params.HostConfig, params.AdjustCPUShares)
|
||||
if err != nil {
|
||||
return types.ContainerCreateResponse{ID: "", Warnings: warnings}, err
|
||||
}
|
||||
|
||||
container, err := daemon.create(params)
|
||||
if err != nil {
|
||||
|
@ -62,15 +68,6 @@ func (daemon *Daemon) create(params *ContainerCreateConfig) (retC *Container, re
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if params.HostConfig == nil {
|
||||
params.HostConfig = &runconfig.HostConfig{}
|
||||
}
|
||||
if params.HostConfig.SecurityOpt == nil {
|
||||
params.HostConfig.SecurityOpt, err = daemon.generateSecurityOpt(params.HostConfig.IpcMode, params.HostConfig.PidMode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if container, err = daemon.newContainer(params.Name, params.Config, imgID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -112,11 +112,7 @@ 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) {
|
||||
if hostConfig == nil {
|
||||
return
|
||||
}
|
||||
|
||||
func (daemon *Daemon) adaptContainerSettings(hostConfig *runconfig.HostConfig, adjustCPUShares bool) error {
|
||||
if adjustCPUShares && hostConfig.CPUShares > 0 {
|
||||
// Handle unsupported CPUShares
|
||||
if hostConfig.CPUShares < linuxMinCPUShares {
|
||||
|
@ -135,6 +131,19 @@ func (daemon *Daemon) adaptContainerSettings(hostConfig *runconfig.HostConfig, a
|
|||
shmSize := DefaultSHMSize
|
||||
hostConfig.ShmSize = &shmSize
|
||||
}
|
||||
var err error
|
||||
if hostConfig.SecurityOpt == nil {
|
||||
hostConfig.SecurityOpt, err = daemon.generateSecurityOpt(hostConfig.IpcMode, hostConfig.PidMode)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if hostConfig.MemorySwappiness == nil {
|
||||
defaultSwappiness := int64(-1)
|
||||
hostConfig.MemorySwappiness = &defaultSwappiness
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// verifyPlatformContainerSettings performs platform-specific validation of the
|
||||
|
|
|
@ -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…
Add table
Reference in a new issue