We can use this to control block IO weight of a container.
Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
| ... | ... |
@@ -383,6 +383,7 @@ func populateCommand(c *Container, env []string) error {
|
| 383 | 383 |
CpusetCpus: c.hostConfig.CpusetCpus, |
| 384 | 384 |
CpusetMems: c.hostConfig.CpusetMems, |
| 385 | 385 |
CpuQuota: c.hostConfig.CpuQuota, |
| 386 |
+ BlkioWeight: c.hostConfig.BlkioWeight, |
|
| 386 | 387 |
Rlimits: rlimits, |
| 387 | 388 |
OomKillDisable: c.hostConfig.OomKillDisable, |
| 388 | 389 |
} |
| ... | ... |
@@ -1184,6 +1184,9 @@ func (daemon *Daemon) verifyHostConfig(hostConfig *runconfig.HostConfig) ([]stri |
| 1184 | 1184 |
warnings = append(warnings, "Your kernel does not support CPU cfs quota. Quota discarded.") |
| 1185 | 1185 |
hostConfig.CpuQuota = 0 |
| 1186 | 1186 |
} |
| 1187 |
+ if hostConfig.BlkioWeight > 0 && (hostConfig.BlkioWeight < 10 || hostConfig.BlkioWeight > 1000) {
|
|
| 1188 |
+ return warnings, fmt.Errorf("Range of blkio weight is from 10 to 1000.")
|
|
| 1189 |
+ } |
|
| 1187 | 1190 |
|
| 1188 | 1191 |
return warnings, nil |
| 1189 | 1192 |
} |
| ... | ... |
@@ -106,6 +106,7 @@ type Resources struct {
|
| 106 | 106 |
CpusetCpus string `json:"cpuset_cpus"` |
| 107 | 107 |
CpusetMems string `json:"cpuset_mems"` |
| 108 | 108 |
CpuQuota int64 `json:"cpu_quota"` |
| 109 |
+ BlkioWeight int64 `json:"blkio_weight"` |
|
| 109 | 110 |
Rlimits []*ulimit.Rlimit `json:"rlimits"` |
| 110 | 111 |
OomKillDisable bool `json:"oom_kill_disable"` |
| 111 | 112 |
} |
| ... | ... |
@@ -54,6 +54,7 @@ func SetupCgroups(container *configs.Config, c *Command) error {
|
| 54 | 54 |
container.Cgroups.CpusetCpus = c.Resources.CpusetCpus |
| 55 | 55 |
container.Cgroups.CpusetMems = c.Resources.CpusetMems |
| 56 | 56 |
container.Cgroups.CpuQuota = c.Resources.CpuQuota |
| 57 |
+ container.Cgroups.BlkioWeight = c.Resources.BlkioWeight |
|
| 57 | 58 |
container.Cgroups.OomKillDisable = c.Resources.OomKillDisable |
| 58 | 59 |
} |
| 59 | 60 |
|
| ... | ... |
@@ -118,6 +118,9 @@ lxc.cgroup.cpuset.mems = {{.Resources.CpusetMems}}
|
| 118 | 118 |
{{if .Resources.CpuQuota}}
|
| 119 | 119 |
lxc.cgroup.cpu.cfs_quota_us = {{.Resources.CpuQuota}}
|
| 120 | 120 |
{{end}}
|
| 121 |
+{{if .Resources.BlkioWeight}}
|
|
| 122 |
+lxc.cgroup.blkio.weight = {{.Resources.BlkioWeight}}
|
|
| 123 |
+{{end}}
|
|
| 121 | 124 |
{{if .Resources.OomKillDisable}}
|
| 122 | 125 |
lxc.cgroup.memory.oom_control = {{.Resources.OomKillDisable}}
|
| 123 | 126 |
{{end}}
|
| ... | ... |
@@ -8,6 +8,7 @@ docker-create - Create a new container |
| 8 | 8 |
**docker create** |
| 9 | 9 |
[**-a**|**--attach**[=*[]*]] |
| 10 | 10 |
[**--add-host**[=*[]*]] |
| 11 |
+[**--blkio-weight**[=*[BLKIO-WEIGHT]*]] |
|
| 11 | 12 |
[**-c**|**--cpu-shares**[=*0*]] |
| 12 | 13 |
[**--cap-add**[=*[]*]] |
| 13 | 14 |
[**--cap-drop**[=*[]*]] |
| ... | ... |
@@ -59,6 +60,9 @@ IMAGE [COMMAND] [ARG...] |
| 59 | 59 |
**--add-host**=[] |
| 60 | 60 |
Add a custom host-to-IP mapping (host:ip) |
| 61 | 61 |
|
| 62 |
+**--blkio-weight**=0 |
|
| 63 |
+ Block IO weight (relative weight) accepts a weight value between 10 and 1000. |
|
| 64 |
+ |
|
| 62 | 65 |
**-c**, **--cpu-shares**=0 |
| 63 | 66 |
CPU shares (relative weight) |
| 64 | 67 |
|
| ... | ... |
@@ -8,6 +8,7 @@ docker-run - Run a command in a new container |
| 8 | 8 |
**docker run** |
| 9 | 9 |
[**-a**|**--attach**[=*[]*]] |
| 10 | 10 |
[**--add-host**[=*[]*]] |
| 11 |
+[**--blkio-weight**[=*[BLKIO-WEIGHT]*]] |
|
| 11 | 12 |
[**-c**|**--cpu-shares**[=*0*]] |
| 12 | 13 |
[**--cap-add**[=*[]*]] |
| 13 | 14 |
[**--cap-drop**[=*[]*]] |
| ... | ... |
@@ -86,6 +87,9 @@ each of stdin, stdout, and stderr. |
| 86 | 86 |
Add a line to /etc/hosts. The format is hostname:ip. The **--add-host** |
| 87 | 87 |
option can be set multiple times. |
| 88 | 88 |
|
| 89 |
+**--blkio-weight**=0 |
|
| 90 |
+ Block IO weight (relative weight) accepts a weight value between 10 and 1000. |
|
| 91 |
+ |
|
| 89 | 92 |
**-c**, **--cpu-shares**=0 |
| 90 | 93 |
CPU shares (relative weight) |
| 91 | 94 |
|
| ... | ... |
@@ -149,6 +149,7 @@ Create a container |
| 149 | 149 |
"CpuShares": 512, |
| 150 | 150 |
"CpusetCpus": "0,1", |
| 151 | 151 |
"CpusetMems": "0,1", |
| 152 |
+ "BlkioWeight": 300, |
|
| 152 | 153 |
"OomKillDisable": false, |
| 153 | 154 |
"PortBindings": { "22/tcp": [{ "HostPort": "11022" }] },
|
| 154 | 155 |
"PublishAllPorts": false, |
| ... | ... |
@@ -195,6 +196,7 @@ Json Parameters: |
| 195 | 195 |
- **Cpuset** - The same as CpusetCpus, but deprecated, please don't use. |
| 196 | 196 |
- **CpusetCpus** - String value containing the cgroups CpusetCpus to use. |
| 197 | 197 |
- **CpusetMems** - Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems. |
| 198 |
+- **BlkioWeight** - Block IO weight (relative weight) accepts a weight value between 10 and 1000. |
|
| 198 | 199 |
- **OomKillDisable** - Boolean value, whether to disable OOM Killer for the container or not. |
| 199 | 200 |
- **AttachStdin** - Boolean value, attaches to stdin. |
| 200 | 201 |
- **AttachStdout** - Boolean value, attaches to stdout. |
| ... | ... |
@@ -341,6 +343,7 @@ Return low-level information on the container `id` |
| 341 | 341 |
"ExecIDs": null, |
| 342 | 342 |
"HostConfig": {
|
| 343 | 343 |
"Binds": null, |
| 344 |
+ "BlkioWeight": 0, |
|
| 344 | 345 |
"CapAdd": null, |
| 345 | 346 |
"CapDrop": null, |
| 346 | 347 |
"ContainerIDFile": "", |
| ... | ... |
@@ -941,6 +941,7 @@ Creates a new container. |
| 941 | 941 |
|
| 942 | 942 |
-a, --attach=[] Attach to STDIN, STDOUT or STDERR |
| 943 | 943 |
--add-host=[] Add a custom host-to-IP mapping (host:ip) |
| 944 |
+ --blkio-weight=0 Block IO weight (relative weight) |
|
| 944 | 945 |
-c, --cpu-shares=0 CPU shares (relative weight) |
| 945 | 946 |
--cap-add=[] Add Linux capabilities |
| 946 | 947 |
--cap-drop=[] Drop Linux capabilities |
| ... | ... |
@@ -1898,6 +1899,7 @@ To remove an image using its digest: |
| 1898 | 1898 |
|
| 1899 | 1899 |
-a, --attach=[] Attach to STDIN, STDOUT or STDERR |
| 1900 | 1900 |
--add-host=[] Add a custom host-to-IP mapping (host:ip) |
| 1901 |
+ --blkio-weight=0 Block IO weight (relative weight) |
|
| 1901 | 1902 |
-c, --cpu-shares=0 CPU shares (relative weight) |
| 1902 | 1903 |
--cap-add=[] Add Linux capabilities |
| 1903 | 1904 |
--cap-drop=[] Drop Linux capabilities |
| ... | ... |
@@ -483,6 +483,7 @@ container: |
| 483 | 483 |
--cpuset-cpus="": CPUs in which to allow execution (0-3, 0,1) |
| 484 | 484 |
--cpuset-mems="": Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems. |
| 485 | 485 |
--cpu-quota=0: Limit the CPU CFS (Completely Fair Scheduler) quota |
| 486 |
+ --blkio-weight=0: Block IO weight (relative weight) accepts a weight value between 10 and 1000. |
|
| 486 | 487 |
--oom-kill-disable=true|false: Whether to disable OOM Killer for the container or not. |
| 487 | 488 |
|
| 488 | 489 |
### Memory constraints |
| ... | ... |
@@ -654,6 +655,30 @@ Linux Scheduler used by the kernel. Set this value to 50000 to limit the contain |
| 654 | 654 |
to 50% of a CPU resource. For multiple CPUs, adjust the `--cpu-quota` as necessary. |
| 655 | 655 |
For more information, see the [CFS documentation on bandwidth limiting](https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt). |
| 656 | 656 |
|
| 657 |
+### Block IO bandwidth (Blkio) constraint |
|
| 658 |
+ |
|
| 659 |
+By default, all containers get the same proportion of block IO bandwidth |
|
| 660 |
+(blkio). This proportion is 500. To modify this proportion, change the |
|
| 661 |
+container's blkio weight relative to the weighting of all other running |
|
| 662 |
+containers using the `--blkio-weight` flag. |
|
| 663 |
+ |
|
| 664 |
+The `--blkio-weight` flag can set the weighting to a value between 10 to 1000. |
|
| 665 |
+For example, the commands below create two containers with different blkio |
|
| 666 |
+weight: |
|
| 667 |
+ |
|
| 668 |
+ $ docker run -ti --name c1 --blkio-weight 300 ubuntu:14.04 /bin/bash |
|
| 669 |
+ $ docker run -ti --name c2 --blkio-weight 600 ubuntu:14.04 /bin/bash |
|
| 670 |
+ |
|
| 671 |
+If you do block IO in the two containers at the same time, by, for example: |
|
| 672 |
+ |
|
| 673 |
+ $ time dd if=/mnt/zerofile of=test.out bs=1M count=1024 oflag=direct |
|
| 674 |
+ |
|
| 675 |
+You'll find that the proportion of time is the same as the proportion of blkio |
|
| 676 |
+weights of the two containers. |
|
| 677 |
+ |
|
| 678 |
+> **Note:** The blkio weight setting is only available for direct IO. Buffered IO |
|
| 679 |
+> is not currently supported. |
|
| 680 |
+ |
|
| 657 | 681 |
## Runtime privilege, Linux capabilities, and LXC configuration |
| 658 | 682 |
|
| 659 | 683 |
--cap-add: Add Linux capabilities |
| ... | ... |
@@ -1158,6 +1158,20 @@ func (s *DockerSuite) TestRunWithCpusetMems(c *check.C) {
|
| 1158 | 1158 |
} |
| 1159 | 1159 |
} |
| 1160 | 1160 |
|
| 1161 |
+func (s *DockerSuite) TestRunWithBlkioWeight(c *check.C) {
|
|
| 1162 |
+ cmd := exec.Command(dockerBinary, "run", "--blkio-weight", "300", "busybox", "true") |
|
| 1163 |
+ if code, err := runCommand(cmd); err != nil || code != 0 {
|
|
| 1164 |
+ c.Fatalf("container should run successfully with blkio-weight of 300: %s", err)
|
|
| 1165 |
+ } |
|
| 1166 |
+} |
|
| 1167 |
+ |
|
| 1168 |
+func (s *DockerSuite) TestRunWithBlkioInvalidWeight(c *check.C) {
|
|
| 1169 |
+ cmd := exec.Command(dockerBinary, "run", "--blkio-weight", "5", "busybox", "true") |
|
| 1170 |
+ if _, err := runCommand(cmd); err == nil {
|
|
| 1171 |
+ c.Fatalf("run with invalid blkio-weight should failed")
|
|
| 1172 |
+ } |
|
| 1173 |
+} |
|
| 1174 |
+ |
|
| 1161 | 1175 |
func (s *DockerSuite) TestRunDeviceNumbers(c *check.C) {
|
| 1162 | 1176 |
cmd := exec.Command(dockerBinary, "run", "busybox", "sh", "-c", "ls -l /dev/null") |
| 1163 | 1177 |
out, _, err := runCommandWithOutput(cmd) |
| ... | ... |
@@ -168,7 +168,8 @@ type HostConfig struct {
|
| 168 | 168 |
CpusetCpus string // CpusetCpus 0-2, 0,1 |
| 169 | 169 |
CpusetMems string // CpusetMems 0-2, 0,1 |
| 170 | 170 |
CpuQuota int64 |
| 171 |
- OomKillDisable bool // Whether to disable OOM Killer or not |
|
| 171 |
+ BlkioWeight int64 // Block IO weight (relative weight vs. other containers) |
|
| 172 |
+ OomKillDisable bool // Whether to disable OOM Killer or not |
|
| 172 | 173 |
Privileged bool |
| 173 | 174 |
PortBindings nat.PortMap |
| 174 | 175 |
Links []string |
| ... | ... |
@@ -65,6 +65,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSe |
| 65 | 65 |
flCpusetCpus = cmd.String([]string{"#-cpuset", "-cpuset-cpus"}, "", "CPUs in which to allow execution (0-3, 0,1)")
|
| 66 | 66 |
flCpusetMems = cmd.String([]string{"-cpuset-mems"}, "", "MEMs in which to allow execution (0-3, 0,1)")
|
| 67 | 67 |
flCpuQuota = cmd.Int64([]string{"-cpu-quota"}, 0, "Limit the CPU CFS quota")
|
| 68 |
+ flBlkioWeight = cmd.Int64([]string{"-blkio-weight"}, 0, "Block IO (relative weight), between 10 and 1000")
|
|
| 68 | 69 |
flNetMode = cmd.String([]string{"-net"}, "bridge", "Set the Network mode for the container")
|
| 69 | 70 |
flMacAddress = cmd.String([]string{"-mac-address"}, "", "Container MAC address (e.g. 92:d0:c6:0a:29:33)")
|
| 70 | 71 |
flIpcMode = cmd.String([]string{"-ipc"}, "", "IPC namespace to use")
|
| ... | ... |
@@ -308,6 +309,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSe |
| 308 | 308 |
CpusetCpus: *flCpusetCpus, |
| 309 | 309 |
CpusetMems: *flCpusetMems, |
| 310 | 310 |
CpuQuota: *flCpuQuota, |
| 311 |
+ BlkioWeight: *flBlkioWeight, |
|
| 311 | 312 |
OomKillDisable: *flOomKillDisable, |
| 312 | 313 |
Privileged: *flPrivileged, |
| 313 | 314 |
PortBindings: portBindings, |