Ubuntu has ionice
, but as far as I can tell, it does absolutely nothing.
I suspect this is because Ubuntu replaced cfq with deadline and deadline doesn't support priorities.
Is there any possible way to have prioritized I/O on Ubuntu anymore?
EDIT: The context is that I have a database restore that easily consumes all my I/O and renders my system unusable until it has finished. I'd like it to remain usable for other tasks.
You have to change your scheduler from
deadline
tocfq
.You can do that per blockdevice and non permanent via
Or for the whole system, permanent via
grub
, with adding theelevator=cfq
parameter to the grub commandline options.This is an excellent post explaining how you can do that.
What the drawbacks of such a change are is better covered elsewhere.
The TL;DR is
This answer might be helpfull for Ubuntu 20.04, which lacks the cfq scheduler: https://askubuntu.com/a/1350605
From that answer:
Ubuntu 20.04 is using Kernel 5.4 (with HWE: 5.8) with only the
mq-deadline
scheduler compiled in.You can check it by viewing
/sys/block/sda/queue/scheduler
. The active scheduler has square brackets around. If there are other schedulers compiled in the kernel they are also shown.Example:
The
mq-deadline
scheduler does not support the mechanism used byionice
at the moment, see: https://unix.stackexchange.com/a/160081/27458Solution: Switch to BFQ scheduler
The
bfq
scheduler does not need to be compiled in the kernel, it can be loaded afterwards using a kernel module.Switch to the BFQ scheduler:
Check:
It is probably a good idea to also do a reboot and check again.
BFQ not available on "virtual" kernel
If you are using a "virtual" kernel, you will probably not have the
bfq
kernel module available because it does not include thelinux-modules-extra-5.xxx
package.You can solve this by switching to the "generic-HWE" kernel:
After reboot you should be on kernel
5.8.0-xxx-generic
. You can check this:Now you can apply the above solution.
Alternative solution: Systemd scope
If you don't want to switch the IO scheduler, you can use a Systemd scope with a lower IO weight.
Create a file
/usr/local/bin/mh_ionice
with contents:Make it executable:
Now you can run: