1- Block IO Controller
2- ===================
1+ ===================
2+ Block IO Controller
3+ ===================
4+
35Overview
46========
57cgroup subsys "blkio" implements the block io controller. There seems to be
@@ -22,28 +24,35 @@ Proportional Weight division of bandwidth
2224You can do a very simple testing of running two dd threads in two different
2325cgroups. Here is what you can do.
2426
25- - Enable Block IO controller
27+ - Enable Block IO controller::
28+
2629 CONFIG_BLK_CGROUP=y
2730
28- - Enable group scheduling in CFQ
31+ - Enable group scheduling in CFQ:
32+
33+
2934 CONFIG_CFQ_GROUP_IOSCHED=y
3035
3136- Compile and boot into kernel and mount IO controller (blkio); see
3237 cgroups.txt, Why are cgroups needed?.
3338
39+ ::
40+
3441 mount -t tmpfs cgroup_root /sys/fs/cgroup
3542 mkdir /sys/fs/cgroup/blkio
3643 mount -t cgroup -o blkio none /sys/fs/cgroup/blkio
3744
38- - Create two cgroups
45+ - Create two cgroups::
46+
3947 mkdir -p /sys/fs/cgroup/blkio/test1/ /sys/fs/cgroup/blkio/test2
4048
41- - Set weights of group test1 and test2
49+ - Set weights of group test1 and test2::
50+
4251 echo 1000 > /sys/fs/cgroup/blkio/test1/blkio.weight
4352 echo 500 > /sys/fs/cgroup/blkio/test2/blkio.weight
4453
4554- Create two same size files (say 512MB each) on same disk (file1, file2) and
46- launch two dd threads in different cgroup to read those files.
55+ launch two dd threads in different cgroup to read those files::
4756
4857 sync
4958 echo 3 > /proc/sys/vm/drop_caches
@@ -65,24 +74,27 @@ cgroups. Here is what you can do.
6574
6675Throttling/Upper Limit policy
6776-----------------------------
68- - Enable Block IO controller
77+ - Enable Block IO controller::
78+
6979 CONFIG_BLK_CGROUP=y
7080
71- - Enable throttling in block layer
81+ - Enable throttling in block layer::
82+
7283 CONFIG_BLK_DEV_THROTTLING=y
7384
74- - Mount blkio controller (see cgroups.txt, Why are cgroups needed?)
85+ - Mount blkio controller (see cgroups.txt, Why are cgroups needed?)::
86+
7587 mount -t cgroup -o blkio none /sys/fs/cgroup/blkio
7688
7789- Specify a bandwidth rate on particular device for root group. The format
78- for policy is "<major>:<minor> <bytes_per_second>".
90+ for policy is "<major>:<minor> <bytes_per_second>"::
7991
8092 echo "8:16 1048576" > /sys/fs/cgroup/blkio/blkio.throttle.read_bps_device
8193
8294 Above will put a limit of 1MB/second on reads happening for root group
8395 on device having major/minor number 8:16.
8496
85- - Run dd to read a file and see if rate is throttled to 1MB/s or not.
97+ - Run dd to read a file and see if rate is throttled to 1MB/s or not::
8698
8799 # dd iflag=direct if=/mnt/common/zerofile of=/dev/null bs=4K count=1024
88100 1024+0 records in
@@ -99,7 +111,7 @@ throttling's hierarchy support is enabled iff "sane_behavior" is
99111enabled from cgroup side, which currently is a development option and
100112not publicly available.
101113
102- If somebody created a hierarchy like as follows.
114+ If somebody created a hierarchy like as follows::
103115
104116 root
105117 / \
@@ -115,7 +127,7 @@ directly generated by tasks in that cgroup.
115127
116128Throttling without "sane_behavior" enabled from cgroup side will
117129practically treat all groups at same level as if it looks like the
118- following.
130+ following::
119131
120132 pivot
121133 / / \ \
@@ -152,27 +164,31 @@ Proportional weight policy files
152164 These rules override the default value of group weight as specified
153165 by blkio.weight.
154166
155- Following is the format.
167+ Following is the format::
168+
169+ # echo dev_maj:dev_minor weight > blkio.weight_device
170+
171+ Configure weight=300 on /dev/sdb (8:16) in this cgroup::
172+
173+ # echo 8:16 300 > blkio.weight_device
174+ # cat blkio.weight_device
175+ dev weight
176+ 8:16 300
177+
178+ Configure weight=500 on /dev/sda (8:0) in this cgroup::
156179
157- # echo dev_maj:dev_minor weight > blkio.weight_device
158- Configure weight=300 on /dev/sdb (8:16) in this cgroup
159- # echo 8:16 300 > blkio.weight_device
160- # cat blkio.weight_device
161- dev weight
162- 8:16 300
180+ # echo 8:0 500 > blkio.weight_device
181+ # cat blkio.weight_device
182+ dev weight
183+ 8:0 500
184+ 8:16 300
163185
164- Configure weight=500 on /dev/sda (8:0) in this cgroup
165- # echo 8:0 500 > blkio.weight_device
166- # cat blkio.weight_device
167- dev weight
168- 8:0 500
169- 8:16 300
186+ Remove specific weight for /dev/sda in this cgroup::
170187
171- Remove specific weight for /dev/sda in this cgroup
172- # echo 8:0 0 > blkio.weight_device
173- # cat blkio.weight_device
174- dev weight
175- 8:16 300
188+ # echo 8:0 0 > blkio.weight_device
189+ # cat blkio.weight_device
190+ dev weight
191+ 8:16 300
176192
177193- blkio.leaf_weight[_device]
178194 - Equivalents of blkio.weight[_device] for the purpose of
@@ -297,30 +313,30 @@ Throttling/Upper limit policy files
297313- blkio.throttle.read_bps_device
298314 - Specifies upper limit on READ rate from the device. IO rate is
299315 specified in bytes per second. Rules are per device. Following is
300- the format.
316+ the format::
301317
302- echo "<major>:<minor> <rate_bytes_per_second>" > /cgrp/blkio.throttle.read_bps_device
318+ echo "<major>:<minor> <rate_bytes_per_second>" > /cgrp/blkio.throttle.read_bps_device
303319
304320- blkio.throttle.write_bps_device
305321 - Specifies upper limit on WRITE rate to the device. IO rate is
306322 specified in bytes per second. Rules are per device. Following is
307- the format.
323+ the format::
308324
309- echo "<major>:<minor> <rate_bytes_per_second>" > /cgrp/blkio.throttle.write_bps_device
325+ echo "<major>:<minor> <rate_bytes_per_second>" > /cgrp/blkio.throttle.write_bps_device
310326
311327- blkio.throttle.read_iops_device
312328 - Specifies upper limit on READ rate from the device. IO rate is
313329 specified in IO per second. Rules are per device. Following is
314- the format.
330+ the format::
315331
316- echo "<major>:<minor> <rate_io_per_second>" > /cgrp/blkio.throttle.read_iops_device
332+ echo "<major>:<minor> <rate_io_per_second>" > /cgrp/blkio.throttle.read_iops_device
317333
318334- blkio.throttle.write_iops_device
319335 - Specifies upper limit on WRITE rate to the device. IO rate is
320336 specified in io per second. Rules are per device. Following is
321- the format.
337+ the format::
322338
323- echo "<major>:<minor> <rate_io_per_second>" > /cgrp/blkio.throttle.write_iops_device
339+ echo "<major>:<minor> <rate_io_per_second>" > /cgrp/blkio.throttle.write_iops_device
324340
325341Note: If both BW and IOPS rules are specified for a device, then IO is
326342 subjected to both the constraints.
0 commit comments