最大化 Windows 上 QEMU 运行的 Linux 系统性能

因为最近在做 Linux from Scratch,更在意 CPU 和 Memory 性能,对比下在 Windows 宿主机上如何运行 QEMU Linux 虚拟机性能更高。

使用 融合怪评测项目 ECS 对各系统做性能测试,用它主要是支持跨平台,但 CPU 测试在 Windows 用的是 winsat,在 Linux 是 sysbench 仅供参考。所以添加 7z 25.01 来在 CPU 性能做基准。记录取多次测试最高值

平台CPU 单核CPU 16 核内存拷贝 MB/s7z 压缩 KiB/s7z 解压 KiB/s
Windows native--60101.11191251575949
WSL27421.2460180.4453639.91110151614714
-accel kvm on WSL25898.9649849.8653601.31091441462513
-accel whpx on Windows5665.2350660.3349081.31138531534549

结论是 WSL2 没什么性能损失,但给 QEMU 多套一层虚拟化还是会降低约 5% 性能,直接 Windows whpx 跑就好

在 WHPX 上启动方式:

$command = @"
qemu-system-x86_64
    -accel whpx
    -smp 16
    -m 16g
    -hda debian.qcow2
    -nographic
    -monitor telnet:127.0.0.1:2223,server,nowait
    -nic user,hostfwd=tcp:127.0.0.1:2222-:22
"@ -replace "`n", " "
Start-Process cmd.exe -ArgumentList "/c", "$command & pause"

如何备份 QEMU 虚拟机

关机状态下创建磁盘快照,保存在同一个文件
qemu-img snapshot disk.qcow2 -c snapshop-tag
 
qemu-img snapshot \
    [--object OBJECTDEF] [--image-opts] [-U] [-q] \
    [-l | -a SNAPSHOT | -c SNAPSHOT | -d SNAPSHOT] FILENAME
 
    Parameters to snapshot subcommand:
 
    SNAPSHOT
           Is the name of the snapshot to create, apply or delete
 
    -a     Applies a snapshot (revert disk to saved state)
    -c     Creates a snapshot
    -d     Deletes a snapshot
    -l     Lists all snapshots in the given image
在线状态下创建磁盘快照
(qemu) info block
ide0-hd0 (#block102): E:\VirtualMachines\LinuxFromScratch\debian.qcow2 (qcow2)
    Attached to:      /machine/unattached/device[19]
    Cache mode:       writeback
(qemu) snapshot_blkdev ide0-hd0 E:/debian-overlay.qcow2 qcow2
(qemu) commit ide0-hd0

savevm 在 WHPX 下无效,有 Error: State blocked due to non-migratable CPUID feature support,dirty memory tracking support, and XSAVE/XRSTOR support 错误

LFS 中构建 readline 出现 0a1,173: command not found 错误

跟着 8.12. Readline-8.3 做的时候出现这个错误

./configure
./config.status: line 533: 0a1,173: command not found
./config.status: line 534: syntax error near unexpected token `newline'
./config.status: line 534: `> # This file is a shell script that caches the results of configure'

解决方式在这 Error running configure readline 8.1.2,也在 LFS FAQ 提到。

在 chroot 外用 root 身份用 mount -v --bind /dev $LFS/dev 把 /dev 挂载上。我是因为重启过设备,没有按照 7.4. 进入 Chroot 环境 的说明设置好 chroot 环境。