Why is my cgroup write throughput not limited?

Viewed 244

I am trying to set upper write throughput limit per cgroup via blkio cgroup controller.

I have tried it like this:

echo "major:minor 10485760" > /sys/fs/cgroup/blkio/docker/XXXXX/blkio.throttle.write_bps_device

This should limit throughput to 10 MBps. However tool, that's monitoring servers disk, reports this behaviour.

Write bytes per second

I thought that, the line should hold somewhere around 10M. Can somebody explain this behaviour to me and maybe propose a better way to limit throughput?

1 Answers

Are you sure that the major/minor numbers that you specified in the command line are correct? Moreover, as you are running in docker, the limitation is for the processes running in the docker container not for the processes running outside. So, you need to check from where the information taken by the monitoring tool come from (does it take numbers for all the processes inside and outside the container or only for the processes inside the container?).

To check the setting, the Linux documentation provides an example with the dd command and a device limited to 1MB/second on reads. You can try the same with a limit on the writes to see if the monitoring tool is coherent with the output of dd. Make the latter run in the container.

For example, my home directory is located on /dev/sdb2:

$ df
Filesystem      1K-blocks      Used  Available Use% Mounted on
[...]
/dev/sdb2      2760183720 494494352 2125409664  19% /home
[...]
$ ls -l /dev/sdb*
brw-rw---- 1 root disk 8, 16 mars  14 08:14 /dev/sdb
brw-rw---- 1 root disk 8, 17 mars  14 08:14 /dev/sdb1
brw-rw---- 1 root disk 8, 18 mars  14 08:14 /dev/sdb2

I check the speed of the writing in a file:

$ dd oflag=direct if=/dev/zero of=$HOME/file bs=4K count=1024
1024+0 records in
1024+0 records out
4194304 bytes (4,2 MB, 4,0 MiB) copied, 0,131559 s, 31,9 MB/s

I set the 1MB/s write limit on the whole disk (8:16) as it does not work on individual partitions (8:18) on which my home directory resides:

# echo "8:16 1048576" > /sys/fs/cgroup/blkio/blkio.throttle.write_bps_device
# cat /sys/fs/cgroup/blkio/blkio.throttle.write_bps_device
8:16 1048576

dd's output confirms the limitation of the I/O throughput to 1 MB/s:

$ dd oflag=direct if=/dev/zero of=$HOME/file bs=4K count=1024
1024+0 records in
1024+0 records out
4194304 bytes (4,2 MB, 4,0 MiB) copied, 4,10811 s, 1,0 MB/s

So, it is possible to make the same in a container.

Related