Controlling blkio usage(systemd)

Controlling blkio usage(systemd)

Setting a blkio limit for a user #

  1. using iotop

    sudo iotop -o
    
  2. create 10GB file

    dd if=/dev/zero of=afile bs=1M count=10000
    

    copy this file to the /dev/null

    dd if=afile of=/dev/null
    

    check iotop

  3. limit read bandwidth ot only one MB per second

    sudo systemctl set-property user-1001.slice BlockIOReadBandwidth="/dev/sda 1M"
    
  4. do a daemon-reload

    sudo systemctl daemon-reload
    
  5. check cgroup filesystem

    cat /sys/fs/cgroup/blkio/user.slice/user-1001.slice/blkio.throttle.read_bps_device
    8:0 1000000
    

    the “8:0” represents the jamor and minor numbers of the /dev/sda device:

    ls -l /dev/sda
    

Setting a blkio limit for a service #

sudo systemctl set-property apache2.service BlockIOReadBandwidth="/dev/sda 1M"

When you set this property on the command line, you had to surround the /dev/sda 1M part with a pair fo double quotes. When you set this in a service file, you do not surround the /dev/sda 1M within double quotes.

man systemd.resource-control