1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

add support for cpuset.mems

Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
This commit is contained in:
Qiang Huang 2015-04-15 09:33:46 +08:00
parent 3a3ab0e4e7
commit 8077b2fb80
11 changed files with 59 additions and 2 deletions

View file

@ -355,6 +355,7 @@ func populateCommand(c *Container, env []string) error {
MemorySwap: c.hostConfig.MemorySwap, MemorySwap: c.hostConfig.MemorySwap,
CpuShares: c.hostConfig.CpuShares, CpuShares: c.hostConfig.CpuShares,
CpusetCpus: c.hostConfig.CpusetCpus, CpusetCpus: c.hostConfig.CpusetCpus,
CpusetMems: c.hostConfig.CpusetMems,
Rlimits: rlimits, Rlimits: rlimits,
} }

View file

@ -110,6 +110,7 @@ type Resources struct {
MemorySwap int64 `json:"memory_swap"` MemorySwap int64 `json:"memory_swap"`
CpuShares int64 `json:"cpu_shares"` CpuShares int64 `json:"cpu_shares"`
CpusetCpus string `json:"cpuset_cpus"` CpusetCpus string `json:"cpuset_cpus"`
CpusetMems string `json:"cpuset_mems"`
Rlimits []*ulimit.Rlimit `json:"rlimits"` Rlimits []*ulimit.Rlimit `json:"rlimits"`
} }
@ -204,6 +205,7 @@ func SetupCgroups(container *configs.Config, c *Command) error {
container.Cgroups.MemoryReservation = c.Resources.Memory container.Cgroups.MemoryReservation = c.Resources.Memory
container.Cgroups.MemorySwap = c.Resources.MemorySwap container.Cgroups.MemorySwap = c.Resources.MemorySwap
container.Cgroups.CpusetCpus = c.Resources.CpusetCpus container.Cgroups.CpusetCpus = c.Resources.CpusetCpus
container.Cgroups.CpusetMems = c.Resources.CpusetMems
} }
return nil return nil

View file

@ -110,6 +110,9 @@ lxc.cgroup.cpu.shares = {{.Resources.CpuShares}}
{{if .Resources.CpusetCpus}} {{if .Resources.CpusetCpus}}
lxc.cgroup.cpuset.cpus = {{.Resources.CpusetCpus}} lxc.cgroup.cpuset.cpus = {{.Resources.CpusetCpus}}
{{end}} {{end}}
{{if .Resources.CpusetMems}}
lxc.cgroup.cpuset.mems = {{.Resources.CpusetMems}}
{{end}}
{{end}} {{end}}
{{if .LxcConfig}} {{if .LxcConfig}}

View file

@ -13,6 +13,7 @@ docker-create - Create a new container
[**--cap-drop**[=*[]*]] [**--cap-drop**[=*[]*]]
[**--cidfile**[=*CIDFILE*]] [**--cidfile**[=*CIDFILE*]]
[**--cpuset-cpus**[=*CPUSET-CPUS*]] [**--cpuset-cpus**[=*CPUSET-CPUS*]]
[**--cpuset-mems**[=*CPUSET-MEMS*]]
[**--device**[=*[]*]] [**--device**[=*[]*]]
[**--dns-search**[=*[]*]] [**--dns-search**[=*[]*]]
[**--dns**[=*[]*]] [**--dns**[=*[]*]]
@ -74,6 +75,13 @@ IMAGE [COMMAND] [ARG...]
**--cpuset-cpus**="" **--cpuset-cpus**=""
CPUs in which to allow execution (0-3, 0,1) CPUs in which to allow execution (0-3, 0,1)
**--cpuset-mems**=""
Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems.
If you have four memory nodes on your system (0-3), use `--cpuset-mems=0,1`
then processes in your Docker container will only use memory from the first
two memory nodes.
**--device**=[] **--device**=[]
Add a host device to the container (e.g. --device=/dev/sdc:/dev/xvdc:rwm) Add a host device to the container (e.g. --device=/dev/sdc:/dev/xvdc:rwm)

View file

@ -13,6 +13,7 @@ docker-run - Run a command in a new container
[**--cap-drop**[=*[]*]] [**--cap-drop**[=*[]*]]
[**--cidfile**[=*CIDFILE*]] [**--cidfile**[=*CIDFILE*]]
[**--cpuset-cpus**[=*CPUSET-CPUS*]] [**--cpuset-cpus**[=*CPUSET-CPUS*]]
[**--cpuset-mems**[=*CPUSET-MEMS*]]
[**-d**|**--detach**[=*false*]] [**-d**|**--detach**[=*false*]]
[**--device**[=*[]*]] [**--device**[=*[]*]]
[**--dns-search**[=*[]*]] [**--dns-search**[=*[]*]]
@ -134,6 +135,13 @@ division of CPU shares:
**--cpuset-cpus**="" **--cpuset-cpus**=""
CPUs in which to allow execution (0-3, 0,1) CPUs in which to allow execution (0-3, 0,1)
**--cpuset-mems**=""
Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems.
If you have four memory nodes on your system (0-3), use `--cpuset-mems=0,1`
then processes in your Docker container will only use memory from the first
two memory nodes.
**-d**, **--detach**=*true*|*false* **-d**, **--detach**=*true*|*false*
Detached mode: run the container in the background and print the new container ID. The default is *false*. Detached mode: run the container in the background and print the new container ID. The default is *false*.

View file

@ -147,6 +147,7 @@ Create a container
"MemorySwap": 0, "MemorySwap": 0,
"CpuShares": 512, "CpuShares": 512,
"CpusetCpus": "0,1", "CpusetCpus": "0,1",
"CpusetMems": "0,1",
"PortBindings": { "22/tcp": [{ "HostPort": "11022" }] }, "PortBindings": { "22/tcp": [{ "HostPort": "11022" }] },
"PublishAllPorts": false, "PublishAllPorts": false,
"Privileged": false, "Privileged": false,
@ -191,6 +192,7 @@ Json Parameters:
(ie. the relative weight vs other containers). (ie. the relative weight vs other containers).
- **Cpuset** - The same as CpusetCpus, but deprecated, please don't use. - **Cpuset** - The same as CpusetCpus, but deprecated, please don't use.
- **CpusetCpus** - String value containing the cgroups CpusetCpus to use. - **CpusetCpus** - String value containing the cgroups CpusetCpus to use.
- **CpusetMems** - Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems.
- **AttachStdin** - Boolean value, attaches to stdin. - **AttachStdin** - Boolean value, attaches to stdin.
- **AttachStdout** - Boolean value, attaches to stdout. - **AttachStdout** - Boolean value, attaches to stdout.
- **AttachStderr** - Boolean value, attaches to stderr. - **AttachStderr** - Boolean value, attaches to stderr.
@ -340,6 +342,7 @@ Return low-level information on the container `id`
"CapDrop": null, "CapDrop": null,
"ContainerIDFile": "", "ContainerIDFile": "",
"CpusetCpus": "", "CpusetCpus": "",
"CpusetMems": "",
"CpuShares": 0, "CpuShares": 0,
"Devices": [], "Devices": [],
"Dns": null, "Dns": null,

View file

@ -892,6 +892,7 @@ Creates a new container.
--cgroup-parent="" Optional parent cgroup for the container --cgroup-parent="" Optional parent cgroup for the container
--cidfile="" Write the container ID to the file --cidfile="" Write the container ID to the file
--cpuset-cpus="" CPUs in which to allow execution (0-3, 0,1) --cpuset-cpus="" CPUs in which to allow execution (0-3, 0,1)
--cpuset-mems="" Memory nodes (MEMs) in which to allow execution (0-3, 0,1)
--device=[] Add a host device to the container --device=[] Add a host device to the container
--dns=[] Set custom DNS servers --dns=[] Set custom DNS servers
--dns-search=[] Set custom DNS search domains --dns-search=[] Set custom DNS search domains
@ -1844,6 +1845,7 @@ To remove an image using its digest:
--cap-drop=[] Drop Linux capabilities --cap-drop=[] Drop Linux capabilities
--cidfile="" Write the container ID to the file --cidfile="" Write the container ID to the file
--cpuset-cpus="" CPUs in which to allow execution (0-3, 0,1) --cpuset-cpus="" CPUs in which to allow execution (0-3, 0,1)
--cpuset-mems="" Memory nodes (MEMs) in which to allow execution (0-3, 0,1)
-d, --detach=false Run container in background and print container ID -d, --detach=false Run container in background and print container ID
--device=[] Add a host device to the container --device=[] Add a host device to the container
--dns=[] Set custom DNS servers --dns=[] Set custom DNS servers

View file

@ -474,6 +474,7 @@ container:
-memory-swap="": Total memory limit (memory + swap, format: <number><optional unit>, where unit = b, k, m or g) -memory-swap="": Total memory limit (memory + swap, format: <number><optional unit>, where unit = b, k, m or g)
-c, --cpu-shares=0: CPU shares (relative weight) -c, --cpu-shares=0: CPU shares (relative weight)
--cpuset-cpus="": CPUs in which to allow execution (0-3, 0,1) --cpuset-cpus="": CPUs in which to allow execution (0-3, 0,1)
--cpuset-mems="": Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems.
### Memory constraints ### Memory constraints
@ -599,6 +600,21 @@ This means processes in container can be executed on cpu 1 and cpu 3.
This means processes in container can be executed on cpu 0, cpu 1 and cpu 2. This means processes in container can be executed on cpu 0, cpu 1 and cpu 2.
We can set mems in which to allow execution for containers. Only effective
on NUMA systems.
Examples:
$ docker run -ti --cpuset-mems="1,3" ubuntu:14.04 /bin/bash
This example restricts the processes in the container to only use memory from
memory nodes 1 and 3.
$ docker run -ti --cpuset-mems="0-2" ubuntu:14.04 /bin/bash
This example restricts the processes in the container to only use memory from
memory nodes 0, 1 and 2.
## Runtime privilege, Linux capabilities, and LXC configuration ## Runtime privilege, Linux capabilities, and LXC configuration
--cap-add: Add Linux capabilities --cap-add: Add Linux capabilities

View file

@ -1367,7 +1367,7 @@ func TestRunWithCpuset(t *testing.T) {
cmd := exec.Command(dockerBinary, "run", "--cpuset", "0", "busybox", "true") cmd := exec.Command(dockerBinary, "run", "--cpuset", "0", "busybox", "true")
if code, err := runCommand(cmd); err != nil || code != 0 { if code, err := runCommand(cmd); err != nil || code != 0 {
t.Fatalf("container should run successfuly with cpuset of 0: %s", err) t.Fatalf("container should run successfully with cpuset of 0: %s", err)
} }
logDone("run - cpuset 0") logDone("run - cpuset 0")
@ -1378,12 +1378,23 @@ func TestRunWithCpusetCpus(t *testing.T) {
cmd := exec.Command(dockerBinary, "run", "--cpuset-cpus", "0", "busybox", "true") cmd := exec.Command(dockerBinary, "run", "--cpuset-cpus", "0", "busybox", "true")
if code, err := runCommand(cmd); err != nil || code != 0 { if code, err := runCommand(cmd); err != nil || code != 0 {
t.Fatalf("container should run successfuly with cpuset-cpus of 0: %s", err) t.Fatalf("container should run successfully with cpuset-cpus of 0: %s", err)
} }
logDone("run - cpuset-cpus 0") logDone("run - cpuset-cpus 0")
} }
func TestRunWithCpusetMems(t *testing.T) {
defer deleteAllContainers()
cmd := exec.Command(dockerBinary, "run", "--cpuset-mems", "0", "busybox", "true")
if code, err := runCommand(cmd); err != nil || code != 0 {
t.Fatalf("container should run successfully with cpuset-mems of 0: %s", err)
}
logDone("run - cpuset-mems 0")
}
func TestRunDeviceNumbers(t *testing.T) { func TestRunDeviceNumbers(t *testing.T) {
defer deleteAllContainers() defer deleteAllContainers()

View file

@ -116,6 +116,7 @@ type HostConfig struct {
MemorySwap int64 // Total memory usage (memory + swap); set `-1` to disable swap MemorySwap int64 // Total memory usage (memory + swap); set `-1` to disable swap
CpuShares int64 // CPU shares (relative weight vs. other containers) CpuShares int64 // CPU shares (relative weight vs. other containers)
CpusetCpus string // CpusetCpus 0-2, 0,1 CpusetCpus string // CpusetCpus 0-2, 0,1
CpusetMems string // CpusetMems 0-2, 0,1
Privileged bool Privileged bool
PortBindings nat.PortMap PortBindings nat.PortMap
Links []string Links []string

View file

@ -64,6 +64,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSe
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)")
flCpusetCpus = cmd.String([]string{"#-cpuset", "-cpuset-cpus"}, "", "CPUs in which to allow execution (0-3, 0,1)") flCpusetCpus = cmd.String([]string{"#-cpuset", "-cpuset-cpus"}, "", "CPUs in which to allow execution (0-3, 0,1)")
flCpusetMems = cmd.String([]string{"-cpuset-mems"}, "", "MEMs in which to allow execution (0-3, 0,1)")
flNetMode = cmd.String([]string{"-net"}, "bridge", "Set the Network mode for the container") flNetMode = cmd.String([]string{"-net"}, "bridge", "Set the Network mode for the container")
flMacAddress = cmd.String([]string{"-mac-address"}, "", "Container MAC address (e.g. 92:d0:c6:0a:29:33)") flMacAddress = cmd.String([]string{"-mac-address"}, "", "Container MAC address (e.g. 92:d0:c6:0a:29:33)")
flIpcMode = cmd.String([]string{"-ipc"}, "", "IPC namespace to use") flIpcMode = cmd.String([]string{"-ipc"}, "", "IPC namespace to use")
@ -313,6 +314,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSe
MemorySwap: MemorySwap, MemorySwap: MemorySwap,
CpuShares: *flCpuShares, CpuShares: *flCpuShares,
CpusetCpus: *flCpusetCpus, CpusetCpus: *flCpusetCpus,
CpusetMems: *flCpusetMems,
Privileged: *flPrivileged, Privileged: *flPrivileged,
PortBindings: portBindings, PortBindings: portBindings,
Links: flLinks.GetAll(), Links: flLinks.GetAll(),