Course contentsShow
← Linux
Lesson 645 of 1,8197. Storage Management and Logical VolumesFree lesson

I/O schedulers and elevator algorithms

Evaluate mq-deadline and kyber schedulers to optimize disk latency under load.

In this lesson, you will learn how to optimize your disk latency under heavy load by choosing between the mq-deadline and kyber I/O schedulers.

When your system performs many read and write operations simultaneously, the Linux kernel must decide which request to process first. If it simply processed requests in the order they arrived, your hard drive head would jump around needlessly, causing massive performance bottlenecks. This is where I/O schedulers—often called "elevator algorithms"—come in, reordering requests to minimize travel time or maximize throughput.

The mq-deadline Scheduler

mq-deadline is the modern successor to the classic deadline scheduler, optimized for multi-queue block devices. It maintains a primary goal: preventing "starvation." It assigns an expiration time to every I/O request. While it tries to keep the "elevator" moving in one direction to maintain efficiency, it will force the disk to jump to a request if that request is nearing its expiration deadline. This makes it an excellent, predictable choice for general-purpose workloads where you need to guarantee that no single task is ignored for too long.

The Kyber Scheduler

kyber is a newer, lightweight scheduler designed specifically for high-speed devices like NVMe drives. Unlike mq-deadline, which focuses on individual request aging, kyber focuses on latency targets. You define a target latency for reads and writes; kyber then monitors the completion time of requests. If your read requests are exceeding the latency target, kyber throttles the number of writes allowed to pass through the queue. It is essentially a "quality of service" regulator that is much better suited for high-concurrency environments where throughput is less important than keeping response times consistently low.

Changing your scheduler

You can check which scheduler is active for your device (e.g., /dev/nvme0n1) by reading its queue settings:

cat /sys/block/nvme0n1/queue/scheduler

To switch to kyber on the fly for testing, you can use:

echo kyber | sudo tee /sys/block/nvme0n1/queue/scheduler

Key Takeaway: Use mq-deadline for general hardware to prevent request starvation, or switch to kyber on high-speed NVMe drives to enforce strict latency targets during heavy I/O loads.