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:
# cat /sys/block/sda/queue/scheduler
[mq-deadline] none
uname -r
5.4.0-26-generic
The mq-deadline
scheduler does not support the mechanism used by ionice
at the moment, see: https://unix.stackexchange.com/a/160081/27458
Solution: 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:
# modprobe "bfq"
# echo "bfq" > /sys/block/sda/queue/scheduler
# echo "bfq" > /etc/modules-load.d/bfq.conf
# echo 'ACTION=="add|change", KERNEL=="sd*[!0-9]|sr*", ATTR{queue/scheduler}="bfq"' > /etc/udev/rules.d/60-scheduler.rules
Check:
# cat /sys/block/sda/queue/scheduler
mq-deadline [bfq] none
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 the linux-modules-extra-5.xxx
package.
You can solve this by switching to the "generic-HWE" kernel:
# sudo apt-get install linux-generic-hwe-20.04 linux-tools-generic-hwe-20.04
# reboot
After reboot you should be on kernel 5.8.0-xxx-generic
. You can check this:
# uname -r
5.8.0-59-generic
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:
#!/bin/bash
if (( EUID == 0 )); then USERMODE=''; else USERMODE='--user'; fi
systemd-run \
--collect \
--quiet \
--scope \
$USERMODE \
--nice=19 \
--property="IOAccounting=yes" \
--property="IOWeight=1" \
"$@"
Make it executable:
chmod 755 /usr/local/bin/mh_ionice
Now you can run:
mh_ionice [heavy_command] [arg] [arg] [arg]
ionice -c idle myprocess
? Could you describe the steps and your hadware (inxi -SMD -! 31 -y 80
)?iotop
while running? – Pablo Bianchi Feb 06 '20 at 05:17sudo echo cfq > /sys/block/<blockdevice>/queue/scheduler
for an immediate change or for a more permanent one, addelevator=cfq
to your grub cmd_line. AFAIK cfq is the only scheduler that supports io priorities. – Robert Riedl Feb 06 '20 at 11:01