使用FIO测试SPDK性能

前提

若在 FEMU 上进行测试,需调整 FEMU 以解决 NVMe 协议的 Admin 命令未实现的问题。以下方法仅为暂时屏蔽该问题。

1
2
3
4
5
6
7
8
9
10
11
--- a/hw/femu/nvme-admin.c
+++ b/hw/femu/nvme-admin.c
@@ -999,6 +999,8 @@ static uint16_t nvme_admin_cmd(FemuCtrl *n, NvmeCmd *cmd, NvmeCqe *cqe)
case NVME_ADM_CMD_SET_DB_MEMORY:
femu_debug("admin cmd,set_db_memory\n");
return nvme_set_db_memory(n, cmd);
+ case NVME_ADM_CMD_ASYNC_EV_REQ:
+ return NVME_SUCCESS;
case NVME_ADM_CMD_ACTIVATE_FW:
case NVME_ADM_CMD_DOWNLOAD_FW:
case NVME_ADM_CMD_SECURITY_SEND:

一、编译FIO

  1. 克隆FIO源代码库:
1
2
git clone https://github.com/axboe/fio
cd fio
  1. 编译并安装FIO:
1
2
make
make install

二、编译SPDK

  1. 克隆SPDK源代码库
1
2
3
git clone https://github.com/spdk/spdk
cd spdk
git submodule update --init
  1. 启用FIO插件,运行SPDK配置脚本
1
./configure --with-fio=/path/to/fio/repo # 示例路径:/user/ctz/fio
  1. 安装依赖并编译SPDK:
1
2
./scripts/pkgdep.sh
make

编译完成后,在 <spdk_repo>/build/fio 目录下会生成 fio_plugin 的可执行文件:spdk_bdevspdk_nvme

在 SPDK 用户态模式下,SPDK 将设备从内核驱动中解绑并绑定到 SPDK 提供的用户层驱动上,因此解绑后用户无法通过 lsblk 等指令直接查看设备。为了方便使用 FIO 测试设备性能,SPDK 推出了 FIO 插件。

SPDK 提供两种形式的 fio_plugin:

  • spdk_nvme:基于裸盘 NVMe 的 fio_plugin,通过 SPDK 用户态驱动直接访问裸盘,用于测试裸盘性能。
  • spdk_bdev:基于 bdev 的 fio_plugin,通过 SPDK 块设备 bdev 层进行 I/O 测试,用于测试 SPDK bdev 的性能。

三、从内核解绑设备

使用 SPDK 提供的 setup.sh 脚本,将存储设备从内核驱动中解绑并分配大页:

1
2
cd /path/to/spdk
sudo ./scripts/setup.sh

创建 JSON 配置文件:

1
sudo scripts/gen_nvme.sh --json-with-subsystems > /tmp/bdev.json

JSON 配置文件示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
"subsystems": [
{
"subsystem": "bdev",
"config": [
{
"method": "bdev_nvme_attach_controller",
"params": {
"trtype": "PCIe",
"name": "Nvme0",
"traddr": "0000:00:05.0"
}
}
]
}
]
}

四、准备FIO配置文件

FIO 配置文件与普通配置文件大致相似,但为了使用 SPDK 编译生成的插件,需要设置 ioenginespdk_json_conf

ioengine 需指定编译好的 spdk_bdevspdk_nvme 的路径,spdk_json_conf 需指定第三步中生成的 JSON 文件。

FIO 配置文件示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[global]
ioengine=<spdk_repo>/build/fio/spdk_bdev
spdk_json_conf=/tmp/bdev.json

thread=1
direct=1
group_reporting=1

bs=4k
rw=randread
rwmixread=70
time_based=1
runtime=10
norandommap=1

[filename0]
filename=Nvme0n1
iodepth=8

五、运行FIO

1
sudo fio fio.conf

输出示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
filename0: (g=0): rw=randread, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=spdk_bdev, iodepth=8
fio-3.36-19-gbdf99
Starting 1 thread
Jobs: 1 (f=1): [r(1)][100.0%][r=2957MiB/s][r=757k IOPS][eta 00m:00s]
filename0: (groupid=0, jobs=1): err= 0: pid=47257: Fri Mar 1 08:09:14 2024
read: IOPS=754k, BW=2944MiB/s (3087MB/s)(28.8GiB/10001msec)
slat (nsec): min=142, max=22523, avg=153.40, stdev=38.74
clat (usec): min=2, max=346, avg=10.07, stdev= 1.91
lat (usec): min=2, max=346, avg=10.23, stdev= 1.91
clat percentiles (nsec):
| 1.00th=[ 5472], 5.00th=[ 7648], 10.00th=[ 8512], 20.00th=[ 9024],
| 30.00th=[ 9408], 40.00th=[ 9664], 50.00th=[ 9920], 60.00th=[10176],
| 70.00th=[10560], 80.00th=[10944], 90.00th=[11840], 95.00th=[13376],
| 99.00th=[15680], 99.50th=[16768], 99.90th=[20352], 99.95th=[21632],
| 99.99th=[28544]
bw ( MiB/s): min= 2845, max= 2960, per=100.00%, avg=2945.67, stdev=24.66, samples=19
iops : min=728552, max=757862, avg=754091.26, stdev=6312.12, samples=19
lat (usec) : 4=0.07%, 10=52.90%, 20=46.92%, 50=0.11%, 100=0.01%
lat (usec) : 250=0.01%, 500=0.01%
cpu : usr=99.97%, sys=0.00%, ctx=31, majf=0, minf=0
IO depths : 1=0.1%, 2=0.1%, 4=41.0%, 8=58.8%, 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=99.7%, 8=0.3%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
issued rwts: total=7537136,0,0,0 short=0,0,0,0 dropped=0,0,0,0
latency : target=0, window=0, percentile=100.00%, depth=8

Run status group 0 (all jobs):
READ: bw=2944MiB/s (3087MB/s), 2944MiB/s-2944MiB/s (3087MB/s-3087MB/s), io=28.8GiB (30.9GB), run=10001-10001msec

六、ZNS性能测试

SPDK FIO 插件支持 ZNS SSD 性能测试。详情请参考ZNS性能测试


使用FIO测试SPDK性能
https://ci-tz.github.io/2024/03/04/使用FIO测试SPDK性能/
作者
次天钊
发布于
2024年3月4日
许可协议