Lesson 9 of 13 · 15m
I/O Latency and the fsync Tax
Buffered writes lie, `fsync` is the real cost, and `iostat` await plus `biolatency` histograms show what averages hide.
A write() returns after copying into the page cache. The data reaches the device later, when flusher threads write back dirty pages — bounded by vm.dirty_ratio/dirty_bytes and the background thresholds. That is why "we wrote it, so it's safe" is false, and it is also why storage latency is invisible when you time the write call: the cost shows up in reads that miss cache, in fsync, and in writeback stalls when the dirty thresholds trip.
The durability tax
fsync is the syscall that pays for durability — it blocks until the device confirms the data. On NVMe that is tens to hundreds of microseconds; on spinning disks, single-digit milliseconds. Call it per record and you have converted asynchronous writeback into synchronous storage latency inside the request path.
Every database solves this identically: group commit. PostgreSQL batches WAL flushes (commit_delay and commit_siblings exist deliberately to trade a little latency for batching), and InnoDB does the same for redo. The alternative — one fsync per commit — caps throughput at 1 / fsync_latency regardless of how fast the CPU is. fdatasync skips the inode metadata update when file size is unchanged, and it is cheaper. O_DSYNC at open time makes every write durable but keeps you paying per write. The real decision is where the durability boundary sits: per request, per batch, or trust writeback and accept the loss window on power failure.
Reading the disk
iostat -xz 1 is the baseline. r_await and w_await give average service time per operation, aqu-sz the average queue depth, %util the fraction of time the device had work outstanding. That last number lies on modern hardware — an NVMe device with deep parallel queues reports 100% util long before saturation. Rising await is the saturation signal, not util.
biolatency-bpfcc prints a per-device histogram of block I/O latency via eBPF — it shows the distribution that iostat's averages hide. A bimodal graph with a fast hump (cache, healthy NVMe) and a slow hump (retries, queueing, a degrading disk) is a diagnosis in one screen. biosnoop-bpfcc shows per-operation latency, opensnoop-bpfcc shows file churn, iotop -o shows who is doing it.
The read side and the direct path
Reads hit the same cache from the other direction: a read() of a cached page is a memcpy, not a disk access — which is why I/O wait only appears on cache misses and first reads. O_DIRECT bypasses the page cache deliberately for engines that do their own caching (databases, VM disk images); it trades the kernel's readahead and write coalescing for predictability, and used casually it makes everything slower while looking honest.
/proc/pressure/io gives the same PSI view as CPU — some/full stall averages for threads blocked on storage — and ioping is a device-level latency probe for a number before the application is involved. Queue tuning (nr_requests, the mq-deadline/none elevator choice on NVMe) comes last: it moves latency by microseconds, while fsync storms move it by milliseconds.
Evidence
The classic application shape: p99 latency tracking a log statement that writes then fsyncs per line — fixed by buffering, not faster disks. At kernel scale, the multiqueue blk-mq rework exists because a single block queue saturated long before the SSDs behind it did; the legacy single-queue path was removed entirely in kernel 5.0.
The practice
iostat -xz 1:awaitandaqu-szbefore%util; 100% util on NVMe is a busy sign, not a full sign.biolatency-bpfccfor the distribution — bimodality beats averages.- Count
fsync/fdatasyncfrequency withstrace -c; batch deliberately, not by accident. opensnoopfinds path churn — the stat/open storm masquerading as disk slowness.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
Your Minecraft Server Isn't Slow, It's Misconfigured
Can't keep up! is not a hardware message. It's the server telling you a tick took longer than 50ms, and almost every cause is a default nobody changed. Here's what actually moves MSPT, with the flags that are now wrong and the setting that isn't where every guide says it is.
Your Minecraft Server Wants Java 25, Not Java 26
Every six months the same thread appears and nobody maps the JVM engineering onto what a Minecraft server actually does. This does — version by version, with the flag most guides still tell you to set that will eventually stop your server from booting.
Your Container Is Running SerialGC and Nobody Told You
You tuned G1 flags for a week. Your pod has one CPU, which means the JVM quietly picked a single-threaded collector at startup and ignored every flag you set. Here is the OpenJDK source that made that decision.
How to Debug Minecraft Server Lag with Spark Profiler (2026 Guide)
Your server dropped to 12 TPS. You copied Aikar's flags. You upgraded Java. Nothing changed. That's because JVM flags don't fix plugin bugs. Here's how to find what's actually killing your tick budget.