]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - Documentation/cgroup-v1/blkio-controller.txt
Merge tag 'gfs2-v5.2.fixes2' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2...
[mirror_ubuntu-jammy-kernel.git] / Documentation / cgroup-v1 / blkio-controller.txt
1 Block IO Controller
2 ===================
3 Overview
4 ========
5 cgroup subsys "blkio" implements the block io controller. There seems to be
6 a need of various kinds of IO control policies (like proportional BW, max BW)
7 both at leaf nodes as well as at intermediate nodes in a storage hierarchy.
8 Plan is to use the same cgroup based management interface for blkio controller
9 and based on user options switch IO policies in the background.
10
11 One IO control policy is throttling policy which can be used to
12 specify upper IO rate limits on devices. This policy is implemented in
13 generic block layer and can be used on leaf nodes as well as higher
14 level logical devices like device mapper.
15
16 HOWTO
17 =====
18 Throttling/Upper Limit policy
19 -----------------------------
20 - Enable Block IO controller
21 CONFIG_BLK_CGROUP=y
22
23 - Enable throttling in block layer
24 CONFIG_BLK_DEV_THROTTLING=y
25
26 - Mount blkio controller (see cgroups.txt, Why are cgroups needed?)
27 mount -t cgroup -o blkio none /sys/fs/cgroup/blkio
28
29 - Specify a bandwidth rate on particular device for root group. The format
30 for policy is "<major>:<minor> <bytes_per_second>".
31
32 echo "8:16 1048576" > /sys/fs/cgroup/blkio/blkio.throttle.read_bps_device
33
34 Above will put a limit of 1MB/second on reads happening for root group
35 on device having major/minor number 8:16.
36
37 - Run dd to read a file and see if rate is throttled to 1MB/s or not.
38
39 # dd iflag=direct if=/mnt/common/zerofile of=/dev/null bs=4K count=1024
40 1024+0 records in
41 1024+0 records out
42 4194304 bytes (4.2 MB) copied, 4.0001 s, 1.0 MB/s
43
44 Limits for writes can be put using blkio.throttle.write_bps_device file.
45
46 Hierarchical Cgroups
47 ====================
48
49 Throttling implements hierarchy support; however,
50 throttling's hierarchy support is enabled iff "sane_behavior" is
51 enabled from cgroup side, which currently is a development option and
52 not publicly available.
53
54 If somebody created a hierarchy like as follows.
55
56 root
57 / \
58 test1 test2
59 |
60 test3
61
62 Throttling with "sane_behavior" will handle the
63 hierarchy correctly. For throttling, all limits apply
64 to the whole subtree while all statistics are local to the IOs
65 directly generated by tasks in that cgroup.
66
67 Throttling without "sane_behavior" enabled from cgroup side will
68 practically treat all groups at same level as if it looks like the
69 following.
70
71 pivot
72 / / \ \
73 root test1 test2 test3
74
75 Various user visible config options
76 ===================================
77 CONFIG_BLK_CGROUP
78 - Block IO controller.
79
80 CONFIG_DEBUG_BLK_CGROUP
81 - Debug help. Right now some additional stats file show up in cgroup
82 if this option is enabled.
83
84 CONFIG_BLK_DEV_THROTTLING
85 - Enable block device throttling support in block layer.
86
87 Details of cgroup files
88 =======================
89 Proportional weight policy files
90 --------------------------------
91 - blkio.weight
92 - Specifies per cgroup weight. This is default weight of the group
93 on all the devices until and unless overridden by per device rule.
94 (See blkio.weight_device).
95 Currently allowed range of weights is from 10 to 1000.
96
97 - blkio.weight_device
98 - One can specify per cgroup per device rules using this interface.
99 These rules override the default value of group weight as specified
100 by blkio.weight.
101
102 Following is the format.
103
104 # echo dev_maj:dev_minor weight > blkio.weight_device
105 Configure weight=300 on /dev/sdb (8:16) in this cgroup
106 # echo 8:16 300 > blkio.weight_device
107 # cat blkio.weight_device
108 dev weight
109 8:16 300
110
111 Configure weight=500 on /dev/sda (8:0) in this cgroup
112 # echo 8:0 500 > blkio.weight_device
113 # cat blkio.weight_device
114 dev weight
115 8:0 500
116 8:16 300
117
118 Remove specific weight for /dev/sda in this cgroup
119 # echo 8:0 0 > blkio.weight_device
120 # cat blkio.weight_device
121 dev weight
122 8:16 300
123
124 - blkio.leaf_weight[_device]
125 - Equivalents of blkio.weight[_device] for the purpose of
126 deciding how much weight tasks in the given cgroup has while
127 competing with the cgroup's child cgroups. For details,
128 please refer to Documentation/block/cfq-iosched.txt.
129
130 - blkio.time
131 - disk time allocated to cgroup per device in milliseconds. First
132 two fields specify the major and minor number of the device and
133 third field specifies the disk time allocated to group in
134 milliseconds.
135
136 - blkio.sectors
137 - number of sectors transferred to/from disk by the group. First
138 two fields specify the major and minor number of the device and
139 third field specifies the number of sectors transferred by the
140 group to/from the device.
141
142 - blkio.io_service_bytes
143 - Number of bytes transferred to/from the disk by the group. These
144 are further divided by the type of operation - read or write, sync
145 or async. First two fields specify the major and minor number of the
146 device, third field specifies the operation type and the fourth field
147 specifies the number of bytes.
148
149 - blkio.io_serviced
150 - Number of IOs (bio) issued to the disk by the group. These
151 are further divided by the type of operation - read or write, sync
152 or async. First two fields specify the major and minor number of the
153 device, third field specifies the operation type and the fourth field
154 specifies the number of IOs.
155
156 - blkio.io_service_time
157 - Total amount of time between request dispatch and request completion
158 for the IOs done by this cgroup. This is in nanoseconds to make it
159 meaningful for flash devices too. For devices with queue depth of 1,
160 this time represents the actual service time. When queue_depth > 1,
161 that is no longer true as requests may be served out of order. This
162 may cause the service time for a given IO to include the service time
163 of multiple IOs when served out of order which may result in total
164 io_service_time > actual time elapsed. This time is further divided by
165 the type of operation - read or write, sync or async. First two fields
166 specify the major and minor number of the device, third field
167 specifies the operation type and the fourth field specifies the
168 io_service_time in ns.
169
170 - blkio.io_wait_time
171 - Total amount of time the IOs for this cgroup spent waiting in the
172 scheduler queues for service. This can be greater than the total time
173 elapsed since it is cumulative io_wait_time for all IOs. It is not a
174 measure of total time the cgroup spent waiting but rather a measure of
175 the wait_time for its individual IOs. For devices with queue_depth > 1
176 this metric does not include the time spent waiting for service once
177 the IO is dispatched to the device but till it actually gets serviced
178 (there might be a time lag here due to re-ordering of requests by the
179 device). This is in nanoseconds to make it meaningful for flash
180 devices too. This time is further divided by the type of operation -
181 read or write, sync or async. First two fields specify the major and
182 minor number of the device, third field specifies the operation type
183 and the fourth field specifies the io_wait_time in ns.
184
185 - blkio.io_merged
186 - Total number of bios/requests merged into requests belonging to this
187 cgroup. This is further divided by the type of operation - read or
188 write, sync or async.
189
190 - blkio.io_queued
191 - Total number of requests queued up at any given instant for this
192 cgroup. This is further divided by the type of operation - read or
193 write, sync or async.
194
195 - blkio.avg_queue_size
196 - Debugging aid only enabled if CONFIG_DEBUG_BLK_CGROUP=y.
197 The average queue size for this cgroup over the entire time of this
198 cgroup's existence. Queue size samples are taken each time one of the
199 queues of this cgroup gets a timeslice.
200
201 - blkio.group_wait_time
202 - Debugging aid only enabled if CONFIG_DEBUG_BLK_CGROUP=y.
203 This is the amount of time the cgroup had to wait since it became busy
204 (i.e., went from 0 to 1 request queued) to get a timeslice for one of
205 its queues. This is different from the io_wait_time which is the
206 cumulative total of the amount of time spent by each IO in that cgroup
207 waiting in the scheduler queue. This is in nanoseconds. If this is
208 read when the cgroup is in a waiting (for timeslice) state, the stat
209 will only report the group_wait_time accumulated till the last time it
210 got a timeslice and will not include the current delta.
211
212 - blkio.empty_time
213 - Debugging aid only enabled if CONFIG_DEBUG_BLK_CGROUP=y.
214 This is the amount of time a cgroup spends without any pending
215 requests when not being served, i.e., it does not include any time
216 spent idling for one of the queues of the cgroup. This is in
217 nanoseconds. If this is read when the cgroup is in an empty state,
218 the stat will only report the empty_time accumulated till the last
219 time it had a pending request and will not include the current delta.
220
221 - blkio.idle_time
222 - Debugging aid only enabled if CONFIG_DEBUG_BLK_CGROUP=y.
223 This is the amount of time spent by the IO scheduler idling for a
224 given cgroup in anticipation of a better request than the existing ones
225 from other queues/cgroups. This is in nanoseconds. If this is read
226 when the cgroup is in an idling state, the stat will only report the
227 idle_time accumulated till the last idle period and will not include
228 the current delta.
229
230 - blkio.dequeue
231 - Debugging aid only enabled if CONFIG_DEBUG_BLK_CGROUP=y. This
232 gives the statistics about how many a times a group was dequeued
233 from service tree of the device. First two fields specify the major
234 and minor number of the device and third field specifies the number
235 of times a group was dequeued from a particular device.
236
237 - blkio.*_recursive
238 - Recursive version of various stats. These files show the
239 same information as their non-recursive counterparts but
240 include stats from all the descendant cgroups.
241
242 Throttling/Upper limit policy files
243 -----------------------------------
244 - blkio.throttle.read_bps_device
245 - Specifies upper limit on READ rate from the device. IO rate is
246 specified in bytes per second. Rules are per device. Following is
247 the format.
248
249 echo "<major>:<minor> <rate_bytes_per_second>" > /cgrp/blkio.throttle.read_bps_device
250
251 - blkio.throttle.write_bps_device
252 - Specifies upper limit on WRITE rate to the device. IO rate is
253 specified in bytes per second. Rules are per device. Following is
254 the format.
255
256 echo "<major>:<minor> <rate_bytes_per_second>" > /cgrp/blkio.throttle.write_bps_device
257
258 - blkio.throttle.read_iops_device
259 - Specifies upper limit on READ rate from the device. IO rate is
260 specified in IO per second. Rules are per device. Following is
261 the format.
262
263 echo "<major>:<minor> <rate_io_per_second>" > /cgrp/blkio.throttle.read_iops_device
264
265 - blkio.throttle.write_iops_device
266 - Specifies upper limit on WRITE rate to the device. IO rate is
267 specified in io per second. Rules are per device. Following is
268 the format.
269
270 echo "<major>:<minor> <rate_io_per_second>" > /cgrp/blkio.throttle.write_iops_device
271
272 Note: If both BW and IOPS rules are specified for a device, then IO is
273 subjected to both the constraints.
274
275 - blkio.throttle.io_serviced
276 - Number of IOs (bio) issued to the disk by the group. These
277 are further divided by the type of operation - read or write, sync
278 or async. First two fields specify the major and minor number of the
279 device, third field specifies the operation type and the fourth field
280 specifies the number of IOs.
281
282 - blkio.throttle.io_service_bytes
283 - Number of bytes transferred to/from the disk by the group. These
284 are further divided by the type of operation - read or write, sync
285 or async. First two fields specify the major and minor number of the
286 device, third field specifies the operation type and the fourth field
287 specifies the number of bytes.
288
289 Common files among various policies
290 -----------------------------------
291 - blkio.reset_stats
292 - Writing an int to this file will result in resetting all the stats
293 for that cgroup.