mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
add support to set MemorySwap
Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
This commit is contained in:
parent
eba451b659
commit
1a9b640e0d
2 changed files with 14 additions and 0 deletions
|
@ -29,6 +29,9 @@ func (daemon *Daemon) ContainerCreate(job *engine.Job) engine.Status {
|
||||||
job.Errorf("Your kernel does not support swap limit capabilities. Limitation discarded.\n")
|
job.Errorf("Your kernel does not support swap limit capabilities. Limitation discarded.\n")
|
||||||
config.MemorySwap = -1
|
config.MemorySwap = -1
|
||||||
}
|
}
|
||||||
|
if config.Memory > 0 && config.MemorySwap > 0 && config.MemorySwap < config.Memory {
|
||||||
|
return job.Errorf("Minimum memoryswap limit should larger than memory limit, see usage.\n")
|
||||||
|
}
|
||||||
|
|
||||||
var hostConfig *runconfig.HostConfig
|
var hostConfig *runconfig.HostConfig
|
||||||
if job.EnvExists("HostConfig") {
|
if job.EnvExists("HostConfig") {
|
||||||
|
|
|
@ -53,6 +53,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSe
|
||||||
flEntrypoint = cmd.String([]string{"#entrypoint", "-entrypoint"}, "", "Overwrite the default ENTRYPOINT of the image")
|
flEntrypoint = cmd.String([]string{"#entrypoint", "-entrypoint"}, "", "Overwrite the default ENTRYPOINT of the image")
|
||||||
flHostname = cmd.String([]string{"h", "-hostname"}, "", "Container host name")
|
flHostname = cmd.String([]string{"h", "-hostname"}, "", "Container host name")
|
||||||
flMemoryString = cmd.String([]string{"m", "-memory"}, "", "Memory limit (format: <number><optional unit>, where unit = b, k, m or g)")
|
flMemoryString = cmd.String([]string{"m", "-memory"}, "", "Memory limit (format: <number><optional unit>, where unit = b, k, m or g)")
|
||||||
|
flMemorySwap = cmd.String([]string{"-memory-swap"}, "", "Total memory usage (memory + swap), set '-1' to disable swap (format: <number><optional unit>, where unit = b, k, m or g)")
|
||||||
flUser = cmd.String([]string{"u", "-user"}, "", "Username or UID")
|
flUser = cmd.String([]string{"u", "-user"}, "", "Username or UID")
|
||||||
flWorkingDir = cmd.String([]string{"w", "-workdir"}, "", "Working directory inside the container")
|
flWorkingDir = cmd.String([]string{"w", "-workdir"}, "", "Working directory inside the container")
|
||||||
flCpuShares = cmd.Int64([]string{"c", "-cpu-shares"}, 0, "CPU shares (relative weight)")
|
flCpuShares = cmd.Int64([]string{"c", "-cpu-shares"}, 0, "CPU shares (relative weight)")
|
||||||
|
@ -136,6 +137,15 @@ func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSe
|
||||||
flMemory = parsedMemory
|
flMemory = parsedMemory
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var MemorySwap int64
|
||||||
|
if *flMemorySwap != "" {
|
||||||
|
parsedMemorySwap, err := units.RAMInBytes(*flMemorySwap)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, cmd, err
|
||||||
|
}
|
||||||
|
MemorySwap = parsedMemorySwap
|
||||||
|
}
|
||||||
|
|
||||||
var binds []string
|
var binds []string
|
||||||
// add any bind targets to the list of container volumes
|
// add any bind targets to the list of container volumes
|
||||||
for bind := range flVolumes.GetMap() {
|
for bind := range flVolumes.GetMap() {
|
||||||
|
@ -261,6 +271,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSe
|
||||||
NetworkDisabled: !*flNetwork,
|
NetworkDisabled: !*flNetwork,
|
||||||
OpenStdin: *flStdin,
|
OpenStdin: *flStdin,
|
||||||
Memory: flMemory,
|
Memory: flMemory,
|
||||||
|
MemorySwap: MemorySwap,
|
||||||
CpuShares: *flCpuShares,
|
CpuShares: *flCpuShares,
|
||||||
Cpuset: *flCpuset,
|
Cpuset: *flCpuset,
|
||||||
AttachStdin: attachStdin,
|
AttachStdin: attachStdin,
|
||||||
|
|
Loading…
Add table
Reference in a new issue