I/O Scheduler

When your system has dozens of processes all reading and writing to disk at once, who goes first? That's the I/O scheduler's job — it decides the order of disk requests to maximize throughput, minimize latency, and be fair to all processes.

Why Does Order Matter?

Why not just process disk requests in the order they arrive? On spinning hard drives (HDDs), the read/write head physically moves across a spinning platter. If requests arrive in random order, the head spends most of its time seeking back and forth — wasting time. Reordering requests so the head sweeps in one direction (like an elevator) dramatically reduces seek time. On SSDs, there's no moving head, but scheduling still helps with request merging and fairness.

HDD vs SSD — Different Needs

HDDNVMe SSD
Seek time5–15ms (physical head movement)~0.1ms (no moving parts)
Random vs sequentialSequential much fasterComparable speed
Scheduling benefitHigh — reorder saves seek timeLow — hardware handles it
Best schedulerBFQ or mq-deadlinenone (no scheduler)
Queue depth1 (single queue)Up to 65535 (multi-queue)

The Schedulers — Old and New

none / noop — No Scheduling

No reordering. Requests processed in arrival order (FIFO), with basic merging of adjacent requests. Best for NVMe SSDs where the device's own hardware queue is smarter than any software scheduler. Also used in VMs (the host handles scheduling).

mq-deadline — Deadline-Based

Each request gets a deadline (default: 500ms reads, 5s writes). The scheduler batches requests for throughput but guarantees no request waits past its deadline. Good balance for SSDs and HDDs. Prevents write starvation — a common problem when reads always jump the queue.

BFQ — Budget Fair Queuing

Assigns each process a "budget" of disk sectors. Processes get fair slices of disk bandwidth, similar to CPU scheduling. Great for desktop use: your music player won't stutter while a large file copies. Slightly higher CPU overhead than mq-deadline. Best for HDDs and SATA SSDs on interactive systems.

CFQ — Completely Fair Queuing (legacy)

The old default before multi-queue block layer. Replaced by BFQ. Uses per-process I/O queues with time slices. Still available but deprecated — use BFQ instead.

Check and Change Schedulers

# Check current scheduler for a device cat /sys/block/sda/queue/scheduler # mq-deadline [bfq] none ← brackets = current cat /sys/block/nvme0n1/queue/scheduler # [none] ← NVMe defaults to none # List available schedulers cat /sys/block/sda/queue/scheduler # mq-deadline [bfq] none # Change at runtime (takes effect immediately) echo mq-deadline > /sys/block/sda/queue/scheduler echo none > /sys/block/nvme0n1/queue/scheduler # Make permanent (udev rule) # /etc/udev/rules.d/60-scheduler.rules: ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/scheduler}="bfq" ACTION=="add|change", KERNEL=="nvme[0-9]*", ATTR{queue/scheduler}="none"

Which Scheduler to Use?

WorkloadDeviceRecommendedWhy
NVMe SSD (any workload)NVMenoneDevice handles queuing natively
Desktop / interactiveHDD/SATA SSDBFQFair per-process, no stutter
Database serverSATA SSDmq-deadlineLower latency, deadline guarantees
VM guestVirtual disknoneHost hypervisor handles it
Spinning HDD, latency mattersHDDmq-deadlinePrevents starvation

Tuning Queue Depth and Read-Ahead

# Queue depth — how many requests device can handle at once cat /sys/block/sda/queue/nr_requests # 64 ← default, good for most cases # Read-ahead — pre-fetch sequential data (in 512-byte sectors) cat /sys/block/sda/queue/read_ahead_kb # 128 ← default # Increase read-ahead for sequential workloads (large file reads, video) echo 2048 > /sys/block/sda/queue/read_ahead_kb # Disable for random-access workloads (databases with their own cache) echo 0 > /sys/block/sda/queue/read_ahead_kb # Check I/O stats per device cat /proc/diskstats # or iostat -x 1 # requires sysstat package

Frequently Asked Questions

What will I learn here?

This page covers the core concepts and techniques you need to understand the topic and progress confidently to the next lesson.

How should I use this page?

Start with the overview, then follow the section links to deepen your understanding. Use the table of contents on the right to jump to specific sections.

What should I read next?

Use the navigation below to continue to the next lesson or explore related topics.