Friday, September 25, 2015

Oracle Linux - change IO scheduler

When installing Oracle Linux you will be equipped with a I/O scheduler which is perfectly usable for a database. This is not surprising as Oracle is from origin a database vendor. 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. However, even though the fact that you get a good scheduler there might be a need to change the default scheduler for some reason. A number of reasons can be thought of, depending on the type of I/O your performance can improve by selecting a different scheduler.

The below image shows the overall view on the Linux Storage Stack which includes the scheduler within the Block Layer. This image shows the full stack which includes more components then only the I/O scheduler.

In case you want to check what the current I/O scheduler is for a specific device you can do this by using the following command (for example for sda):

cat /sys/block/sda/queue/scheduler

This will show you the current scheduler that is used. For example, the output could be the one shown in the example below:

[root@demo1 etc]# cat /sys/block/sda/queue/scheduler
noop [deadline] cfq
[root@demo1 etc]# 

In case you need to change this there are some differences in how to do this. To activate a different scheduler, for example change it to cfq you can cat the new scheduler in by using the below commands:

[root@demo1 etc]#
[root@demo1 etc]# cat /sys/block/sda/queue/scheduler
noop [deadline] cfq
[root@demo1 etc]# cat cfq > /sys/block/sda/queue/scheduler
[root@demo1 etc]# cat /sys/block/sda/queue/scheduler
noop deadline [cfq]
[root@demo1 etc]#

As you can see this has changed the scheduler to cfq and no longer deadline is selected as the standard I/O scheduler. To make things persistent you have to change the grub configuration. When you are using grub2 the process is a bit different from using grub which is still in most standing Linux implementations. When using grub2 you have to edit the default grub2 file which is located at /etc/default/grub here you will have to add the new scheduler to GRUB_CMDLINE_LINUX which could look like the example below:

GRUB_CMDLINE_LINUX="crashkernel=auto  vconsole.font=latarcyrheb-sun16 vconsole.keymap=us rhgb quiet"

If we, for example, like to make cfq persitant we have to change the line into the example below by add elevator=cfq to it:

GRUB_CMDLINE_LINUX="crashkernel=auto  vconsole.font=latarcyrheb-sun16 vconsole.keymap=us rhgb quiet elevator=cfq"

This only has placed the new information into the defaults file and not yet into the grub2.cfg file where it is needed during boot. To ensure this is added to the grub2.cfg file you have run grub2-mkconfig and ensure the output is directed to /boot/grub2/grub.cfg as shown in the example below.

[root@demo1 default]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-123.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-123.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.8.13-35.3.1.el7uek.x86_64
Found initrd image: /boot/initramfs-3.8.13-35.3.1.el7uek.x86_64.img
Warning: Please don't use old title `Oracle Linux Server, with Unbreakable Enterprise Kernel 3.8.13-35.3.1.el7uek.x86_64' for GRUB_DEFAULT, use `Advanced options for Oracle Linux Server>Oracle Linux Server, with Unbreakable Enterprise Kernel 3.8.13-35.3.1.el7uek.x86_64' (for versions before 2.00) or `gnulinux-advanced-8f652ccf-3540-4549-9a5c-1d126e882d35>gnulinux-3.8.13-35.3.1.el7uek.x86_64-advanced-8f652ccf-3540-4549-9a5c-1d126e882d35' (for 2.00 or later)
Found linux image: /boot/vmlinuz-0-rescue-782e1cbce43c4c9d8829bd4addd5f09d
Found initrd image: /boot/initramfs-0-rescue-782e1cbce43c4c9d8829bd4addd5f09d.img
[root@demo1 default]#

If we now reboot the machine and check again what the scheduler is that is applied on sda we can see that cfq has been selected as the default scheduler for this device:

[root@demo1 ~]# cat /sys/block/sda/queue/scheduler
noop deadline [cfq]
[root@demo1 ~]#

When working with a grub bootloader you can directly change the scheduler in /etc/grub.conf however, withthe introduction of grub2 this is no longer an option and you need to take the above mentioned steps to change the I/O scheduler in Oracle Linux. 

No comments: