Search code examples
linuxnixcgroupsbandwidth-throttling

Can't throttle IO on cgroup. Says "No such device" when device exists. What could be wrong?


Instructions I followed: https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v1/blkio-controller.html

Script I ran:

 
 BYTES_PER_SEC=1048576;
 
 MAJOR=259
 MINOR=1
 
 echo "device name:"
 udevadm info -rq name /sys/dev/block/$MAJOR:$MINOR
 echo ""
 echo "device numbers:"
 echo $MAJOR:$MINOR;
 echo ""
 
 sudo mount -t cgroup -o blkio none /sys/fs/cgroup/blkio;
 sudo echo "COMMAND TO BE EXECUTED:";
 sudo echo "$MAJOR:$MINOR  $BYTES_PER_SEC";
 sudo echo "$MAJOR:$MINOR  $BYTES_PER_SEC" > /sys/fs/cgroup/blkio/blkio.throttle.read_bps_device
 sudo echo "$MAJOR:$MINOR  $BYTES_PER_SEC" > /sys/fs/cgroup/blkio/blkio.throttle.write_bps_device

Output:

~/Desktop >>> sudo ./test.sh                                                                                                                                                                                   [1]
[sudo] password for brian: 
/dev/nvme0n1p1
device name: 259:1
mount: /sys/fs/cgroup/blkio: none already mounted on /sys/fs/bpf.
COMMAND TO BE EXECUTED:
259:1  1048576
echo: write error: No such device
echo: write error: No such device

Not sure what could be wrong. I'm also using NixOS here so not sure if that will actually effect the results.


Solution

  • The error occurs because the only way to throttle IO using cgroups version 1 is to use a device that is physical. The major and minor version numbers I used above are for a partition. You need to pick the major and minor numbers for the physical device that HOLDS the partition.