You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

开启KVM的QEMU中fio runtime选项失效问题求助

问题解决:KVM开启后fio runtime参数失效的修复方案

可能原因分析

开启KVM后虚拟机性能大幅提升,加上/dev/nullb0是零开销虚拟块设备,fio可能因时钟同步问题或IO处理过快触发隐含终止条件,导致runtime参数失效。以下是针对性修复方案:


修复方案1:同步虚拟机时钟

KVM虚拟机时钟与宿主机不同步会导致fio计时错误,需在QEMU启动参数中添加时钟同步配置:

qemu-system-x86_64 \
    -nographic --enable-kvm\
    -smp 4 -m 4096 \
    -kernel arch/x86_64/boot/bzImage \
    -append "console=ttyS0 root=/dev/sda rootfstype=ext4 rw clocksource=kvm-clock" \
    -hda /data/bupt-rtos/x86_ramdisk/ubuntu-rootfs.img \
    -nic tap,id=net0,ifname=tap0,script=no,downscript=no\
    -object "filter-dump,id=net0,netdev=net0,file=dump.dat" \
    -rtc base=utc,clock=host
  • -rtc base=utc,clock=host:让虚拟机时钟同步宿主机系统时间
  • clocksource=kvm-clock:指定使用KVM专用时钟源,提升计时精度

修复方案2:强制fio持续运行

通过指定size或loops参数,避免fio因IO处理过快提前结束:

方式A:添加超大size参数

设置远大于30秒内能处理的IO量,确保fio被runtime限制终止:

fio --filename=/dev/nullb0 --iodepth=64 --ioengine=psync --direct=1 --rw=randread --bs=$1k --numjobs=$2 --runtime=30s --size=100G --group_reporting --name=test-rand-read --output=test_c_randwrite.log

方式B:设置极大循环次数

让fio循环执行IO,直到runtime到期:

fio --filename=/dev/nullb0 --iodepth=64 --ioengine=psync --direct=1 --rw=randread --bs=$1k --numjobs=$2 --runtime=30s --loops=1000000 --group_reporting --name=test-rand-read --output=test_c_randwrite.log

修复方案3:更换IO引擎

psync引擎在KVM环境下可能因性能特性触发提前终止,尝试换用libaio引擎(需确保系统已安装libaio库):

fio --filename=/dev/nullb0 --iodepth=64 --ioengine=libaio --direct=1 --rw=randread --bs=$1k --numjobs=$2 --runtime=30s --group_reporting --name=test-rand-read --output=test_c_randwrite.log

替代方案:Shell脚本强制控制运行时间

如果上述方案均无效,可通过脚本强制让fio运行满30秒:

#!/bin/bash
# 启动fio后台进程
fio --filename=/dev/nullb0 --iodepth=64 --ioengine=psync --direct=1 --rw=randread --bs=$1k --numjobs=$2 --group_reporting --name=test-rand-read --output=test_c_randwrite.log &
FIO_PID=$!

# 等待30秒
sleep 30

# 终止fio进程并等待退出
kill $FIO_PID
wait $FIO_PID 2>/dev/null

赋予脚本执行权限后运行,即可确保fio至少运行30秒。

内容的提问来源于stack exchange,提问作者Yexuan Yang

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 08:07:50