Skip to content

Checking your reading list…

Retry verification

Stay curious. Build better.

Appearance

Choose how BestHub looks on this device.

Changes apply immediately.

Search articles

Open Discover with these filters

Suggested searches

Linux Kernel's 4 IO Schedulers: Noop, CFQ, Deadline & Anticipatory Explained
Fundamentals 12 min read

Linux Kernel's 4 IO Schedulers: Noop, CFQ, Deadline & Anticipatory Explained

This article explains the four Linux kernel IO schedulers—Noop, CFQ, Deadline, and Anticipatory—detailing their queue structures, merging and sorting strategies, priority handling, and ideal use cases for traditional rotating disks versus SSDs.

Linux kernel includes four IO schedulers: Noop, Anticipatory, Deadline, and CFQ. Disk read/write latency mainly comes from head movement; the kernel mitigates this via caching and IO scheduling algorithms.

Scheduling Algorithm Concepts

When writing or reading data blocks, requests are placed in a queue waiting for completion.

Each block device has its own request queue.

The IO scheduler maintains queue order to utilize media more efficiently, turning unordered IO into ordered IO.

The kernel must first determine the number of requests in the queue before scheduling.

IO Scheduler (IO Scheduler)

The IO scheduler decides the submission order of IO operations on block devices, aiming to increase IO throughput and reduce IO response time. These two goals often conflict, so multiple algorithms adapt to different scenarios. For database random read/write workloads, Deadline is most beneficial.

In the kernel stack, each block device or partition has a request_queue, which can select an IO scheduler to coordinate submitted requests. The scheduler sorts requests by sector number to minimize head movement. Besides the device queue, each scheduler maintains internal queues; the front request moves to the request queue for processing.

IO schedulers reduce disk rotation needs via two mechanisms:

Merging : adjacent requests are combined into one.

Sorting : requests are ordered by disk rotation direction.

When a new request arrives, if it is adjacent to an existing request, they merge; otherwise it is inserted in sorted order, while avoiding excessive delay for individual requests.

1. NOOP

NOOP (No Operation) uses a FIFO queue: requests are processed in arrival order. It does minimal work—merge if possible, otherwise attempt sorting. If queue requests are old, new requests go to the end; otherwise they insert at the appropriate position. If neither merge nor insert is possible, the request goes to the end.

Suitable scenarios:

When request order must not be changed.

Devices with smarter scheduling underneath (e.g., NAS storage).

Applications that already optimize their IO requests.

Non-rotational media like SSDs, because SSDs have no seek time.

2. CFQ (Completely Fair Queuing)

CFQ assigns each process a request queue and a time slice. Within its time slice, a process can submit read/write requests to the block device; when the slice expires, the queue is suspended. Time slice length and queue length depend on the process's IO priority.

IO priorities (high to low):

RT (real time)

BE (best effort)

IDLE (idle)

RT and BE each have 8 sub-priorities, adjustable via ionice. Higher priority gets earlier processing, larger time slices, and more requests per slice.

Only synchronous requests (read or sync write) are per-process; they go into the process's own queue. Asynchronous requests of the same priority share a common queue: 8 (RT) + 8 (BE) + 1 (IDLE) = 17 async queues total.

Since Linux 2.6.18, CFQ is the default IO scheduler. For general-purpose servers, CFQ is a good choice, but the final selection should be based on benchmarks for the specific workload.

3. DEADLINE

Deadline addresses the starvation problem in CFQ. Besides CFQ's sorted queue, Deadline adds separate FIFO queues for read and write IO.

Read FIFO max wait: 500 ms

Write FIFO max wait: 5 s (both tunable)

Priority order: FIFO(Read) > FIFO(Write) > CFQ. Deadline guarantees minimal latency for each request, making it suitable for DSS applications.

Deadline improves the Elevator algorithm by:

Avoiding indefinite request postponement.

Differentiating read vs. write operations.

It maintains three queues: (1) sorted by physical position (like Elevator), (2) read requests by time, (3) write requests by time. Reads get higher priority because applications typically block on reads, while writes often return after copying to memory (background writeback).

Each new request enters the sorted queue and the tail of the respective read/write FIFO. The scheduler processes from the sorted queue while checking if the head of the read/write FIFOs has exceeded its deadline (5 ms for reads, 5 s for writes); if so, it services those requests.

Note: For partitions handling database transaction logs (e.g., Oracle online logs, MySQL binlog), Deadline may not be ideal because those writes often use fsync and can stall if writes are delayed.

4. ANTICIPATORY

CFQ and Deadline focus on random IO. For sequential IO (e.g., sequential reads), they lack optimization. Anticipatory builds on Deadline, adding a 6 ms anticipation window for each read IO. If a nearby read request arrives within 6 ms, it is served immediately, optimizing mixed random/sequential workloads.

Summary

IO scheduler choice depends on hardware characteristics and application scenarios.

On traditional SAS disks, CFQ, Deadline, and Anticipatory are all solid choices; for dedicated database servers, Deadline offers good throughput and response time.

On SSDs or Fusion IO, the simplest NOOP may be best because the other three optimize for seek time reduction, which is irrelevant on solid-state media with near-zero seek latency.

About this article

For questions about attribution, corrections or content rights, please contactadmin@besthub.devand we will review it promptly.

Published

AI-assisted summary

Report an issue with this article
Linux kernelSSDblock deviceIO schedulerDeadlineCFQNoopAnticipatory

Reader feedback

Was this useful?

Useful0

Discussion 0

Questions, practical examples and thoughtful responses.

Open full discussion