How to enable the BFQ I/O scheduler on kernel >=4.12


(Luca Giambonini) #1

The kernel 4.12 introduces the BFQ scheduler.

The BFQ (Budget Fair Queue) has been developed in the last few years and only recently included in the mainline kernel. Some distributions already included this by manually patching the kernel, and there was a PPA available for Ubuntu as well. However, we now get this available to all!

In a nutshell: this is a I/O scheduler that balances how the system accesses data on a drive (HDD, SSD, etc.). BFQ targets desktop users by ensuring that at no point a single application is using all of the bandwidth. Sometimes when copying large files in Linux a user sees the system slow down down or freeze completely – this will now be a thing of the past! (source)

BFQ is available in Linux 4.12 but is not enabled by default. To enable blk-mq at boot time, edit your /etc/default/grub file and add scsi_mod.use_blk_mq=1 to your GRUB_CMDLINE_LINUX like this:

GRUB_CMDLINE_LINUX="scsi_mod.use_blk_mq=1 quiet"

After that, you must update your grub with:

sudo update-grub

Create /etc/udev/rules.d/60-scheduler.rules if it did not exist and add:

# set deadline scheduler for non-rotating disks
ACTION=="add|change", KERNEL=="sd[a-z]", TEST!="queue/rotational", ATTR{queue/scheduler}="deadline"
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="bfq"

# set cfq scheduler for rotating disks
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="1", ATTR{queue/scheduler}="cfq"

Save it, and reload and trigger udev rules:

sudo udevadm control --reload
sudo udevadm trigger

Now you can reboot and then check if btq is running:

sudo cat /sys/block/sda/queue/scheduler
mq-deadline kyber [bfq] none

It is important to note that enabling blk_mq turn it impossible to use non blk_mq schedulers, so you will lose noop cfq and the non mq deadline.

About to build a new rig x370, ryzen 7 1700
Linux-zen; have you ever tested a different kernel then the default kernel?
Linux kernel 4.19 with ck patch enabled
(Neofytos Kolokotronis) #2

Oh this is interesting news, BFQ took a while but it finally landed in the main kernel!

Once we gather enough feedback we can decide if we want to ship it by default on Chakra.

Btw, to everyone reading, this will be included in an upcoming update of the kernel group, so it’s not available yet.

(tom) #3

a udev rule is much effort for changing the scheduler^^
i do this task with elevator= in the kcmd or with systemd-tmpfiles

GRUB_CMDLINE_LINUX="elevator=bfq quiet"

w /sys/block/sda/queue/scheduler - - - -  bfg 

there are some changes to the older kernel it seems because with blk_mq was only

i found this article about the scheduler

(Luca Giambonini) #4

yes true @brikler, but I read that the elevator does not always work in grub, and with udev you can tune more precisely the settings.

(tom) #5

indeed the elevator doesn’t work with blk_mq i had tested yesterday.
your udev rule is very much effort for changing the scheduler in my opinion because the user know if there is a ssd or not but anyway your udev rule is easy to tweak

there are some opportunity to set the scheduler at boot or run time.

some infos about I/O scheduler can be found here:

(Luca Giambonini) #6

My personal notes:
I tested BFQ for the last week and I didn’t notified any performance improvement, but instead, I had several kernel “hang” when compiling big packages (like the kernel). Reverting to the standard scheduler solved the problem.
I don’t know if is related to the kernel 4.12.1 or attributabe to the BFQ, for that reason I build a newer version 4.12.4 and I will check during the next week if the hang again.

(tom) #7

i never had problems with bfq but what for a bfq had you used? blk_mq or on a hdd?
do you compile in a tmpfs? if you compile in tmpfs this isn’t “expensive” enough to notice i suppose

(Alexander Waldemar Ahjolinna) #11

the little testing I have done with my ultrabook, and I haven’t notice any problems with the 4.12.x kernel …yet. And my Arch desktop has both 4.12.x kernel (using bfq) and the ck-kernel (4.11.x) where I need to build few big aur pkgs like ffmpeg-full I have never notice any issues

@AlmAck: apparently this is planned for 4.13:

a side note: manjaro had some issues with making bfq default in 4.12 (…manjaro as been using bfq by default way before 4.12) as workaround solution was “bfq@.service” file

apparently this udev rule should work also (to make bfq default):

ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/scheduler}="bfq"

“In order to enable blk-mq subsystem the kernel has to be configured with option CONFIG_SCSI_MQ_DEFAULT=y or pass parameter scsi_mod.use_blk_mq=1 in boot loader.”

source is from the ck-kernel’s AUR comment section …which also has/had problems with making bfq default with 4.12.

(Luca Giambonini) #12

Thanks for the inputs @ahjolinna
Following my initial post I was able to set bfq as default, the bfq@.service is for sure an other option.
When Linus releases bfq as default schedule we will follow the upstream decision and build the kernel with that scheduler, but until now, if the performance difference is not huge we will stay with the cfq.

(Alexander Waldemar Ahjolinna) #13

@AlmAck: bfq is designed mainly for desktop usage so I highly doubt we ever see it as default scheduler when the Linux kernel is not desktop only kernel!

and as chakraOS is a desktop only distro it would make common sense that configurations would lean towards stuff that benefits desktop over other platform…but this is just me

(Luca Giambonini) #14

I agree with you, chakra is a desktop distro and we should provide the best experience to our users. I would like to make some more tests, and have some other feedback from our @testers team.

(kepszlok) #15

I have 2 Chakra installed on the same ssd so i can compare schedulers. Just give me some simple how-to about BFQ.

(tom) #16

as root at run time:

echo bfq > /sys/block/sda/queue/scheduler

or every boot with systemd-tmpfiles
create in /etc/tmpfiles.d/bfq.conf

w /sys/block/sd*/queue/scheduler - - - - bfq

definitive the best experience deliver kernel with the ck patch set…

(kepszlok) #17

Hmm, there are no BFQ scheduler in my system.

echo bfq > /sys/block/sda/queue/scheduler
-bash: echo: write error: Invalid argument

cat /sys/block/sda/queue/scheduler
noop deadline [cfq]

How can i get BFQ? I’m on testing repo.

(Neofytos Kolokotronis) #18

Hey, make sure to check the instructions on the first post of this thread.

(tom) #19

do so but only with ssd because hdd can’t handle multi queue

(kepszlok) #21

I did, but it’s not doing anything.

My cmdline:
GRUB_CMDLINE_LINUX_DEFAULT=‘quiet splash=silent logo.nologo acpi_osi=Linux video.use_native_backlibacklight=1 audit=0 scsi_mod.use_blk_mq=1’

After update-grub and reboot, i still only get the basic ones. noop deadline [cfq], using this kernel:
4.12.4-1-CHAKRA #1 SMP PREEMPT Tue Aug 1 18:19:44 CEST 2017 x86_64 GNU/Linux

(tom) #22

with linux 4.12-4 and after reboot?
please check your kernel commandline

cat /proc/cmdline
[tom@frija ~]$ uname -r
[tom@frija ~]$ cat /proc/cmdline 
initrd=/initramfs-linux.img  root=/dev/sda2  rw quiet config_scsi_mq_default=y scsi_mod.use_blk_mq=1  resume=/dev/sda4
[tom@frija ~]$ cat /sys/block/sda/queue/scheduler 
mq-deadline kyber [bfq] none

(kepszlok) #23

Yes, with 4.12-4 + reboot.

Something is quite odd here:

cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-linux root=UUID=8ac38f81-6f87-4ffd-9626-9352a60b8ac5 rw quiet resume=UUID=578f2ca5-2c3b-482b-adbe-23d4cae759a2

My /etc/default/grub file got ignored?

(tom) #24

please try and check /boot/grub/grub.cfg

sudo grub-mkconfig -o /boot/grub/grub.cfg

btw you can edit /boot/grub/grub.cfg

sudoedit /boot/grub/grub.cfg