fio will tell you what a disk actually does, and it will just as happily hand you a number that means nothing at all. The distance between those two outcomes is about five options. This guide covers how to pick the job file that answers the question you are actually asking — random read IOPS, sequential throughput, or fsync latency for a database write-ahead log — how to run it without shredding a filesystem you cared about, and how to read the output so that IOPS, bandwidth and the completion-latency percentiles each mean what you think they mean.
What you’ll accomplish
- Install fio, confirm which ioengines your kernel and build actually support, and identify a benchmark target without guessing.
- Write and run three job files that answer three different questions, instead of one job file you re-run and misinterpret.
- Bypass the page cache with
direct=1, precondition an SSD so the numbers reflect steady state, and run long enough that they hold. - Read the output correctly: what
IOPS=means versusBW=, whyclatpercentiles matter more than the average, and howiodepthandnumjobsdiffer. - Emit JSON and pull the p99 out with
jqso you can track the same number across firmware and kernel changes.
Prerequisites
- fio 3.20 or newer. Debian 13 and Ubuntu 24.04 ship 3.3x; Rocky/Alma 9 ship an older 3.3x through EPEL. Anything older than 3.20 has enough option and JSON differences to make copy-pasted job files behave oddly. Check with
fio --version. - Root or
sudofor raw block-device tests. Tests against a file on a mounted filesystem need only write permission on that directory. - The
libaioengine needs fio built against libaio, which every distro package is. Theio_uringengine needs kernel 5.1+ and a fio built against liburing, which is less universal. On kernel 6.6 and newer,io_uringcan also be switched off system-wide via/proc/sys/kernel/io_uring_disabled. - A target you can afford to lose. A write job pointed at
/dev/sdboverwrites the partition table and everything after it. There is no confirmation prompt. - Filesystem caveats.
direct=1is honoured by ext4 and XFS. Btrfs honours it with copy-on-write caveats, and OpenZFS only gained real Direct I/O support in 2.3 — on older ZFS yourdirect=1request is quietly serviced from the ARC. If you are still deciding what to put underneath, choosing a filesystem for production covers the trade-offs.
How it works
A fio job is a synthetic application. It generates I/O requests of a size and pattern you specify, hands them to an ioengine, and times how long each one takes to come back. Everything that makes a benchmark meaningful or meaningless happens between those two points.
Three things in that path deserve attention before you run anything.
The page cache is the default, and it is a liar. Without direct=1, a read that hits the page cache returns from DRAM in a few hundred nanoseconds. Point fio at a 1 GiB file on a machine with 64 GiB of RAM and you will measure memory bandwidth, then attribute it to the disk. direct=1 opens the file with O_DIRECT and skips the cache entirely.
iodepth and numjobs are not interchangeable. iodepth is how many requests one worker keeps outstanding at once, and it only does anything with an asynchronous engine — libaio or io_uring, and libaio only behaves asynchronously when direct=1 is also set. numjobs forks that many independent workers. A sync engine such as psync ignores iodepth completely; parallelism there comes only from numjobs.
Latency is reported in three parts. slat is submission latency — how long it took to hand the request to the kernel. clat is completion latency — submission to completion, which is the device’s contribution. lat is the sum, which is what an application actually experiences. For a queue-depth-1 test the three are nearly identical; at iodepth=64 they diverge sharply, because queueing time is counted in clat.
Step-by-step
- Install fio and confirm the engines exist. The package name is the same everywhere.
sudo apt install fio # Debian, Ubuntu
sudo dnf install fio # Rocky, Alma, Fedora
fio --version
Expected output is a single line naming the version:
fio-3.36
Then confirm the engines you intend to use are compiled in. --enghelp lists every available ioengine:
fio --enghelp | grep -E '^\s+(psync|libaio|io_uring)$'
Success signal: psync and libaio are both listed. If io_uring is missing, your fio was built without liburing — use libaio and move on, the difference at these depths is small.
- Identify the target and prove it is the one you meant. This is the step people skip and then regret. Confirm the device has nothing mounted on it and nothing you care about inside it:
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS /dev/nvme1n1
sudo findmnt --source /dev/nvme1n1
sudo wipefs --no-act /dev/nvme1n1
Success signal: lsblk shows an empty FSTYPE and MOUNTPOINTS, findmnt prints nothing and exits non-zero, and wipefs --no-act reports no signatures. If any of the three disagrees, stop and pick a different target, or benchmark a file on a mounted filesystem instead.
One warning about thin provisioning: on an LVM thin volume, the first write to a block also allocates it, so a first-pass write test measures allocation, not steady-state write. Run the write pass twice and take the second, or benchmark a thick volume. The allocation mechanics are covered in LVM thin snapshot backups.
- Choose the job that matches your question. There is no general-purpose fio invocation. The parameters that answer “how many random IOPS” are the wrong parameters for “how fast can this commit a transaction”.
- Random read IOPS — the datasheet number. Save this as
randread.fio:
[global]
ioengine=libaio
direct=1
time_based=1
runtime=300
ramp_time=30
randrepeat=0
group_reporting=1
filename=/dev/nvme1n1
[randread-4k]
rw=randread
bs=4k
iodepth=64
numjobs=4
Because this job only reads, you can add fio’s own safety interlock, which makes the run abort if any job would write:
sudo fio --readonly randread.fio
Success signal: the run completes after roughly 330 seconds (30 s ramp plus 300 s measured) and prints one read: line for the group, because group_reporting=1 merged the four workers.
- Sequential throughput — the backup and restore number. Large blocks, low depth, one worker. Save as
seqread.fio:
[global]
ioengine=libaio
direct=1
time_based=1
runtime=120
ramp_time=15
group_reporting=1
filename=/mnt/bench/fio-testfile
size=64G
[seqread-1m]
rw=read
bs=1M
iodepth=8
numjobs=1
Note size=64G. A file-based test must be large enough that it cannot sit in RAM and cannot sit in the drive’s own DRAM cache. On a host with 64 GiB of RAM, a 64 GiB file is the floor, not a generous choice. For this job read BW=; the IOPS= figure is just bandwidth divided by 1 MiB and tells you nothing extra.
- Commit latency — the database WAL number. This one deliberately does not use
direct=1, because PostgreSQL and MySQL write buffered and then callfdatasync(). What you want to measure is that flush. Save aswal.fio:
[global]
ioengine=psync
direct=0
time_based=1
runtime=120
ramp_time=10
group_reporting=1
directory=/var/lib/bench
size=4G
[wal-fdatasync]
rw=write
bs=4k
iodepth=1
numjobs=1
fdatasync=1
fdatasync=1 issues an fdatasync() after every single write. The IOPS number here is meaningless in isolation — it is simply one divided by the flush latency. Read the clat percentiles instead, and expect a number in the tens of microseconds on enterprise NVMe with power-loss protection, and in the low milliseconds on consumer hardware that honours the flush.
- Precondition before you trust any write number. A fresh or freshly trimmed SSD returns zeros for unwritten blocks without touching the media, and has an empty over-provisioning pool, so early write numbers are fantasy. Fill it, then beat on it until the garbage collector reaches steady state:
sudo blkdiscard /dev/nvme1n1
sudo fio --name=fill --filename=/dev/nvme1n1 --rw=write --bs=1M \
--ioengine=libaio --iodepth=32 --direct=1 --loops=2 --group_reporting
sudo fio --name=precond --filename=/dev/nvme1n1 --rw=randwrite --bs=4k \
--ioengine=libaio --iodepth=64 --numjobs=4 --direct=1 \
--time_based --runtime=3600 --group_reporting
Success signal: during the second command, the reported IOPS starts high and settles to a lower plateau. That plateau is the number worth quoting. If it is still falling when the hour is up, the drive has not reached steady state and needs longer.
Validate it works
First, confirm the device really saw the I/O rather than the cache. In a second terminal, while a job runs:
iostat -x 5 /dev/nvme1n1
The r/s or w/s column should be close to the IOPS fio reports, and %util should be near 100 for a saturating job. If iostat shows almost no activity while fio reports huge numbers, direct=1 is not in effect.
Second, check inside fio’s own output that the run did what you asked. The IO depths : line shows the distribution of outstanding requests:
IO depths : 1=0.1%, 2=0.1%, 4=0.1%, 8=0.1%, 16=0.1%, 32=0.1%, >=64=99.9%
If you asked for iodepth=64 and this line reads 1=100.0%, the depth never materialised — see troubleshooting below.
Third, check that throughput was stable rather than averaged across a cliff. The per-job bw line reports minimum, maximum and standard deviation over the run. A min far below avg means the drive degraded partway through and your average is hiding it.
Finally, capture the run as JSON so it is comparable later:
sudo fio --output-format=json --output=randread.json randread.fio
jq '.jobs[0].read | {iops, bw_kibs: .bw, p99_us: (.clat_ns.percentile."99.000000"/1000)}' randread.json
Success signal: jq prints a three-key object. Store that alongside the kernel version, firmware revision and scheduler setting — a percentile without its context is not a data point.
Troubleshooting
The numbers are physically impossible. A SATA SSD reporting 4 GB/s, or an NVMe drive reporting 3 million 4k IOPS, means you measured RAM. Confirm direct=1 is in [global] and not just in one job section, confirm the target file is larger than system RAM, and confirm the filesystem honours O_DIRECT. On older OpenZFS the option is accepted and ignored, which produces exactly this symptom.
fio: engine libaio not loadable or an unknown engine error. The fio binary was built without that engine. Install the distro package rather than a hand-built binary, or fall back to ioengine=psync and raise numjobs to get parallelism. For io_uring specifically, also check cat /proc/sys/kernel/io_uring_disabled on kernel 6.6+ — a value of 2 blocks the syscall for everyone.
IOPS falls off a cliff two minutes into the run. Consumer SSDs write into a fast SLC cache and collapse to native TLC or QLC speed when it fills. This is real behaviour, not a measurement error, and it is why runtime=300 and preconditioning matter. Add --write_bw_log=bw to a run and plot the log to see exactly where the knee is.
IO depths : 1=100.0% despite iodepth=64. Either the ioengine is synchronous (psync, sync, pvsync), or you set direct=0 with libaio — buffered libaio falls back to synchronous behaviour and silently ignores the depth. Set ioengine=libaio together with direct=1, or switch to io_uring.
Latency looks fine but the cpu line shows sys=99%. You are benchmarking the CPU, not the disk. This happens with very high numjobs on small block sizes. Reduce numjobs to the number of physical cores at most, and consider cpus_allowed to keep workers off the cores handling device interrupts.
When this is the wrong approach
fio measures a synthetic pattern. Uniform random 4k reads across a whole device are a stress test, not a workload — real databases have hot ranges, real filesystems have metadata, and real applications have think time between requests. If the question is “will this host run my database well”, the honest answer comes from pgbench, sysbench or a replay of your own traffic. fio tells you the ceiling; it does not tell you where you sit under it.
On cloud block storage, you are usually benchmarking a throttle rather than media. Provisioned-IOPS volumes, burst credit buckets and instance-level throughput caps produce a flat line that says nothing about the underlying hardware, and burst credits make short runs look far better than the steady state you will live with. Run long enough to exhaust the burst.
On shared storage — SAN, Ceph, NFS — a single-client run measures your slice at that moment, including whatever your neighbours were doing. Repeat it at different times of day and treat the spread as the real result.
And fio is not a filesystem metadata benchmark. Creating a million small files or stressing rename() exercises code paths fio barely touches. Reach for a metadata-specific tool there.
Finally, do not run write jobs against production storage to satisfy curiosity. Preconditioning alone writes the device several times over, consuming real endurance. Benchmark hardware you are qualifying, not hardware you are depending on.
The official fio documentation is the reference for every option named here, and the fio source repository carries example job files worth reading before you write your own.
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.