Skip to content

Commit 4e25d29

Browse files
committed
Use *int64 for MemorySwappiness.
So we marshal/unmarshal its value properly when it's empty. Signed-off-by: David Calavera <[email protected]>
1 parent 0bab97f commit 4e25d29

4 files changed

Lines changed: 26 additions & 19 deletions

File tree

daemon/container_unix.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,11 @@ func populateCommand(c *Container, env []string) error {
280280
BlkioWeight: c.hostConfig.BlkioWeight,
281281
Rlimits: rlimits,
282282
OomKillDisable: c.hostConfig.OomKillDisable,
283-
MemorySwappiness: c.hostConfig.MemorySwappiness,
283+
MemorySwappiness: -1,
284+
}
285+
286+
if c.hostConfig.MemorySwappiness != nil {
287+
resources.MemorySwappiness = *c.hostConfig.MemorySwappiness
284288
}
285289

286290
processConfig := execdriver.ProcessConfig{

daemon/daemon_unix.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,16 @@ func (daemon *Daemon) verifyContainerSettings(hostConfig *runconfig.HostConfig,
177177
if hostConfig.Memory == 0 && hostConfig.MemorySwap > 0 {
178178
return warnings, fmt.Errorf("You should always set the Memory limit when using Memoryswap limit, see usage.")
179179
}
180-
if hostConfig.MemorySwappiness != -1 && !daemon.SystemConfig().MemorySwappiness {
180+
if hostConfig.MemorySwappiness != nil && !daemon.SystemConfig().MemorySwappiness {
181181
warnings = append(warnings, "Your kernel does not support memory swappiness capabilities, memory swappiness discarded.")
182182
logrus.Warnf("Your kernel does not support memory swappiness capabilities, memory swappiness discarded.")
183-
hostConfig.MemorySwappiness = -1
183+
hostConfig.MemorySwappiness = nil
184184
}
185-
if hostConfig.MemorySwappiness != -1 && (hostConfig.MemorySwappiness < 0 || hostConfig.MemorySwappiness > 100) {
186-
return warnings, fmt.Errorf("Invalid value: %d, valid memory swappiness range is 0-100.", hostConfig.MemorySwappiness)
185+
if hostConfig.MemorySwappiness != nil {
186+
swappiness := *hostConfig.MemorySwappiness
187+
if swappiness < -1 || swappiness > 100 {
188+
return warnings, fmt.Errorf("Invalid value: %v, valid memory swappiness range is 0-100.", swappiness)
189+
}
187190
}
188191
if hostConfig.CPUPeriod > 0 && !daemon.SystemConfig().CpuCfsPeriod {
189192
warnings = append(warnings, "Your kernel does not support CPU cfs period. Period discarded.")

runconfig/hostconfig.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -260,19 +260,19 @@ func NewCapList(caps []string) *CapList {
260260
// Here, "non-portable" means "dependent of the host we are running on".
261261
// Portable information *should* appear in Config.
262262
type HostConfig struct {
263-
Binds []string // List of volume bindings for this container
264-
ContainerIDFile string // File (path) where the containerId is written
265-
LxcConf *LxcConfig // Additional lxc configuration
266-
Memory int64 // Memory limit (in bytes)
267-
MemorySwap int64 // Total memory usage (memory + swap); set `-1` to disable swap
268-
CPUShares int64 `json:"CpuShares"` // CPU shares (relative weight vs. other containers)
269-
CPUPeriod int64 `json:"CpuPeriod"` // CPU CFS (Completely Fair Scheduler) period
270-
CpusetCpus string // CpusetCpus 0-2, 0,1
271-
CpusetMems string // CpusetMems 0-2, 0,1
272-
CPUQuota int64 `json:"CpuQuota"` // CPU CFS (Completely Fair Scheduler) quota
273-
BlkioWeight int64 // Block IO weight (relative weight vs. other containers)
274-
OomKillDisable bool // Whether to disable OOM Killer or not
275-
MemorySwappiness int64 // Tuning container memory swappiness behaviour
263+
Binds []string // List of volume bindings for this container
264+
ContainerIDFile string // File (path) where the containerId is written
265+
LxcConf *LxcConfig // Additional lxc configuration
266+
Memory int64 // Memory limit (in bytes)
267+
MemorySwap int64 // Total memory usage (memory + swap); set `-1` to disable swap
268+
CPUShares int64 `json:"CpuShares"` // CPU shares (relative weight vs. other containers)
269+
CPUPeriod int64 `json:"CpuPeriod"` // CPU CFS (Completely Fair Scheduler) period
270+
CpusetCpus string // CpusetCpus 0-2, 0,1
271+
CpusetMems string // CpusetMems 0-2, 0,1
272+
CPUQuota int64 `json:"CpuQuota"` // CPU CFS (Completely Fair Scheduler) quota
273+
BlkioWeight int64 // Block IO weight (relative weight vs. other containers)
274+
OomKillDisable bool // Whether to disable OOM Killer or not
275+
MemorySwappiness *int64
276276
Privileged bool // Is the container in privileged mode
277277
PortBindings nat.PortMap // Port mapping between the exposed port (container) and the host
278278
Links []string // List of links (in the name:alias form)

runconfig/parse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSe
362362
CPUQuota: *flCPUQuota,
363363
BlkioWeight: *flBlkioWeight,
364364
OomKillDisable: *flOomKillDisable,
365-
MemorySwappiness: swappiness,
365+
MemorySwappiness: flSwappiness,
366366
Privileged: *flPrivileged,
367367
PortBindings: portBindings,
368368
Links: flLinks.GetAll(),

0 commit comments

Comments
 (0)