日度归档:2026-01-04

linux中使用fio测试硬盘入写性成

fio可能需要安装

sudo apt install fio
或
sudo dnf install fio

检测命令:

cd <测试磁盘对应目录>
fio --name=seqwrite --rw=write --bs=1M --size=2G --direct=1 --iodepth=1

# 4K随机写入
fio --name=randwrite --rw=randwrite --bs=4k --size=1G --direct=1 --sync=0 --iodepth=1 --numjobs=1 --runtime=60 --time_based --group_reporting

# 模拟真实数据库负载(高队列深度)
fio --name=randwrite --rw=randwrite --bs=4k --size=10G --direct=1 --iodepth=32 --numjobs=1 --runtime=60 --time_based --group_reporting

# 单线程、低队列深度(贴近桌面/轻负载)
fio --name=randwrite --rw=randwrite --bs=4k --size=1G --direct=1 --iodepth=1 --numjobs=1 --runtime=30 --time_based

结果示例:

seqwrite: (g=0): rw=write, bs=(R) 1024KiB-1024KiB, (W) 1024KiB-1024KiB, (T) 1024KiB-1024KiB, ioengine=psync, iodepth=1
fio-3.39
Starting 1 process
seqwrite: Laying out IO file (1 file / 2048MiB)

seqwrite: (groupid=0, jobs=1): err= 0: pid=179780: Sat Jan  3 14:52:33 2026
  write: IOPS=2506, BW=2507MiB/s (2628MB/s)(2048MiB/817msec); 0 zone resets
    clat (usec): min=334, max=3223, avg=386.08, stdev=189.18
     lat (usec): min=340, max=3229, avg=395.13, stdev=189.45
    clat percentiles (usec):
     |  1.00th=[  338],  5.00th=[  338], 10.00th=[  343], 20.00th=[  347],
     | 30.00th=[  351], 40.00th=[  351], 50.00th=[  351], 60.00th=[  355],
     | 70.00th=[  359], 80.00th=[  367], 90.00th=[  416], 95.00th=[  515],
     | 99.00th=[  848], 99.50th=[ 1909], 99.90th=[ 3130], 99.95th=[ 3195],
     | 99.99th=[ 3228]
   bw (  MiB/s): min= 2488, max= 2488, per=99.25%, avg=2488.00, stdev= 0.00, samples=1
   iops        : min= 2488, max= 2488, avg=2488.00, stdev= 0.00, samples=1
  lat (usec)   : 500=94.87%, 750=3.32%, 1000=1.03%
  lat (msec)   : 2=0.29%, 4=0.49%
  cpu          : usr=2.45%, sys=18.26%, ctx=2053, majf=0, minf=9
  IO depths    : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     issued rwts: total=0,2048,0,0 short=0,0,0,0 dropped=0,0,0,0
     latency   : target=0, window=0, percentile=100.00%, depth=1

Run status group 0 (all jobs):
  WRITE: bw=2507MiB/s (2628MB/s), 2507MiB/s-2507MiB/s (2628MB/s-2628MB/s), io=2048MiB (2147MB), run=817-817msec

Disk stats (read/write):
  nvme0n1: ios=0/12655, sectors=0/3084040, merge=0/54, ticks=0/2598, in_queue=2598, util=68.09%

Run status group 0 (all jobs) 可以看到 bw 参数。以下是常见硬盘类型在 4K 随机写入(典型 OLTP 场景) 下的 IOPS 等级与参考值(基于行业实测与厂商数据):

性能等级IOPS 范围(4K 随机写)对应存储介质典型场景
极差< 50 IOPS低速机械盘(如 5400 RPM HDD)、老旧/故障设备、严重拥塞的虚拟磁盘不适合数据库、系统盘
低劣50 – 150 IOPS普通桌面级 HDD(7200 RPM)基础文件存储,非关键业务
中等150 – 1,000 IOPS企业级 HDD(10K–15K RPM)、低端 SATA SSD轻量级虚拟机、日志盘、开发环境
良好1,000 – 10,000 IOPS主流 SATA SSD(如三星 870 EVO、Intel D3-S4510)中小型数据库、系统盘、通用服务器
优秀10,000 – 100,000 IOPS高端 SATA / PCIe 3.0 NVMe SSD(如 Samsung PM9A1、WD SN750)高并发数据库、虚拟化平台、容器节点
顶级> 100,000 IOPS高性能 NVMe SSD(如 Samsung PM1733、Intel Optane P5800X、PCIe 4.0/5.0 旗舰盘)核心交易系统、高频金融、AI 训练缓存

注:

  • 所有数值基于 队列深度 ≥ 16、4K 随机写、稳态(steady-state) 条件;
  • 实际 IOPS 受队列深度、读写比例、预处理(preconditioning)、SLC 缓存耗尽等因素显著影响;
  • NVMe 盘在高队列深度下可达 50万~200万+ IOPS(如企业级 U.2 或 EDSFF 形态)。