How can I switch between the CFS and BFS schedulers?

Solution 1:

Having researched this a bit, there seems to be only two schedulers for Linux: CFS and BFS.

The simplest way to install BFS in Ubuntu 10.10 is a PPA patch:

sudo add-apt-repository ppa:chogydan/ppa 
sudo apt-get update
sudo apt-get install linux-image-generic-ck linux-headers-generic-ck

You can also install the patch using the Ubuntu Software Center as described in "What are PPAs and how do I use them".

The patch installs a new (patched) kernel, which will show up in the GRUB menu at boot with the suffix "-ck". Switch between schedulers by rebooting and selecting the appropriate kernel in the boot menu.


On performance

In my case, running Folding@Home in the background on a desktop PC (eight F@H threads on eight cores on an Intel i7 2600K), BFS is significantly better: Desktop response is snappier (not a big difference, but definitely noticeable) while the background F@H application is 20-25% faster.

In this scenario, dealing with interactive desktop use and long-running CPU-heavy background tasks simultaneously, CFS tended to leave one core idle for long periods at a time. BFS appears much better at using all cores 100% for background tasks while still providing fast response for interactive desktop tasks.

There is probably no single scheduler that will perform optimally under every possible combination of loads, but there are cases where BFS is better.

Solution 2:

You will have to download, patch, and compile your own kernel because BFS is currently not part of the mainline kernel. The mainline kernel contains only one scheduler and is not meant to have multiple schedulers in the same codebase, or even on-the-fly switchable schedulers (it that's even something that could possibly be done). It would simply be too complicated, and not worth the effort.

So, in order to get BFS on your system:

  • Get the kernel: http://www.kernel.org
  • Get the latest BFS patch for your kernel version: http://ck.kolivas.org/patches/bfs/
  • Patch, compile, and then boot your new kernel.

The benefit of running BFS over CFS is very small though, especially with newer kernel versions. Keep in mind that CFS is constantly being improved.

Solution 3:

The below worked for me on Precise Pangolin (Ubuntu 12.04) YMMV, though.

BFS is Part of pf-kernel

The best way to install BFS on an Ubuntu system today (December 2013) seem to be to install pf-kernel, which is basically a standard kernel with a bunch of performance patches applied. These patches include:

  • BFS (CPU scheduler gives low latency on machines with less than 16 CPU cores)
  • BFQ (I/O disk scheduler optimized for low latency under heavy loads)
  • TuxOnIce (faster hibernation)

Instructions on the Web

I found some instructions on how to install the pf-kernel packages for Ubuntu in the article “Get Better Linux Desktop Performance and more with pf-kernel.” – However these instructions are somewhat outdated, as it points to a non-existing source for the relevant Debian packages. But I found the thread “pf-kernel for Ubuntu” (on the pk-kernel forums) which mentions that Debian packages can be downloaded from forum user big_bum’s Dropbox account.

Installing pf-kernel

The machine I installed on is an old 32-bit laptop, so I started off by downloading the required linux-headers and linux-image packages into a directory on my machine called ~/kernel.

  • linux-headers-3.12.2-pf+_3.12.2-pf+-10.00.Custom_i386.deb
  • linux-image-3.12.2-pf+_3.12.2-pf+-10.00.Custom_i386.deb

(Go to the above mentioned Dropbox account to find 64 bit and/or newer versions of these packages.)

Thereafter I followed the instructions on “Get Better Linux Desktop Performance and more with pf-kernel,” and executed the following commands:

$ cd ~/kernel
$ sudo dpkg -i *.deb

Everything seem to work smoothly, so I rebooted.

Checking If It Works

A quick inspection seems to indicate that it works, e.g. the command uname -a reports that I'm using the pf-kernel:

Linux siobhan 3.12.2-pf+ #6 SMP PREEMPT Mon Dec 2 19:09:52 EET 2013 i686 i686 i386 GNU/Linux

And cat /sys/block/sda/queue/scheduler shows that BFQ now is the current disk scheduler (for the sda disk):

noop deadline cfq [bfq] 

Solution 4:

Patch and install a new kernel with BFS. You have to use sepatare kernels, there is no way of using both in the same kernel image (especially to swith them on-the-fly)