Diagram of the chain from a library rescan to a full XFS journal, and the four levers to fix it
|

How-to: a healthy disk that paralyses the server, investigating write saturation

A healthy disk can still freeze a server. Measure what it does, read the XFS journal, find the backlog and apply the levers, from noatime to the scheduler.

One October evening, several WordPress sites on my server stopped answering. No 500 error, nothing in the logs: requests that never completed. MariaDB no longer answered a plain connection. The disk was healthy, SMART reported nothing, neither did the kernel. And yet everything was waiting for the disk. The XFS journal turned out to be the bottleneck.

This tutorial walks through the investigation step by step, with the tools that made sense of it: knowing who waits for what, measuring what a disk really does, reading the XFS journal state, and picking the right levers (I/O scheduler, priorities, mount options) rather than guessing. The server: Rocky Linux 10, two 2 TB spinning disks combined into one LVM volume, an XFS filesystem for data.

Diagram of the chain from a library rescan to a full XFS journal, and the four levers to fix it
From a harmless upgrade to every write waiting on the XFS journal.

The symptom: nothing crashes, everything waits

The first question with a “slow” server is whether it lacks CPU, memory or I/O. The fastest way is to look at processes in D state (uninterruptible sleep): they wait for I/O and can’t even be killed. A few, briefly, is normal; dozens, for long, is saturation. The wchan column gives the kernel function each one is blocked in, and that’s often the key:

ps -eo pid,stat,etime,wchan:28,comm | awk '$2 ~ /D/'
    974 D     2-05:37:15 rq_qos_wait                  xfsaild/dm-0
 536618 D          25:43 xlog_state_get_iclog_space   kworker/u32:7+xfs-cil/dm-0
 542795 D          20:46 flush_workqueue              kworker/3:1+xfs-inodegc/dm-0
 553713 D          12:08 xfs_buf_lock                 rsync
  • xfsaild: the daemon that writes modified XFS metadata to disk, blocked in rq_qos_wait, i.e. held back by the kernel’s write throttling because the disk answers too slowly;
  • xfs-cil: the worker that commits transactions into the journal, blocked in xlog_state_get_iclog_space: it waits for room in the journal;
  • rsync (or any application process) blocked on xfs_buf_lock: it waits for a metadata buffer locked by the previous chain.

The message is clear: it’s not one process being slow, it’s the filesystem waiting for its journal, which waits for the disk.

The five indicators to know

IndicatorWhere to read itWhat it tells you
processes in D stateps -eo stat,wchanwho waits for the disk, and on what exactly (wchan)
in-flight requests per disk/sys/block/sdX/inflightrequests sent to the disk and not finished yet
utilisation, latency/proc/diskstats, iostat -xis the disk saturated, and at what cost per write
XFS journal fill/sys/fs/xfs/<dev>/log/is the filesystem waiting for room in its journal
hardware healthsmartctl -A, dmesgreallocated sectors, errors, link resets

Step 1: rule out a hardware fault

dmesg -T | grep -iE 'ata|sd[a-z]|I/O error|reset|timeout|xfs'
smartctl -H /dev/sda
smartctl -A /dev/sda | grep -E 'Reallocated|Pending|Uncorrect|CRC'

No errors, no link resets, zero reallocated or pending sectors: the disk works. This step is essential before any tuning. A dying disk slows down the same way, because it retries every hard read internally; tuning the scheduler of a dying disk wastes precious time.

Step 2: measure what the disk does

iostat -x (sysstat package) gives everything you need, but it isn’t always installed and can itself hang. The raw counters in /proc/diskstats are enough: field 8 counts completed writes, field 10 sectors written, field 11 time spent writing, field 13 time the disk was busy. Two samples five seconds apart give the rates:

a=$(awk '$3=="sda"{print $8,$10,$11}' /proc/diskstats); sleep 5
b=$(awk '$3=="sda"{print $8,$10,$11}' /proc/diskstats)
paste <(echo $a) <(echo $b) | awk '{w=($4-$1)/5; kb=($5-$2)/2/5;
  printf "writes/s %.0f  KB/s %.0f  KB/write %.1f  ms/write %.1f\n", w, kb, kb/w, ($6-$3)/($4-$1)}'
# writes/s 329  KB/s 5296  KB/write 16.1  ms/write 57.7

The picture becomes readable: about 330 writes per second, 16 KB each, at nearly 60 ms apiece, on a disk 90% busy. A 7,200 rpm spinning disk handles 100 to 200 random operations per second; beyond that, every request queues. Throughput, meanwhile, is laughable (5 MB/s): it’s not volume that saturates, it’s the number of small scattered writes. And that’s exactly the profile of filesystem metadata.

It remained to find out who was writing. The write_bytes field of /proc/<pid>/io gives what each process wrote; sampled twice, no process explained the volume. Normal: metadata writes are done by kernel threads (XFS, flush workers), on nobody’s behalf.

The same disks on an ordinary day

Numbers mean more with a reference point. Here is the same server on 2 November 2026, a quiet morning, measured over ten seconds. sysstat isn’t installed there, so the figures come straight from /proc/diskstats, which is where iostat reads them too:

dev        r/s     w/s    wkB/s  r_await  w_await   aqu  %util
sdb        0.0    54.0      121      0.0     11.4  0.88   27.1
sda        0.0    41.7      178      0.0      5.5  0.36   14.3
dm-0       0.0    72.6      267      0.0     12.1  0.88   38.8

# findmnt -no OPTIONS /data
rw,noatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota
# xfs_info /data | grep ^log
log      =internal log           bsize=4096   blocks=225409, version=2
# cat /sys/block/sda/queue/scheduler
none [mq-deadline] kyber bfq
  • About 70 writes per second at 12 ms, against 330 at nearly 60 ms during the incident: the disks spend a third of their time busy instead of nine tenths. Nothing is waiting in line (aqu under 1).
  • No reads at all: everything read is already in the page cache. On this kind of server, a sudden rise in reads is often the first sign that memory is short.
  • dm-0 is the logical volume holding /data, spread over the two disks: its %util is not the sum of the two, it’s the share of time at least one request was in flight on the volume.
  • noatime is now in the mount options: reading a file no longer writes its access time. That alone removed a whole category of writes after the incident.
  • An 880 MB journal (225 409 blocks of 4 KB): comfortably sized for a 3.6 TB filesystem.
  • mq-deadline on rotating disks (rotational=1): it gives every request a deadline, so reads don’t wait indefinitely behind a long queue of writes.

Step 3: read the XFS journal

XFS is a journaling filesystem: every metadata change (creating a file, changing permissions, updating an access time) is first written to a circular journal, then carried over to its final place in the background. If changes arrive faster than they’re carried over, the journal fills. When it’s full, it blocks every new transaction, so every write on the filesystem, including the database’s fsync.

The kernel exposes the journal’s head (where we write) and tail (what hasn’t been carried over yet) in /sys:

D=/sys/fs/xfs/dm-0/log
for i in 1 2 3; do echo "head=$(cat $D/log_head_lsn) tail=$(cat $D/log_tail_lsn)"; sleep 4; done
# head=136:1560506 tail=135:1562937
# head=136:1560762 tail=135:1562937
# head=136:1560792 tail=135:1562937

Each value is a cycle and a position in 512-byte sectors. Here the head is on cycle 136, the tail on cycle 135, 2,400 sectors apart in a journal of about 1.8 million (xfs_info gives its size): the journal is over 99% full, and the tail doesn’t move for thirty seconds. Everything that wants to write to /data waits.

XFS’s internal statistics then tell what kind of work is going on. Compared five seconds apart, they showed zero new transactions committed, but thousands of inodes being carried over (push_ail, icluster): the filesystem was draining a huge backlog at the disk’s pace.

S=/sys/fs/xfs/dm-0/stats/stats
grep -E '^(trans|push_ail|icluster|attr|dir) ' $S > /tmp/a; sleep 5
grep -E '^(trans|push_ail|icluster|attr|dir) ' $S > /tmp/b
paste -d' ' /tmp/a /tmp/b    # compare column by column

Step 4: find what created the backlog

Such a backlog comes from a burst of metadata changes. The cause was a music server, Navidrome, freshly upgraded: its new version rewrote its whole database, then reread the entire music library. Reading shouldn’t write anything… except the access time.

By default Linux mounts filesystems with relatime: a file’s last access time (atime) is only updated if it’s older than its modification time or more than 24 hours old. It’s a good everyday compromise. But an application that suddenly rereads tens of thousands of files it hadn’t read for a day modifies as many inodes: as many journal transactions, as many small scattered writes to carry over. On a spinning disk, that’s saturation.

Once the application was stopped, the journal tail started moving again, and within about ten minutes everything was back to normal: 23 writes per second, 7% busy, empty journal.

The levers, from most to least effective

1. Remove useless writes: noatime

If no application uses access times (almost always the case on a server), the noatime mount option removes all these writes. It applies live, without unmounting:

mount -o remount,noatime /data
# then in /etc/fstab, to make it permanent:
/dev/mapper/vg-data  /data  xfs  defaults,noatime  0 0

A few rare tools use atime (some mbox mail clients, cleanup scripts for “files not read for X days”): check first. The lazytime option is a middle ground: times stay exact in memory but are only written to disk in batches.

2. Put background tasks behind the others: priorities

# /etc/systemd/system/navidrome.service (excerpt)
[Service]
Nice=10
IOSchedulingClass=idle

Nice=10 lowers CPU priority; IOSchedulingClass=idle only gives the service disk access when nobody else wants it. It’s ideal for an indexer, a backup, a scan. Two limits to know: the idle class is only really honoured by schedulers that handle priorities (bfq, and mq-deadline to a lesser extent), and it only applies to writes made by the process itself. Metadata updates carried over later by kernel threads, such as access times, escape it. That’s why the first lever remains the most effective.

After changing the unit, check that the running process really has the new values, without trusting systemctl show, which reads the file:

ionice -p $(systemctl show -p MainPID --value navidrome)
# idle
ps -o ni= -p $(systemctl show -p MainPID --value navidrome)
# 10

3. Choose the scheduler knowingly

SchedulerPrincipleFor whom
noneno sorting, requests go out in orderNVMe drives, which manage their own queues
mq-deadlinesorts by position, guarantees a maximum delay, separates reads and writesdefault for SATA disks; good general choice
bfqfair bandwidth sharing between processes, honours priorities closelydesktops, mixed servers on slow disks
kybertwo queues with latency targetsfast SSDs, rarely useful
cat /sys/block/sda/queue/scheduler
# none [mq-deadline] kyber bfq
cat /sys/block/sda/queue/wbt_lat_usec
# 75000

The scheduler changes live (echo bfq > /sys/block/sda/queue/scheduler) and is made permanent with a udev rule. But don’t change it on a hunch: measure. Run a representative load (a file copy, an fio job mimicking the database) with each scheduler, and compare the latency of other applications meanwhile, not just the test load’s throughput. On a server mixing a database and background jobs on spinning disks, bfq often protects interactive requests better, at the cost of a little more CPU.

wbt_lat_usec is the writeback throttling latency target: when writes exceed 75 ms, the kernel slows background writes to protect reads. That’s what was holding xfsaild in rq_qos_wait. It does its job; lowering or disabling it doesn’t create extra capacity.

4. Don’t undersize the journal

A bigger XFS journal absorbs longer bursts before blocking. Its size is set at creation (mkfs.xfs -l size=…) and can’t be changed afterwards. Keep it in mind for the next data filesystem on slow disks.

What to monitor to see it coming

  • disk utilisation (node_disk_io_time_seconds_total in node_exporter): above 80% for more than ten minutes, something is saturating;
  • the average time per write, which rises long before applications time out;
  • the number of processes in D state (node_procs_blocked);
  • and on the application side, database response time: it’s often the first to scream.

In short

A healthy disk can paralyse a server. The method fits in four questions: who waits (D state and wchan), is the disk sick (SMART, dmesg), what is it really doing (/proc/diskstats), and why (the filesystem’s journal and statistics). The answers almost always lead to a write that could have been avoided.


This post is part of a series of sysadmin tutorials (tag “how-to”).
Series “How-to”, tutorial 16/77. · ← Previous tutorial · Next tutorial → (coming 7 Dec) · Version française

Related articles

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *