Reputation: 333
I'm trying to control I/O bandwidth by using cgroup blkio controller.
Cgroup has been setup and mounted successfully, i.e. calling grep cgroup /proc/mounts
returns:
....
cgroup /sys/fs/cgroup/blkio cgroup rw,relatime,blkio 0 0
...
I then make a new folder in the blkio
folder and write to the file blkio.throttle.read_bps_device
, as follows:
1. mkdir user1; cd user1
2. echo "8:5 10485760" > blkio.throtlle.read_bps_device
----> echo: write error: Invalid argument
My device major:minor number is correct from using df -h
and ls -l /dev/sda5
for the storage device.
And I can still write to file that requires no device major:minor number, such as blkio.weight
(but the same error is thrown for blkio.weigth_device
)
Any idea why I got that error?
Upvotes: 3
Views: 4724
Reputation: 6768
Not sure which flavour/version of Linux you are using, on RHEL 6.x kernels, this was did not work for some reason, however it worked when I compiled on a custom kernel on RHEL and on other Fedora versions without any issues.
To check if supported on your kernel, run lssubsys -am | grep blkio
. Check the path if you can file the file blkio.throttle.read_bps_device
However, here is an example of how you can do it persistently, set a cgroups to limit the program not to exceed more than 1 Mibi/s:
/proc/partitions
`cat /proc/partitions | grep vda` major minor #blocks name 252 0 12582912 vda --> this is the primary disk (with MAJOR:MINOR -> 8:0)
Now if you want to limit your program to 1mib/s (convert the value to bytes/s) as follows. => 1MiB/s => 1024 kiB/1MiB * 1024 B/s = 1048576 Bytes/sec
Edit /etc/cgconfig.conf and add the following entry
group ioload { blkio.throttle.read_bps_device = "252:0 1048576" } }
*: blkio ioload
`chkconfig {cgred,cgconfig} on;` `service {cgred,cgconfig} restart`
Refer: blkio-controller.txt
hope this helps!
Upvotes: 6