Rate This Document
Findability
Accuracy
Completeness
Readability

Optimizing the Drive I/O Scheduling Mode

Principles

When the file system performs drive read and write operations through the driver, the read and write requests are not sent to the driver immediately. Instead, the read and write requests are delayed. In this way, the I/O scheduler of the Linux kernel can combine multiple read and write requests into one request or sort them (to reduce the addressing of mechanical drives) and send them to the driver, improving performance. When we introduced the iostat tool previously, we also mentioned the merged statistics, which are obtained from this process.

The current Linux versions support the following scheduling mechanisms:

  1. Completely Fair Queuing (CFQ) scheduling

    This is the default scheduling algorithm of the early Linux kernel. It allocates a scheduling queue to each process. By default, I/O resources are fairly allocated between processes based on the time slice and the number of requests. The performance of this algorithm is not very high when the I/O pressure is high and I/Os are concentrated in several processes.

  2. Deadline scheduling

    This scheduling algorithm maintains four queues: the read queue, the write queue, the read timeout queue, and the write timeout queue. When the kernel receives a new request, it merges the request if possible; if the request cannot be merged, it sorts the request. If neither merge nor insertion is possible, it is placed at the end of the read or write queue. After a period of time, the I/O scheduler moves the requests in the read or write queue to the read timeout or write timeout queue. This algorithm does not limit the I/O resources used by each process. It is applicable to scenarios where I/O pressure is high and I/Os are concentrated in several processes, for example, big data and database scenarios using HDDs.

  3. NOOP (or NONE) scheduling, a simple first in first out (FIFO) scheduling policy

    SSDs support random read and write. Therefore, you can select this simplest scheduling policy for SSDs to achieve the best performance.

Modification Method

Check the current scheduling mode.

1
2
# cat /sys/block/$DEVICE-NAME/queue/scheduler
noop deadline [cfq]

[ ] contains the current drive I/O scheduling mode.

The returned value or default value may vary according to the operating system you are using.

To change the value, run the echo command. For example, to change sda to deadline, run the following command:

1
# echo deadline > /sys/block/sda/queue/scheduler