Modern Linux kernels ship four I/O schedulers — none, mq-deadline, bfq and kyber — and the short answer is that NVMe wants none, SATA and SAS SSDs want mq-deadline, spinning disks and interactive desktops want bfq, and cloud VMs mostly want whatever the distro already picked. The older names you will still find in blog posts — cfq, deadline, noop, anticipatory — no longer exist; they were deleted along with the single-queue block layer in Linux 5.0. This guide covers reading and setting the current scheduler, what each one actually does, the queue knobs that sit next to it, and how to make the choice survive a reboot with a udev rule rather than a startup script.
What you’ll accomplish
- Read the active scheduler for every block device on a host, and see the whole fleet at a glance.
- Pick a scheduler deliberately for NVMe, SATA/SAS SSD, spinning disk and virtual disk, and know why.
- Tune the related queue attributes
nr_requests,read_ahead_kb,rotationalandadd_random. - Persist the choice with a udev rule at
/etc/udev/rules.d/60-ioscheduler.rulesthat survives reboots and device hotplug. - Measure the change with
fiobefore and after, so the decision rests on your workload rather than someone else’s benchmark.
Prerequisites
- A Linux host running kernel 5.0 or newer. Everything here assumes blk-mq, which has been the only block path since 5.0 (2019). On a 4.x kernel you may still see
cfqanddeadline, and this guide does not apply cleanly. - Root or
sudo. Writing to/sys/blockand installing udev rules both need it. util-linuxforlsblk(theSCHEDcolumn needs a reasonably recent version),systemd/udevforudevadm, andfiofor measurement. On Debian and Ubuntu:apt install fio. On RHEL family:dnf install fio.- Examples use
nvme0n1andsda. Substitute your own device names — always the whole disk, never a partition. Partitions have no scheduler of their own. bfqandkyberare often built as modules and may not appear in the list until loaded. That is covered in troubleshooting.
How it works
The block layer that reaches your disk is multi-queue. When a process calls write(), the data lands in the page cache, and when the kernel decides to issue it, the request enters a per-CPU software queue — one per CPU, so there is no single lock every core fights over. From there it is either handed straight to a hardware dispatch queue that the driver owns, or it passes through an I/O scheduler first.
That scheduler stage is optional, and none is the setting that removes it. The point of a scheduler was always to compensate for a device that was bad at receiving requests out of order — a spinning platter where a poorly ordered queue costs milliseconds of seek time. An NVMe drive is the opposite case: it exposes many deep hardware queues and reorders internally, so sorting requests in software adds CPU work and latency without buying anything back.
The four choices divide cleanly by intent. none does no reordering and no merging beyond what blk-mq already does. mq-deadline keeps separate read and write queues, assigns each request an expiry, and dispatches in sector order until something is about to miss its deadline — it costs very little and it stops a heavy writer from starving readers. bfq (Budget Fair Queueing) gives each process a time budget and shares bandwidth proportionally; it is the right answer when a desktop, a build machine or a spinning disk needs one greedy job not to freeze everything else, and it carries real CPU overhead once you are past roughly 100k IOPS. kyber is the simplest of the tuned ones: you give it target read and write latencies and it throttles queue depth to hold them.
Four sysfs attributes live next to scheduler in the same directory and matter as much as the scheduler itself. nr_requests is how many requests the scheduler queue holds per device; raising it can improve throughput on deep-queue devices and can also inflate latency. read_ahead_kb (128 by default) is the sequential prefetch window — worth raising for large sequential reads, worth lowering for random workloads that read ahead into nothing. rotational is a 0/1 flag the kernel guesses from the device, and it is what udev rules and other tuning tools key on; a virtual disk backed by SSD sometimes reports 1 incorrectly. add_random controls whether the device contributes timing entropy to the kernel pool, a small per-request cost with no value on a device with no mechanical randomness.
Step-by-step
1. Read the current scheduler. The active one is the value in square brackets:
cat /sys/block/nvme0n1/queue/scheduler
[none] mq-deadline kyber bfq
If a scheduler you expect is missing from the list, its module is not loaded — see troubleshooting.
2. See every device at once. For a fleet or a many-disk host, lsblk gives you the device name, whether the kernel thinks it rotates, and the scheduler in one table:
lsblk -d -o NAME,ROTA,SCHED,SIZE,MODEL
NAME ROTA SCHED SIZE MODEL
nvme0n1 0 none 476.9G Samsung SSD 980 PRO
sda 0 mq-deadline 1.8T Samsung SSD 870
sdb 1 bfq 3.6T ST4000NM000A
The -d flag suppresses partitions, which is what you want — schedulers are a whole-disk property. A quick sysfs equivalent that works anywhere lsblk is old:
grep . /sys/block/*/queue/scheduler
3. Change it for a live test. Writing the name into the sysfs file switches it immediately. The queue is briefly quiesced, so do this when the device is not under peak load:
echo mq-deadline | sudo tee /sys/block/sda/queue/scheduler
mq-deadline
Confirm the brackets moved:
cat /sys/block/sda/queue/scheduler
none [mq-deadline] kyber bfq
This change is not persistent. A reboot, and on some setups a device re-scan, puts it back.
4. Look at the queue knobs before you touch them. Record the current values so you can put them back:
grep . /sys/block/sda/queue/{nr_requests,read_ahead_kb,rotational,add_random}
/sys/block/sda/queue/nr_requests:256
/sys/block/sda/queue/read_ahead_kb:128
/sys/block/sda/queue/rotational:0
/sys/block/sda/queue/add_random:0
Change one at a time, and only with a reason. Raising read_ahead_kb to 512 or 1024 helps a backup target or a media store doing long sequential reads; leaving it at 128 is correct for a database. Note that with none selected, nr_requests reflects the hardware tag depth and cannot be raised above it.
5. Correct a mis-detected rotational flag. If a virtualised or RAID-backed SSD reports 1, tools downstream will treat it as a platter:
echo 0 | sudo tee /sys/block/sda/queue/rotational
0
6. Write the udev rule. This is the part most guides get wrong. Create /etc/udev/rules.d/60-ioscheduler.rules so the rule applies at boot and on hotplug, matching on device class rather than hardcoding names:
sudo tee /etc/udev/rules.d/60-ioscheduler.rules >/dev/null <<'EOF'
ACTION=="add|change", KERNEL=="nvme[0-9]n[0-9]", ATTR{queue/scheduler}="none"
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="mq-deadline"
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="1", ATTR{queue/scheduler}="bfq"
EOF
Two details carry the whole file. ACTION=="add|change" is needed because a disk that is already present at rule-reload time emits change, not add. And single = assigns while double == matches — ATTR{queue/rotational}=="0" is a test, ATTR{queue/scheduler}="none" is a write.
7. Reload and apply the rules. Reloading alone does not re-run rules against existing devices; trigger them:
sudo udevadm control --reload
sudo udevadm trigger --subsystem-match=block --action=change
Neither command prints anything on success.
8. Do not use the elevator= kernel parameter. It is inert on blk-mq kernels. If you have it in /etc/default/grub, remove it and regenerate the config — it is doing nothing except making the next person think the scheduler is pinned:
grep -r elevator= /etc/default/grub /etc/kernel/cmdline 2>/dev/null
No output means you are clean.
9. Measure, do not assume. Run the same fio job before and after the change. This one is read-only against the raw device, so it will not destroy data, but confirm the device path first:
sudo fio --name=randread --filename=/dev/sda --rw=randread --bs=4k \
--ioengine=libaio --direct=1 --iodepth=32 --numjobs=4 \
--runtime=60 --time_based --group_reporting
The numbers to compare are IOPS and, more importantly, the completion-latency percentiles:
read: IOPS=94.2k, BW=368MiB/s (386MB/s)(21.6GiB/60001msec)
clat percentiles (usec):
| 50.00th=[ 330], 95.00th=[ 668], 99.00th=[ 1237], 99.90th=[ 2245]
If the 99th percentile does not move, the scheduler is not your bottleneck.
Validate it works
Confirm the runtime state right now. Every device should show the scheduler you intended:
lsblk -d -o NAME,ROTA,SCHED
NAME ROTA SCHED
nvme0n1 0 none
sda 0 mq-deadline
sdb 1 bfq
Confirm the rule itself is what applied it, not a leftover manual echo. udevadm test replays rule processing against one device and shows which files it would write:
sudo udevadm test /sys/block/sda 2>&1 | grep -i scheduler
60-ioscheduler.rules:2 ATTR '/sys/block/sda/queue/scheduler' writing 'mq-deadline'
Confirm it survives a reboot. This is the only test that matters for persistence:
sudo reboot
After it comes back, re-run lsblk -d -o NAME,ROTA,SCHED. If the values match, the rule is doing its job.
Troubleshooting
- The scheduler you want is not in the list.
cat /sys/block/sda/queue/schedulershows[none] mq-deadlinewith nobfq— the module is not loaded. Runsudo modprobe bfq(the kyber module is namedkyber-iosched) and read the file again. To load it at boot, add the module name to a file under/etc/modules-load.d/. Ifmodprobefails withModule bfq not found, the kernel was built without it; checkgrep -i bfq /boot/config-$(uname -r). - The udev rule applies at boot but not when you reload it. Almost always a missing
changeaction. A rule with onlyACTION=="add"never fires for a disk that already exists, becauseudevadm triggeremitschangeevents. UseACTION=="add|change"and re-runsudo udevadm control --reload. echointo the sysfs file returns “Invalid argument”. The name is misspelled or the module for it is not loaded — sysfs only accepts a name that appears in the file’s own list. It also fails if you are writing to a partition (/sys/block/sda1/...does not exist) or to a device-mapper target that has no scheduler of its own.- The setting reverts after a while on its own. Something else is managing it.
tunedon RHEL-family systems sets schedulers through its profiles, and so do some vendor tuning packages. Checktuned-adm active, then either change the profile or accept it and drop your udev rule rather than fighting over the same file. - You changed the scheduler and nothing got faster. That is the common outcome, and it is information. Before blaming the scheduler, establish where the time is actually going — diagnose a disk I/O bottleneck with iostat walks through the service-time and queue-depth numbers that tell you whether the device is saturated at all.
When this is the wrong approach
Scheduler tuning is a small lever, and it is often the wrong one.
- On a cloud VM it barely matters. The guest’s block layer sees a virtio device backed by the hypervisor’s own queueing and, usually, network-attached storage several hops away. Your guest scheduler reorders requests that get reordered again downstream. Leave it at whatever the distro image chose, spend the effort on volume type and IOPS provisioning, and move on.
- When the real problem is elsewhere. Sustained high iowait usually means too little RAM for the working set, a failing disk, or an application doing synchronous small writes. Start from why iowait spiked and what to do about it, not from
/sys/block. A scheduler change cannot make a disk that is at 100% utilisation any faster. - On a database host, before checking the storage stack above it. Filesystem mount options, the barrier and flush behaviour, and the database’s own I/O configuration all sit between the query and the scheduler, and each has more room to move.
- When you cannot measure the result. If you have no before-and-after
fiorun and no latency histogram from the application, you are copying a stranger’s configuration onto hardware they never saw. Changing nothing is better than changing something you cannot evaluate.
The authoritative references are the kernel’s block layer documentation, which documents the schedulers and every sysfs queue attribute, and the kernel admin guide for the boot parameters and module loading around them.
If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.