Monday, April 01, 2013

Installing BFQ I/O Scheduler using Liquorix Kernel


The operating system is said to be stable when both the software and hardware of a machine or a system go parallel hand in hand. Your favorite operating system or the best hardware that you opt for alone cannot outperform to provide the best performance. Hence, if we choose for the best hardware we have to tune the operating system that we install to run efficiently on that hardware.

Optimizing an operating system requires tuning of various parameters. These parameters are a part of various software that an operating system is built of. Hence tuning of all the parameters to their appropriate values as required by the user to get the best performance gives the best overall performance of the system.

One of the most important factors to regulate the system's overall performance is “Disk I/O Scheduler”. People normally wonder that their system under performs even though they have latest processor, a fast spinning hard disk and huge RAM, this is where the I/O schedulers play their role particularly under heavy work loads. By “heavy work loads” I mean to say that I can be running 3 virtual machines, copying a Ubuntu iso file from host to guest, reading a document, there's also an audio playing in the background, and web browser in which I might be sending some mails. This might be too much to handle for the operating system, I might face slow response from the web browser or I might also get some trouble hearing the song. This is where you will find the disk I/O scheduler being a little laggy.

Disk I/O is mainly categorized into sequential I/O and random I/O. Sequential involves operating on one block immediately after it's neighbor  In this type of I/O there is very little effect on the response time as the disk drive head has to do the least work in moving from one location to another. Whereas the random I/O, on the other hand, involves large numbers of seeks and rotations, which is usually much slower. We can know if our disk I/O scheduler is sequential or random by determining the “average request size” of each I/O operation. The “avgrq-sz” column from iostat output shows the average request size per I/O operation. If the average size per I/O operation is 16KB or less then it is random disk I/O and if it is greater than 128KB then it is sequential disk I/O. The below command shows average request size.

Every operating system has a special software to communicate directly with the computer's hardware called “kernel” and I/O scheduler is the part of the kernel that handles read / write access to block storage devices. It may be a a USB stick, local hard disk, or network file system or any other storage environment that holds data in blocks. In short I/O scheduler is the guy who decides how the bandwidth of the disk has to be distributed to all of the applications simultaneously or parallely that is ultimately based on the priority of the process. A scheduler, queues and sequences the execution of read-write requests, to manage mechanical latency and optimization of data delivery performance. Latency is the seek time related to head travel around the disk. Without an I/O scheduler, Linux kernel follows FIFO (First In, First Out) algorithm which can result in hard disk crashing. For example if one process is reading from one part of disk and writing to another part of the disk that will make the head move back and forth for every operation performed. A disk I/O scheduler's main goal to optimize the disk access time.

There are four main I/O schedulers that we can find in Ubuntu namely noop, cfq, deadline and anticipatory. Since anticipatory has become obsolete, you wont find it in Ubuntu 12.04. Ubuntu 12.04 has got “CFQ” as the default I/O scheduler whereas “deadline” is default in Ubuntu 12.10.

Another such I/O scheduler is BFQ (Budget Fair Queueing) which is based on CFQ (Completely Fair Queueing). Queueing doesnt actually mean that the requests will be arranged in FIFO (First-In-First-Out) order, here queue means a container that contains or holds all the requests that need to be manipulated further. BFQ was developed by Paolo Valente, who is Assistant Professor of Computer Science at the Department of Computer Science of University of Modena.

There's more material and benchmarking tests of bfq represented graphically on HecticGeek's Website. The results are interesting enough to make anyone install it in his/her machine. You can also have a look at the video on cfq and bfq comparison posted by Paolo on Youtube.

Installation
Using Liquorix Kernel - Why drive when you can FLY?
The three most important things for a good pc is cost, security and performance. As we all know ubuntu linux is free and equally very secure. What remains is performance. For performance there are many guides available on internet. One particular way that I am always interested in is to build a custom kernel. There are also performance-focused kernels available. The Liquorix kernel and Zen kernel available at Damentz websites are built for performance enhancement. Liquorix kernel is based on zen kernel. Another major benefit of using this kernel is that it has integrated BFS (Brain Fuck Scheduler, and yes that is what it is called) which is the next best thing that money cant buy. BFS is a process scheduler developed by Con Kolivas. We will discuss BFS in detail later.

Installing Liquorix kernel is very simple. To install Liquorix kernel in Ubuntu 12.04 / 12.10 one needs to install the latest gcc using "http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu precise main" ppa. Below shown is the screenshot to add gcc repo in Update Manager.

$ sudo apt-get update

Now install the latest gcc version. I found the latest gcc version to be 4.7 at the time of composing this post.
$ sudo apt-get install gcc-4.7 g++-4.7

$ sudo apt-get update

Install the Liquorix keyring.
$ sudo apt-get install '^liquorix-([^-]+-)?keyring.?'

$ sudo apt-get update

Search for the latest liquorix kernel available using the below command.
$ sudo apt-cache search liquorix

Now install Liquorix kernel.
$ sudo apt-get install liquorix*

After installing, set the “GRUB_TIMEOUT” parameter value to “-1” in /etc/default/grub file. After this you can see the list of kernels after rebooting the machine, where you can select the liquorix kernel to boot.

To list all the kernels installed in your system use the below mention command.
$ sudo dpkg --list | grep linux-image


There various benchmarking tools available for free like hdparm, iozone, bonnie++, phoronix test suite, stress, etc to test the performance of your system. Lastly I would say everyone must once try “BFQ” and feel the difference, though it is not yet seen in Ubuntu 12.10.



No comments:

Post a Comment