28.4. Diagnosing Storage and Filesystem Performance

Storage measurements are dominated by three things: the workload's access pattern, the cache in front of the device, and the queueing layer between the application and the media. The same disk can look fast for sequential writes, slow for synchronous small writes, and terrible for metadata-heavy operations. The goal is to measure the workload that matters, not the easiest benchmark.

Every example in this section reads and writes a disposable disk rather than the guest's root filesystem: on the lab hosts that is the 2 GiB /dev/vdb, which Section 28.4.4 identifies, formats, and mounts at /mnt/perfdisk. Prepare that disk first - the captures in Sections 28.4.1 through 28.4.3 assume it is mounted and that john owns /mnt/perfdisk/john.

28.4.1. Throughput, Latency, Queue Depth, and Device Utilization

iostat -x reports rates and the derived latency and queue values. The measurement below was taken while the 30-second fio random-write load described in Section 28.4.2 was running on the test disk; the job file itself is introduced in Section 28.4.5. Selected output is shown. Read the columns as a chain: r/s and w/s are completed operations, rkB/s and wkB/s are throughput, r_await and w_await are average latency per request, aqu-sz is the average queue length, and %util is the fraction of time the device had at least one request in flight:

$ sudo iostat -xz 1 2
Linux 6.12.86+deb13-amd64 (perf1)   11/24/26    _x86_64_    (2 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           7.17    0.00    2.46   18.04    0.47   71.86

Device            r/s     rkB/s   rrqm/s  %rrqm r_await rareq-sz     w/s     wkB/s   wrqm/s  %wrqm w_await wareq-sz     d/s     dkB/s   drqm/s  %drqm d_await dareq-sz     f/s f_await  aqu-sz  %util
vda              8.09    390.06     4.21  34.24   15.30    48.20   15.73    578.53    37.08  70.21  391.79    36.77    0.25   2298.62     0.00   0.00    0.12  9160.65    2.01  141.95    6.57  21.96
vdb             12.54  12275.45     0.02   0.17    6.64   979.25  404.95   3370.78    14.57   3.47    3.57     8.32    0.00   1893.87     0.00   0.00    0.10 699052.00    0.07 1571.11    1.64  13.07

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           9.74    0.00   33.85   14.87    9.74   30.77

Device            r/s     rkB/s   rrqm/s  %rrqm r_await rareq-sz     w/s     wkB/s   wrqm/s  %wrqm w_await wareq-sz     d/s     dkB/s   drqm/s  %drqm d_await dareq-sz     f/s f_await  aqu-sz  %util
vda             121.00   3008.00   224.00  64.93    2.64    24.86   86.00    392.00     2.00   2.27    0.21     4.56    0.00      0.00     0.00   0.00    0.00     0.00    0.00    0.00    0.34  71.20
vdb               0.00      0.00     0.00   0.00    0.00     0.00 16156.00  64628.00     0.00   0.00    0.19     4.00    0.00      0.00     0.00   0.00    0.00     0.00    1.00 13384.00   16.44 100.40

The second interval catches the test device at 100.40 percent utilization with 16,156 write completions per second and a queue length of 16.44. The first interval is mostly the earlier baseline. A value slightly above 100 can occur because the device serviced overlapping requests during the interval. A %util near 100 with a shallow queue means the device is busy but may still be responsive; a deep queue with high await means requests are waiting. Neither number alone is a verdict.

Storage path

Figure 28.4. Conceptual storage path. iostat sees the block device; the page cache, filesystem journal, and host cache sit above or below that observation point and can dominate the result.

28.4.2. Using iostat, pidstat, and Per-Process I/O Measurements

iostat says which device is busy; pidstat -d says which process is responsible. To sample while the load runs, save the job file from Section 28.4.5 with runtime raised to 30 as fio-load.fio, so the six-second file used for the scheduler comparison stays unchanged. Start the load as a transient unit run as john. The transient unit does not inherit the shell's working directory - it starts in / - so the job file needs its absolute path:

$ sudo systemd-run --unit=io-load --uid=john --collect fio --output-format=json --output=/home/john/debian-handbook/performance/fio-load.json /home/john/debian-handbook/performance/fio-load.fio
Running as unit: io-load.service; invocation ID: cbc26d71b1f74a1cb6dc2e33f15ec624

The fio report goes to the JSON file named by --output, so the terminal shows only the unit line; the load stops itself after 30 seconds, and --collect removes the unit afterwards. Run the sampling commands during that window. During a 30-second run on the test disk, selected output is shown:

$ sudo pidstat -d 1 2
Linux 6.12.86+deb13-amd64 (perf1)   11/24/26    _x86_64_    (2 CPU)

00:16:11      UID       PID   kB_rd/s   kB_wr/s kB_ccwr/s iodelay  Command
00:16:12        0       270      0.00     27.18      0.00       0  systemd-journal
00:16:12     1001     31083      0.00  75794.17      0.00       0  fio

00:16:12      UID       PID   kB_rd/s   kB_wr/s kB_ccwr/s iodelay  Command
00:16:13      102     29650    128.00     12.00      0.00       0  prometheus
00:16:13     1001     31083      0.00  77116.00      0.00       0  fio

Average:      UID       PID   kB_rd/s   kB_wr/s kB_ccwr/s iodelay  Command
Average:        0       270      0.00     13.79      0.00       0  systemd-journal
Average:      102     29650     63.05      5.91      0.00       0  prometheus
Average:     1001     31083      0.00  76445.32      0.00       0  fio

The fio process is writing about 75 MiB per second (76,445 KiB/s on average). iodelay is the time the task spent waiting for I/O during the interval; a high value with low throughput points to storage latency, while a low value with high throughput points to a healthy device. pidstat -d reports per-process block I/O, not filesystem or network I/O, so a process that is slow on a remote filesystem may not show the wait here. Correlate with iostat and the filesystem mount.

28.4.3. Filesystem Space, Metadata Workloads, and Synchronous Writes

Space and inode exhaustion are different failures. df -h reports blocks and df -i reports inodes:

$ df -h /mnt/perfdisk
Filesystem      Size  Used Avail Use% Mounted on
/dev/vdb        2.0G  540K  1.8G   1% /mnt/perfdisk
$ df -i /mnt/perfdisk
Filesystem     Inodes IUsed  IFree IUse% Mounted on
/dev/vdb       131072    13 131059    1% /mnt/perfdisk

A filesystem can have plenty of free blocks and no free inodes. Creating many small files measures the metadata path:

$ python3 create-files.py 2000 /mnt/perfdisk/john/meta
created=2000 elapsed=0.152s
$ df -i /mnt/perfdisk
Filesystem     Inodes IUsed  IFree IUse% Mounted on
/dev/vdb       131072  2018 129054    2% /mnt/perfdisk

The create-files.py helper writes the files and reports the elapsed time:

#!/usr/bin/env python3
import os
import sys
import time

count = int(sys.argv[1]) if len(sys.argv) > 1 else 2000
root = sys.argv[2] if len(sys.argv) > 2 else "/mnt/perfdisk/john/meta"
os.makedirs(root, exist_ok=True)
start = time.monotonic()
for index in range(count):
    with open(os.path.join(root, f"file-{index:05d}.txt"), "w") as handle:
        handle.write("x\n")
print(f"created={count} elapsed={time.monotonic() - start:.3f}s")

Two thousand files consumed about two thousand inodes. On a filesystem with a small inode pool, a cache or mail spool can fail long before the block count looks dangerous. df -i belongs in the routine capacity check.

Synchronous writes are the other common surprise. dd without a flush can end before the data reaches stable storage; conv=fdatasync waits for the data, and oflag=direct bypasses the page cache. The options used here are:

Option Description
if=, of= Input and output files or devices.
bs=, count= Block size and number of blocks.
conv=fdatasync Flush data to stable storage before dd exits.
oflag=direct Use direct I/O and bypass the page cache.
status=none Suppress the transfer summary.

The writes below run in john's directory on the test disk; the cd prints nothing:

$ cd /mnt/perfdisk/john

The synchronous write is measured with:

$ time dd if=/dev/zero of=sync-test.img bs=1M count=128 conv=fdatasync status=none

real    0m9.527s
user    0m0.000s
sys 0m0.374s

The same 128 MiB, still from /mnt/perfdisk/john, with direct I/O is much faster in this run:

$ time dd if=/dev/zero of=direct-test.img bs=1M count=128 oflag=direct status=none

real    0m0.375s
user    0m0.000s
sys 0m0.032s

The difference does not mean the device is faster in one mode. The synchronous run waited for the host to flush; the direct run still traversed the virtual device and the host cache. A direct write can be fast because the host absorbs it, while a later flush or a power loss reveals the cost. sync flushes dirty pages globally and normally produces no output; it returns when the writeback has been submitted, not necessarily when every physical device has committed. For a single file, conv=fdatasync is a more targeted measurement.

Cache warmth is easy to confirm with fincore. This is a different cache-test.img from the one in Section 28.3.1: the working directory is now the test disk. Write a fresh file:

$ dd if=/dev/zero of=cache-test.img bs=1M count=128 status=none

The write is silent because status=none suppresses the summary. All of its pages are resident:

$ fincore cache-test.img
  RES PAGES  SIZE FILE
  128M 32768  128M cache-test.img

Read the file back:

$ dd if=cache-test.img of=/dev/null bs=1M status=none

This read is also silent. Check the cache again:

$ fincore cache-test.img
  RES PAGES  SIZE FILE
  128M 32768  128M cache-test.img

The resident size is unchanged after the read, so the read was served from memory; a benchmark that reports it as disk throughput is reporting memory bandwidth.

28.4.4. Designing Representative Storage Measurements Without Destroying Data

Never point a write benchmark at a device whose contents matter. The first step is to identify a disposable target. lsblk with the model, serial, filesystem, and mountpoint columns makes the choice explicit:

$ sudo lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS,MODEL,SERIAL
NAME    SIZE TYPE FSTYPE MOUNTPOINTS MODEL SERIAL
vda     100G disk
└─vda1  100G part ext4   /
vdb       2G disk

The vdb disk is the 2 GiB volume attached for this chapter; it has no filesystem and no mountpoint. If the output had shown a mounted filesystem or a model/serial belonging to production storage, stop. The following command destroys the current contents of /dev/vdb:

$ sudo mkfs.ext4 -F -L perfdata /dev/vdb
Discarding device blocks:      0/524288             done
Creating filesystem with 524288 4k blocks and 131072 inodes
Filesystem UUID: 58a082e8-789c-42b2-9383-54149dcc34f8
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912

Allocating group tables:  0/16             done
Writing inode tables:  0/16             done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information:  0/16             done

mke2fs 1.47.2 (1-Jan-2025)

Mount it at a dedicated path. Create the mountpoint; the command is silent:

$ sudo mkdir -p /mnt/perfdisk

Mount the filesystem by its label, also silently:

$ sudo mount LABEL=perfdata /mnt/perfdisk

Give john a subdirectory to own:

$ sudo install -d -o john -g john /mnt/perfdisk/john

The last command prints nothing either; verify the result with df:

$ df -h /mnt/perfdisk
Filesystem      Size  Used Avail Use% Mounted on
/dev/vdb        2.0G  540K  1.8G   1% /mnt/perfdisk

Three ways to obtain a disposable target are compared in the table. Choose based on what the measurement must represent and how much data-loss risk is acceptable.

Target What it measures Data-loss risk Limitations
Spare disk or partition Device and filesystem path closest to production Destroys the target Requires a real spare device; size and media differ from production
File on an existing filesystem Filesystem and page-cache behavior for one workload Low if bounded to a workspace file Shares the device with other data; file size and fragmentation affect results
Loop-mounted file Isolated filesystem for capacity or functional tests Low; remove the backing file Extra loop layer and host cache; not representative of raw device latency

The chapter uses the spare vdb for the throughput tests and a loop-mounted file for the capacity alert. A file in john's home would be acceptable for a small functional test but would compete with the root filesystem.

28.4.5. Comparing I/O Schedulers and Limits While Accounting for Cache and Host Effects

The test disk exposes two schedulers, none and mq-deadline. The fio job writes 4 KiB blocks at queue depth 16 for six seconds. The relevant fio options are:

Option Description
filename, size File and total working-set size for the job.
fallocate=native Preallocate the file with the filesystem's native method.
direct=1 Use direct I/O rather than the guest page cache.
ioengine=libaio, iodepth=16 Submit asynchronous I/O with up to 16 requests in flight.
bs=4k, rw=randwrite Use 4 KiB random writes; randread and read are also useful.
runtime, time_based Run for a fixed time rather than a fixed byte count.
output-format=json Write machine-readable results for jq summaries.

The job file is:

[global]
filename=/mnt/perfdisk/john/fio-test.dat
size=256M
fallocate=native
direct=1
ioengine=libaio
iodepth=16
bs=4k
rw=randwrite
time_based=1
runtime=6
group_reporting=1

[randwrite]

Save it as fio-randwrite.fio in john's performance workspace - the same directory that holds fio-load.fio in Section 28.4.2 - and run the jobs from there; the cd in Section 28.4.3 left the shell in /mnt/perfdisk/john. Run it under the default none scheduler and summarize the JSON output:

$ fio --output-format=json --output=fio-none.json fio-randwrite.fio

The command is silent because the report goes to the file. Summarize the fields that matter:

$ jq -r '.jobs[0] | "iops=\(.write.iops|floor) bw=\(.write.bw|floor)KiB/s clat_mean=\((.write.clat_ns.mean/1000)|floor)us p99=\((.write.clat_ns.percentile["99.000000"]/1000)|floor)us"' fio-none.json
iops=316 bw=1266KiB/s clat_mean=50456us p99=2277us

Switch the scheduler by writing its name to the sysfs queue file. This is a root operation; the command is silent. In the root shell:

# echo mq-deadline > /sys/block/vdb/queue/scheduler

The brackets in the following cat show the active choice:

# cat /sys/block/vdb/queue/scheduler
none [mq-deadline]

Run the same job again and summarize:

$ fio --output-format=json --output=fio-deadline.json fio-randwrite.fio
$ jq -r '.jobs[0] | "iops=\(.write.iops|floor) bw=\(.write.bw|floor)KiB/s clat_mean=\((.write.clat_ns.mean/1000)|floor)us p99=\((.write.clat_ns.percentile["99.000000"]/1000)|floor)us"' fio-deadline.json
iops=4053 bw=16214KiB/s clat_mean=3886us p99=1843us

Restore the original scheduler and measure again. The write is silent:

# echo none > /sys/block/vdb/queue/scheduler
# cat /sys/block/vdb/queue/scheduler
[none] mq-deadline
$ fio --output-format=json --output=fio-none-reverted.json fio-randwrite.fio
$ jq -r '.jobs[0] | "iops=\(.write.iops|floor) bw=\(.write.bw|floor)KiB/s"' fio-none-reverted.json
iops=19914 bw=79658KiB/s

The three runs do not form a clean ranking. mq-deadline produced 4,053 IOPS, but the reverted none run produced 19,914 IOPS, more than sixty times the first none run's 316. Host load and cache state moved the result more than the scheduler did. A defensible comparison would repeat each configuration several times, randomize the order, and report the distribution, not one run. The chapter shows the raw runs because that is what an investigator often has; the honest conclusion is that this experiment did not isolate a scheduler effect.

Scheduler comparison variance

Figure 28.5. Three single fio runs from the same measurement session. The reverted baseline is faster than the first baseline, so the difference cannot be attributed to the scheduler without repetition and control of host load.

Scheduler Intended strength Cost or limitation
none Minimal overhead; passes requests directly to the device queue No merging or ordering at the block layer; relies on the device
mq-deadline Bounded latency by ordering requests and limiting starvation Extra queue processing; not a substitute for enough device queue depth

The scheduler choice is device- and workload-specific. On a modern NVMe device the kernel may expose only none because the device has many hardware queues; on a virtual disk the host and the qcow2 layer can dominate. Check what the device actually offers before assuming a scheduler is active.

Cgroup I/O limits add a second control point. IOReadBandwidthMax caps reads for a unit. Measure the control first, with no limit applied:

$ sudo systemd-run --unit=io-unlimited --uid=john --collect --wait fio --name=read --filename=/mnt/perfdisk/john/fio-test.dat --size=256M --direct=1 --ioengine=libaio --iodepth=16 --bs=1M --rw=read --time_based=1 --runtime=6 --output-format=json --output=/home/john/debian-handbook/performance/io-unlimited.json
Running as unit: io-unlimited.service; invocation ID: c19d0a69da2e48efb7090618525a83cc
Finished with result: success
Main processes terminated with: code=exited, status=0/SUCCESS
Service runtime: 6.388s
CPU time consumed: 861ms
Memory peak: 24.8M (swap: 0B)

With --wait, systemd-run prints this short summary when the command finishes; the fio report itself goes to the JSON file:

$ jq -r '.jobs[0] | "bw=\(.read.bw|floor)KiB/s"' io-unlimited.json
bw=2444733KiB/s

Now repeat the same read under a 20 MiB/s cap:

$ sudo systemd-run --unit=io-limit --uid=john --collect --wait --property=IOReadBandwidthMax='/dev/vdb 20M' fio --name=read --filename=/mnt/perfdisk/john/fio-test.dat --size=256M --direct=1 --ioengine=libaio --iodepth=16 --bs=1M --rw=read --time_based=1 --runtime=6 --output-format=json --output=/home/john/debian-handbook/performance/io-limit.json
Running as unit: io-limit.service
Finished with result: success
Main processes terminated with: code=exited, status=0/SUCCESS
Service runtime: 9.548s
CPU time consumed: 156ms
Memory peak: 24.8M (swap: 0B)
$ jq -r '.jobs[0] | "bw=\(.read.bw|floor)KiB/s"' io-limit.json
bw=19533KiB/s

The capped run stayed just below the 20,000 KiB/s ceiling and consumed almost no CPU - the cgroup throttled the requests before the device saw them. The control run reached 2,444,733 KiB/s - roughly 125 times the cap - because the host served the file from its own cache, on the same disk and in the same session. The cap is a useful policy control, but the comparison also shows why a storage number needs its cache state stated. This is the central lesson of storage measurement: state the cache state, repeat the control, and do not present a single pair of runs as a device capability.