Change disk I/O scheduler on the fly

diskThe Linux kernel supports 4 I/O schedulers for disks:

  • Deadline: minimizes disk seeks in order to provide best possible response time Default on Ubuntu.
  • Anticipatory: Adds an anticipation heuristic on top of deadline I/O scheduler. It spends a few milliseconds in anticipation that new requests in the same area might appear. However, if there are no further requests, the time is wasted in waiting. Not very common.
  • Completely Fair Queueing: Assigns the requests to multiple queues based on the process requesting the I/O. Services the queues round-robin. Default on RHEL.
  • Noop: No optimization of disk seeks.

As you can understand from the working principle of each scheduler, they fit the bill or different use-cases. The good part is they are per-disk based schedulers and can be changed on the fly.

You can, of course, change the behaviour of the kernel and compile it from scratch. All you need to set is any one of the following  kernel config options:

CONFIG_DEFAULT_DEADLINE
CONFIG_DEFAULT_CFQ
CONFIG_DEFAULT_NOOP

and set

CONFIG_DEFAULT_IOSCHED="scheduler_of_choice"

To check the scheduler used for a particular disk (e.g. sda):

$ cat /sys/block/sda/queue/scheduler 
noop [deadline] cfq

To set it to cfq at runtime:

$ echo cfq | sudo tee /sys/block/sda/queue/scheduler

Leave a Reply

Your email address will not be published. Required fields are marked *