Linux I/O Scheduler

(updated: )
  1. 1. What Is I/O Scheduler
  2. 2. Types
  3. 3. Commands
    1. 3.1. Identifying Current I/O Scheduler
    2. 3.2. Changing IO Scheduler on Runtime
    3. 3.3. Changing the Scheduler on Boot

What Is I/O Scheduler

The purpose of I/O Scheduler is to improve the I/O performance fo traditional hard disk drive.
Like merging I/O requests to similar locations on disk, so that the drive doesn’t need to “seek” as often, improving the overall response time for disk operations.

It tries to balance between these goals:

  • fairness (let every process have its share of the access to disk)
  • performance (try to serve requests close to current disk head position first, because seeking there is fastest)
  • realtime (guarantee that a request is serviced in a given time)

Types

  • deadline scheduler
    Two queues: a read queue and a write queue.
    Each I/O request has a time stamp associated that is used by the kernel for an expiration time.
    The default “deadline” values are 500 ms for read operations and 5,000 ms for write operations, which means good for read-heavy workload.
    This is a cyclic elevator but with a twist: requests are given a deadline by which they get served. When a request starts to look like it’s going to expire, the kernel will skip intermediate sectors and move to that request, thus giving some realtime behaviour.
  • AS (Anticipatory Scheduler) scheduler
    A cyclic elevator with waiting policy: after you service a request that looks like it might have future requests coming nearby, you pause even if there’s more sectors in your work queue. The anticipatory scheduler literally anticipates more requests to follow on this track or very close by. How AS decides whether to anticipate is basically just lot of guesswork based on typical access patterns.
  • cfq (Complete Fairness Queueing) scheduler
    The default for most Linux distributions.
    Providing a fair I/O priority to each process (round-robin), each process has it’s own queue.
  • noop scheduler
    No special Operation, no algorithms, raw, just serve the requests in the FIFO queue one by one.
    Good for SSD.

Commands

Identifying Current I/O Scheduler

1
cat /sys/block/sda/queue/scheduler

Changing IO Scheduler on Runtime

This change takes effect immediately, but is NOT permanent.

1
echo "noop" > /sys/block/sda/queue/scheduler

Changing the Scheduler on Boot

1
vi /etc/default/grub

Add is the elevator parameter:

1
GRUB_CMDLINE_LINUX="elevator=noop"

Run update-grub2 command to apply the changed configurations:

1
update-grub2