So we marshal/unmarshal its value properly when it's empty.
Signed-off-by: David Calavera <david.calavera@gmail.com>
| ... | ... |
@@ -280,7 +280,11 @@ func populateCommand(c *Container, env []string) error {
|
| 280 | 280 |
BlkioWeight: c.hostConfig.BlkioWeight, |
| 281 | 281 |
Rlimits: rlimits, |
| 282 | 282 |
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 |
|
| 284 | 288 |
} |
| 285 | 289 |
|
| 286 | 290 |
processConfig := execdriver.ProcessConfig{
|
| ... | ... |
@@ -177,13 +177,16 @@ func (daemon *Daemon) verifyContainerSettings(hostConfig *runconfig.HostConfig, |
| 177 | 177 |
if hostConfig.Memory == 0 && hostConfig.MemorySwap > 0 {
|
| 178 | 178 |
return warnings, fmt.Errorf("You should always set the Memory limit when using Memoryswap limit, see usage.")
|
| 179 | 179 |
} |
| 180 |
- if hostConfig.MemorySwappiness != -1 && !daemon.SystemConfig().MemorySwappiness {
|
|
| 180 |
+ if hostConfig.MemorySwappiness != nil && !daemon.SystemConfig().MemorySwappiness {
|
|
| 181 | 181 |
warnings = append(warnings, "Your kernel does not support memory swappiness capabilities, memory swappiness discarded.") |
| 182 | 182 |
logrus.Warnf("Your kernel does not support memory swappiness capabilities, memory swappiness discarded.")
|
| 183 |
- hostConfig.MemorySwappiness = -1 |
|
| 183 |
+ hostConfig.MemorySwappiness = nil |
|
| 184 | 184 |
} |
| 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 |
+ } |
|
| 187 | 190 |
} |
| 188 | 191 |
if hostConfig.CPUPeriod > 0 && !daemon.SystemConfig().CpuCfsPeriod {
|
| 189 | 192 |
warnings = append(warnings, "Your kernel does not support CPU cfs period. Period discarded.") |
| ... | ... |
@@ -260,19 +260,19 @@ func NewCapList(caps []string) *CapList {
|
| 260 | 260 |
// Here, "non-portable" means "dependent of the host we are running on". |
| 261 | 261 |
// Portable information *should* appear in Config. |
| 262 | 262 |
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 |
|
| 276 | 276 |
Privileged bool // Is the container in privileged mode |
| 277 | 277 |
PortBindings nat.PortMap // Port mapping between the exposed port (container) and the host |
| 278 | 278 |
Links []string // List of links (in the name:alias form) |
| ... | ... |
@@ -362,7 +362,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSe |
| 362 | 362 |
CPUQuota: *flCPUQuota, |
| 363 | 363 |
BlkioWeight: *flBlkioWeight, |
| 364 | 364 |
OomKillDisable: *flOomKillDisable, |
| 365 |
- MemorySwappiness: swappiness, |
|
| 365 |
+ MemorySwappiness: flSwappiness, |
|
| 366 | 366 |
Privileged: *flPrivileged, |
| 367 | 367 |
PortBindings: portBindings, |
| 368 | 368 |
Links: flLinks.GetAll(), |