Operations 9 min read

How to Safely Benchmark Disk Performance with fio on Linux

This guide explains how to install fio, run various disk performance tests—including random and sequential reads/writes and mixed workloads—while avoiding data loss, and shows how to interpret key metrics such as IOPS, bandwidth, and latency.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Safely Benchmark Disk Performance with fio on Linux

In Linux, the popular tool fio (Flexible I/O Tester) is used to evaluate storage performance by simulating various I/O patterns and workloads.

Typical tests include random write, random read, sequential write, sequential read, and mixed read/write.

Installing and Using fio

fio is not bundled with most Linux distributions and must be installed manually.

# ubuntu
sudo apt install fio

# centos
sudo yum install fio

Warning: testing write performance with fio can easily cause data loss. This occurs when no filename is specified (the test writes directly to the device) or when the specified filename overlaps an existing file.

Without a filename, fio writes directly to the disk, overwriting the filesystem, partition table, and all data.

When the filename matches an existing file, the file's contents are overwritten.

Random Write Performance Test

Without Bypassing Cache

When the OS page cache is used, results may appear artificially high. Using direct I/O provides uncached, realistic disk performance.

fio --name=testfile --directory=/home/ehigh/test_dir --size=1G --rw=randwrite --bs=4k --ioengine=libaio --iodepth=16 --numjobs=1 --runtime=30 --time_based --end_fsync=1

This creates a 1 GB test file in /home/ehigh/test_dir and performs random writes with a 4 KB block size for 30 seconds. --name sets the test file name; omitting it writes directly to the device. --directory sets the file location; if omitted, the current directory is used. --numjobs defines the number of threads (1 for a single‑thread test). --runtime sets the test duration (30 s is typical for quick evaluation). --size specifies the test file size (1 GB is usually sufficient). --rw selects the I/O pattern (randwrite for random writes, randrw for random read/write, read/write for sequential, etc.). --bs sets the I/O block size (4 KB here). --end_fsync=1 forces a sync at the end of the test to ensure data is flushed.

write: IOPS=11.3k, BW=43.0MiB/s
# slat: submit latency (average 2.68 µs)
# clat: completion latency (average 1326.67 µs)
# lat: total latency (average ~168 ms, stddev 167,993.51 µs)
# 99.99th percentile latency = 545 µs
# CPU usage: usr (user space) and sys (kernel space)
# Disk stats: sda ios=2/7271, util=95.63%

Bypassing Cache

Adding the -direct=1 option enables direct I/O, sending data straight between user space and the disk without OS caching.

fio --name=testfile --directory=/home/ehigh/test_dir --size=1G --rw=randwrite --bs=4k --ioengine=libaio --iodepth=16 --numjobs=1 --runtime=30 --time_based --end_fsync=1 -direct=1

Bypassing the cache noticeably reduces the reported performance numbers, reflecting true disk speed.

Multithreaded Test

The --numjobs option specifies how many threads or processes to use, allowing evaluation of concurrency, throughput, and latency under higher I/O pressure.

fio --name=testfile --directory=/home/ehigh/test_dir --size=1G --rw=randwrite --bs=4k --ioengine=libaio --iodepth=16 --numjobs=4 --runtime=30 --time_based --end_fsync=1 -direct=1

Random Read Test

fio --name=randread --directory=/home/ehigh/test_dir --size=1G --rw=randread --bs=4k --ioengine=libaio --iodepth=16 --numjobs=1 --runtime=30 --time_based --end_fsync=1

Sequential Write Test

fio --name=seqwrite --directory=/home/ehigh/test_dir --size=1G --rw=write --bs=1M --ioengine=libaio --iodepth=16 --numjobs=1 --runtime=30 --time_based --end_fsync=1

Sequential Read Test

fio --name=seqread --directory=/home/ehigh/test_dir --size=1G --rw=read --bs=1M --ioengine=libaio --iodepth=16 --numjobs=1 --runtime=30 --time_based --end_fsync=1

Mixed Read/Write Test

fio --name=mixedrw --rw=rw --rwmixread=70 --bs=4k --numjobs=1 --ioengine=libaio --iodepth=16 --runtime=60 --size=1G --filename=testfile --directory=/home/ehigh/test_dir
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Linuxfiostorage performanceIO testingdisk benchmark
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.