使用文件模拟nvme设备

使用文件模拟nvme设备

我可以使用文件来模拟 NVMe 设备吗?我不想使用 qemu,它在我的机器上真的很慢。

答案1

是的,可以,但您需要 NVME 目标支持。

  1. 确保您有内核模块:nvme_loop, nvmet,nvme_fabrics
  2. 在文件上设置循环设备:losetup /dev/loop0 /tmp/mynvmefile
  3. 获取NVME 目标 CLI,并确保您具有依赖项。
    1. configshell-fb是主要部门,并且没有正确声明setup.py
  4. examples/loop.json从 nvmetcli 编辑:
    1. device将示例中的背景更改为/dev/loop0(默认为/dev/nvme0n1)。
  5. 设定目标:sudo ./nvmetcli restore examples/loop-modified.json
    1. 内核日志应该只有一行:nvmet: adding nsid 1 to subsystem testnqn
  6. 使用 nvme-cli 工具连接到目标:nvme connect -t loop -n testnqn -q hostnqn
  7. 利润!

创建和连接后的 dmesg 输出示例

nvmet: adding nsid 1 to subsystem testnqn
nvmet: creating controller 1 for subsystem testnqn for NQN hostnqn.
nvme nvme0: creating 8 I/O queues.
nvmet: adding queue 1 to ctrl 1.
nvmet: adding queue 2 to ctrl 1.
nvmet: adding queue 3 to ctrl 1.
nvmet: adding queue 4 to ctrl 1.
nvmet: adding queue 5 to ctrl 1.
nvmet: adding queue 6 to ctrl 1.
nvmet: adding queue 7 to ctrl 1.
nvmet: adding queue 8 to ctrl 1.
nvme nvme0: new ctrl: "testnqn"

NVME 信息:

# nvme  list
Node             SN                   Model                                    Namespace Usage                      Format           FW Rev  
---------------- -------------------- ---------------------------------------- --------- -------------------------- ---------------- --------
/dev/nvme0n1     191b474c759f6b80     Linux                                    1         134.22  MB / 134.22  MB      4 KiB +  0 B   4.14.0-r

fio 结果在这个假设备上运行(内存支持,而不是磁盘上的文件):

# fio --filename=/dev/nvme0n1  --rw=write --bs=4k --numjobs=1 \
--iodepth=1 --runtime=60 --time_based --group_reporting \
--name=journal-test
journal-test: (g=0): rw=write, bs=4K-4K/4K-4K/4K-4K, ioengine=psync, iodepth=1
fio-2.16
Starting 1 process
Jobs: 1 (f=1): [W(1)] [100.0% done] [0KB/951.4MB/0KB /s] [0/244K/0 iops] [eta 00m:00s]
journal-test: (groupid=0, jobs=1): err= 0: pid=13352: Thu Oct 19 13:26:18 2017
  write: io=110476MB, bw=1840.5MB/s, iops=471152, runt= 60027msec
    clat (usec): min=0, max=85222, avg= 1.78, stdev=190.60
     lat (usec): min=0, max=85222, avg= 1.84, stdev=190.60
    clat percentiles (usec):
     |  1.00th=[    0],  5.00th=[    0], 10.00th=[    1], 20.00th=[    1],
     | 30.00th=[    1], 40.00th=[    1], 50.00th=[    1], 60.00th=[    1],
     | 70.00th=[    1], 80.00th=[    1], 90.00th=[    2], 95.00th=[    2],
     | 99.00th=[    2], 99.50th=[    3], 99.90th=[    9], 99.95th=[    9],
     | 99.99th=[   21]
    lat (usec) : 2=88.18%, 4=11.50%, 10=0.27%, 20=0.03%, 50=0.01%
    lat (usec) : 100=0.01%, 250=0.01%, 500=0.01%, 750=0.01%
    lat (msec) : 2=0.01%, 4=0.01%, 10=0.01%, 20=0.01%, 50=0.01%
    lat (msec) : 100=0.01%
  cpu          : usr=26.90%, sys=39.40%, ctx=3488, majf=0, minf=11
  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    : total=r=0/w=28281845/d=0, short=r=0/w=0/d=0, drop=r=0/w=0/d=0
     latency   : target=0, window=0, percentile=100.00%, depth=1

Run status group 0 (all jobs):
  WRITE: io=110476MB, aggrb=1840.5MB/s, minb=1840.5MB/s, maxb=1840.5MB/s, mint=60027msec, maxt=60027msec

Disk stats (read/write):
  nvme0n1: ios=0/12044, merge=0/3027439, ticks=0/347358, in_queue=318011, util=46.10%

相关内容