Linux Commands

How and When to Change I/O Scheduler in Linux

The I/O Scheduler is a fascinating topic; Beforehand, we get into how and when to adjust the I/O scheduler; let’s have a deeper understanding of what I/O schedulers do. A Linux I/O scheduler governs how the kernel commits, reads, and writes to the disc. Executives have been capable of adjusting the scheduling system since about the 2.6 kernels, allowing them to tailor their frameworks to their exact requirements. Disk accessibility has long been thought to be the relatively slow means of data access. Despite the increasing prevalence of Flash and Solid State-space, retrieving data from disc is sluggish than collecting information from RAM. This is particularly valid if the framework is based on spinning discs.

Why Use Scheduler:

Since standard spinning discs write information based on places on a rotating platter, this is the case. While accessing data from a spinning disc, the actual drive must rotate the platters to a specific position so the information can be read. This is referred to as “seeking” because it can take much longer in terms of computation. I/O schedulers aim to help you get the most out of your disc access permissions. We used to do the same by combining I/O transactions and sending them to neighboring disc locations. The drive doesn’t even have to “seek” as much when requests are grouped in adjacent parts of the disk, which improves the average response time for disc operational activities. There are many I/O scheduler solutions available on current Linux architectures. Either one of these has its system for arranging disc access requests. This article will learn how to check the current scheduler in your system and how to change your scheduler while working on the Linux operating system.

Types of Schedulers:

There seem to be 3 types of schedulers to pick from, each with its own set of advantages in the Linux operating system. So, here is the list and explanation of each scheduler:

  • CFQ (cfq): the standard scheduler for so many Linux distros; it cohorts simultaneous requests made by operations into a series of per-process pools before allocating timeslices to use the disc for every queue.
  • The Noop scheduler (noop): It is the most basic I/O scheduler for the Linux kernel, built upon on FIFO pool principle. This scheduler works well for SSDs.
  • Deadline scheduler (deadline): This scheduler tries to ensure a request begin-service period.

Check Current Scheduler:

Before going forward, you must know about the I/O scheduler configured in your current Linux system. At the time of implementation, we have been using the Ubuntu 20.04 Linux system, so our scheduler will be. It could be possible that your Linux system may have a different I/O scheduler configured in the system. So, log in from your current Linux system to try checking it. Now, launch the terminal shell using the simple shortcut key, “Ctrl+Alt+T.” You can try to open the terminal shell using the activity bar area on your Linux desktop. Now, the command-shell terminal has been opened, we can start working on it. First of all, we have to log in as a sudo user from the terminal to work efficiently and without interruption. So, type the “su” command in the terminal to log in. It will ask you for your sudo account password to log in from it. Type the sudo account password and hit the “enter” key from your typewriter.

$ su

Now, it’s time to check and identify the I/O scheduler of our Linux system. As you know, currently, we have been working on Ubuntu 20.04 Linux system to be according to it, and we have to check it by reading the scheduler file via its path. So, we have to try out the below cat instruction in the shell terminal along with the file location via path and hit the “Enter button from the typewriter of your computer.

# cat /sys/block/sda/queue/scheduler

The picture below shows the output as “[mq-deadline] none”, which means our device has a multi-queue Deadline scheduler in it. It is a Multiqueue device-specific adaptation of the deadline I/O scheduler. A solid all-arounder with low CPU use.

Note: You have to make your mind clear that the multi-queue I/O schedulers are the solitary I/O schedulers offered in the Ubuntu Eoan Ermine 19.10 as well as headlong.

Change the I/O Scheduler:

If a Linux system user wants to change his/her I/O scheduler to “Kyber,” they have to firstly install the “kyber” package in their Linux system in the two below steps. One must have to execute the below sudo command having the keyword “modprobe” with the name of a scheduler as “kyber-iosched.”

# sudo modprobe kyber-iosched

The second step is to run the same “cat” command mentioned in one of the above commands to install it.

# cat /sys/block/sda/queue/scheduler

Now the “kyber” is successfully configured. Now you can enable “kyber” using the below “echo” scheduler command along with the “sudo” and “tee” keywords having the path of a scheduler attached to it. The output image is presenting the enabled scheduler “kyber.”

# echo “kyber” | sudo tee /sys/block/sda/queue/scheduler

The output below is showing that the “kyber” has been set to default.

# cat /sys/block/sda/queue/scheduler

To change the scheduler to the “bfq” scheduler, install it using the below command.

# sudo modprobe bfq

Now run the same “cat” command.

# cat /sys/block/sda/queue/scheduler

Now the “bfq” has been installed, enable it using the same “echo” command.

# echo “bfq” | sudo tee /sys/block/sda/queue/scheduler

Check the default “bfq” scheduler through the “cat” command.

# cat /sys/block/sda/queue/scheduler

Conclusion:

This tutorial article has covered a simple way to change the I/O scheduler using two different schedulers. We have discussed why the system wants to change its scheduler hope it works for you.

About the author

Aqsa Yasin

I am a self-motivated information technology professional with a passion for writing. I am a technical writer and love to write for all Linux flavors and Windows.