Kernel: Change to BFQ I/O Scheduler Without Patches

Forum Forums General Tips and Tricks Kernel: Change to BFQ I/O Scheduler Without Patches

  • This topic has 4 replies, 3 voices, and was last updated Jul 3-7:47 am by sleekmason.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #8069
    Member
    sleekmason

      All of the latest kernels from 4.12 on support the BFQ IO Scheduler with changes to the kernel config file. This makes it easy to test or use a different scheduler for different uses.

      For those using the 4.9.87 kernel you can find the patches to make your kernel use BFQ –HERE–
      Place patches in the kernel folder, and before “make menuconfig” run: patch -p1 < 0001 tab-to-the-full-patch-name and do the same for all four patches.


      To find out which kernel you are currently using, type uname -r in a terminal:
      uname -r

      You will see your kernel revision number:
      4.15.9-antix.1-amd64-smp


      What is the BFQ IO Scheduler?

      From: HERE “BFQ is a proportional-share storage-I/O scheduler that also supports hierarchical scheduling with a cgroups interface.”


      And from the IO scheduler wiki: HERE

      Input/output (I/O) scheduling is the method that computer operating systems use to decide in which order the block I/O operations will be submitted to storage volumes. I/O scheduling is sometimes called disk scheduling.


      What this means in general is that IO schedulers choose what and when files are accessed/copied to disk.

      I/O schedulers can have many purposes depending on the goals; common purposes include the following:

      —To minimize time wasted by hard disk seeks
      —To prioritize a certain processes’ I/O requests
      —To give a share of the disk bandwidth to each running process
      —To guarantee that certain requests will be issued before a particular deadline


      Your current IO scheduler is probably “cfq” and you can check this with:
      sudo cat /sys/block/sda/queue/scheduler


      You should see:
      noop deadline [cfq]
      *Note (Your drive may not be sda)


      SO, BFQ differs by:

      —BFQ is based on CFQ code, but it implements a more accurate scheduling policy.
      —Distributes the throughput to I/O-bound processes as desired, even if it fluctuates. Even with a heavy load.
      — Soft real-time applications enjoy up to 3-time lower latencies than under CFQ and do not suffer from glitches.
      — Achieves a high throughput on SSDs without losing low-latency guarantees. (for solid state)
      —BFQ achieves up to 30% higher aggregate disk throughput than CFQ. (as claimed)


      Basically, if you do a lot of file transfer from video editing, copying files, backup, etc . . . BFQ might be what you are looking for.

      Also BFQ is the default I/O scheduler in Manjaro, Mageia, OpenMandriva, Sabayon, Arch Linux ARM. Interesting tidbit that.


      To Use BFQ
      Easy peasy. Follow the steps below. All commands need sudo or use root in the terminal.


      REBOOT your computer, and at the grub screen, use the DOWN arrow to Advanced Options and type “e” to edit the grub command line.


      To check out BFQ without changing anything permenently, add this line after “quiet”, making sure to leave a space between “quiet” and the command below.
      scsi_mod.use_blk_mq=1


      Once you have booted into your desktop, to see a list of available schedulers, open a terminal “su” to root and:
      cat /sys/block/sda/queue/scheduler

      Your output should be:
      [bfq] none


      or, if you have built your own kernel and enabled the options in the block layer, you will get:
      [mq-deadline] kyber bfq none


      Next, IF you are using a rebuilt kernel, you will need to change the scheduler to BFQ by using:
      echo bfq > /sys/block/sda/queue/scheduler

      If you simply installed the latest kernel with apt, you won’t need to do this.


      Run the cat command again and you should see:
      mq-deadline kyber [bfq] none


      If so, then you are now using BFQ for the current session. Try them all if you like.


      TO apply on boot:

      Now after you have been using BFQ for a bit and decide you want to make it permanent on boot, you will need to edit /etc/default/grub
      nano /etc/default/grub

      You should see:

      -GRUB_DEFAULT=0
      GRUB_TIMEOUT=5
      GRUB_DISTRIBUTOR=<code>lsb_release -i -s 2> /dev/null || echo Debian</code>
      GRUB_CMDLINE_LINUX_DEFAULT=" vga=791 quiet "
      GRUB_CMDLINE_LINUX=""



      Add the same line you used at the boot prompt: scsi_mod.use_blk_mq=1 and add this to the file as shown below:

      GRUB_DEFAULT=0
      GRUB_TIMEOUT=5
      GRUB_DISTRIBUTOR=<code>lsb_release -i -s 2> /dev/null || echo Debian</code>
      GRUB_CMDLINE_LINUX_DEFAULT=" vga=791 quiet scsi_mod.use_blk_mq=1 "
      GRUB_CMDLINE_LINUX=""



      Once you have the line the way you want, simply hit “F2” to open the “save file” prompt, type “y” and ENTER.


      UPDATE GRUB! If you don’t, nothing changes.
      update-grub

      *Note Be careful here. Screwing up you grub file may or may not allow you to boot if you get it wrong.
      IF you did mess up, upon boot, Use DOWN arrow to Advanced Options and type “e” again to bring up the prompt, and change it back to the original.


      Once updated, you will need to make a file to activate BFQ at boot, or you will have to use echo bfq > /sys/block/sda/queue/scheduler after every boot.


      To make the file 60-block.rules in /etc/udev/rules.d, as root/sudo:
      nano /etc/udev/rules.d/60-scheduler.rules

      Add this line:
      ACTION=="add|change", KERNEL=="sd*[!0-9]|sr*", ATTR{queue/scheduler}="bfq"
      Hit F2 and save.
      upon REBOOT, check with:
      cat /sys/block/sda/queue/scheduler


      Thats it!

      • This topic was modified 5 years, 1 month ago by sleekmason.
      #8285
      Member
      ohh
        Helpful
        Up
        0
        ::

        Excellent, very good how to. Nice work sleekmason

        cheers,
        ohh

        Every matter requires prior knowledge.

        - Du Mu
        The Art of War

        #8333
        Member
        sleekmason
          Helpful
          Up
          0
          ::

          Thank you ohh! fun project:)

          #8377
          Member
          wildstar84
            Helpful
            Up
            0
            ::

            OR, you can just install the latest Liquorix kernel!

            #11237
            Member
            sleekmason
              Helpful
              Up
              0
              ::

              https://phoronix.com/scan.php?page=news_item&px=Liquorix-Linux-4.17-Kernel
              Faster compile times?
              Edit * Benchmarks can be fickle to be sure. Years ago, I used Liquorix and thought it was fine. I am interested in the compile speed doubling:)
              Edit 2 My original statement sounded harsh as hell, and was not intended that way at all. My apologies.

              • This reply was modified 4 years, 10 months ago by sleekmason.
            Viewing 5 posts - 1 through 5 (of 5 total)
            • You must be logged in to reply to this topic.