profile picture

Michael Stapelberg

systemd: modify IO scheduling (2012)

published 2012-09-23, last modified 2020-12-31
Edit Icon

One of the nice things about systemd is that you can change the Nice level and IO scheduling class/priority in a very simple way. I have recently configured bacula-fd on my server in such a way that it will not put a lot of load on the machine:

To override the service unit, in this case bacula-fd.service, run:

$ sudo systemctl edit bacula-fd.service

And add these lines:

[Service]
Nice=10
IOSchedulingClass=best-effort
IOSchedulingPriority=7

To verify the current unit configuration you can use systemctl cat:

$ sudo systemctl cat bacula-fd.service
# /lib/systemd/system/bacula-fd.service
# Systemd Bacula service file
...here you can see the base configuration provided by the package...

# /etc/systemd/system/bacula-fd.service.d/override.conf
[Service]
Nice=10
IOSchedulingClass=best-effort
IOSchedulingPriority=7

Note that this created a separate file to avoid touching the original one.
Now you can enable and start the unit as you usually would:

$ sudo systemctl enable --now bacula-fd.service

And that’s it. See nice(1) and ionice(1) for the possible values. Of course, these attributes are passed on to child processs:

USER       PID PRI  NI %CPU %MEM COMMAND
root      3522  30  10  0.0  0.0 /usr/sbin/bacula-fd -u root -g root -c /etc/bacula/bacula-fd.conf
root     23380  30  10  0.0  0.0  \_ /bin/sh /root/bin/xen-lvm-snapshot/foreach-domu.sh mount
root     23607  30  10  0.0  0.0      \_ /bin/sh /root/bin/xen-lvm-snapshot/mount-snapshot.sh plana/domu-web
root     23665  30  10  0.0  0.0          \_ /sbin/fsck.ext3 -y /dev/loop3

PS: If you wanted, you can revert the the changes with:

$ sudo systemctl revert bacula-fd.service

I run a blog since 2005, spreading knowledge and experience for almost 20 years! :)

If you want to support my work, you can buy me a coffee.

Thank you for your support! ❤️