2

I'm trying to limit IO usage of a service (or process/command). (Limit for IO read/write on hardware device, not for network.)

I found IOAccounting from systemd:

systemd-run --scope --user -p "IOReadBandwidthMax=/dev/zero 1M" -p "IOAccounting=true" \
    time dd if=/dev/zero count=1 bs=100M of=/tmp/foo conv=fdatasync

systemd-run --scope --user -p "IOWriteBandwidthMax=/dev/sdd 1M" -p "IOAccounting=true"
time dd if=/dev/zero count=1 bs=100M of=/tmp/foo conv=fdatasync

The command ends quickly and report 200/300 MB/s. Exactly the same results when I run the command, without systemd-run wrapper.

I tried also to write the systemd service, without systemd-run: IO bandwidth limitation is not working.

Do you have any tips?

  • Thank you for the reponse. sudo made the trick. I failed also to limit read/write from or to a encrypted device. /tmp was in this case. – Richard Buchmann May 22 '22 at 20:24

1 Answers1

2

Running your test for system's systemd (root authentication required) shows that the IO limit is working, it takes 10 seconds:

systemd-run --scope -p IOWriteBandwidthMax='/dev/sda 10M' time dd if=/dev/zero count=1 bs=100M of=/tmp/foo conv=fdatasync

Running for user's systemd the limit is not working, because IO cannot be controlled by default by users. The Arch wiki has a useful bit for this:

https://wiki.archlinux.org/title/cgroups#As_unprivileged_user

There is a proposal to use delegation for a user service. Also for any process, the control groups can be used (like into this post) and again it is not directly available for user to control IO and set limits.

thanasisp
  • 8,122