kvm-guest-drivers-windows icon indicating copy to clipboard operation
kvm-guest-drivers-windows copied to clipboard

virtio-blk trim support

Open vorph1 opened this issue 5 years ago • 8 comments

Hi, given that qemu 4.0 is out and it supports discards when using virtio-blk i'm wondering if this driver needs to be modified to support trim? I'm getting

Optimize-Volume : The volume optimization operation requested is not supported by the hardware backing the volume.
Activity ID: {10443e0f-8d96-4757-aa30-f6dbd78b7a4f}
At line:1 char:1
+ Optimize-Volume -DriveLetter C -ReTrim -Verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (StorageWMI:ROOT/Microsoft/...age/MSFT_Volume) [Optimize-Volume], CimExcep
   tion
    + FullyQualifiedErrorId : StorageWMI 43022,Optimize-Volume

when running Optimize-Volume -DriveLetter C -ReTrim -Verbose

vorph1 avatar Apr 27 '19 14:04 vorph1

Thank you for reporting this issue. I'm working on adding trim handler to viostor driver. Meanwhile, if trim support is needed, you can try switching to vioscsi (virtio-scsi backend).

Best regards, Vadim.

vrozenfe avatar Apr 27 '19 14:04 vrozenfe

Thanks!

vorph1 avatar Apr 27 '19 16:04 vorph1

Hi, I just tested with the latest release and the issue still persists. Here's my libvirt storage config

    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' discard='unmap' detect_zeroes='unmap' queues='4'/>
      <source file='/var/lib/libvirt/images/win10-home-passthrough-games.qcow2'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x08' slot='0x00' function='0x0'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' discard='unmap' detect_zeroes='unmap' queues='4'/>
      <source file='/mnt/ssd/vm-images/win10-games.qcow2'/>
      <target dev='vdb' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x0b' slot='0x00' function='0x0'/>
    </disk>

and host versions

Name            : qemu
Version         : 4.1.0-1
Name            : libvirt
Version         : 5.5.0-1
Name            : linux
Version         : 5.2.11.arch1-1

Not sure if this should work with the above configuration at this point or the preliminary support is not enough. Thanks!

vorph1 avatar Sep 05 '19 12:09 vorph1

Strange. It should work. At least with qcow2 images.

I rechecked it again with upstream b172 drivers.

My setup is as following: qemu 4.0.92v4.1.0-rc2 kernel 5.1.16-200.fc29.x86_64 guest en_windows_10_business_editions_version_1903_x86_dvd_ca4f0f49.iso

qemu command line: #!/bin/sh IMG='/home/vrozenfe/work/images/1903_32.qcow2' DSK='/images/images/disk1.qcow2' ISO='/home/vrozenfe/Downloads/virtio-win-0.1.172.iso' QEMU=/home/vrozenfe/work/upstream/qemu/x86_64-softmmu/qemu-system-x86_64 FLGS=',hv_relaxed,hv_vapic,hv_spinlocks=0x1fff'

sudo $QEMU -cpu host$FLGS -m 2G -smp 8,maxcpus=8,cores=4,threads=1,sockets=2 -usb -device usb-tablet,id=tablet0 -drive file=$IMG,if=none,id=drive-ide0-0-0,cache=off,werror=stop,rerror=stop -device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 -netdev tap,id=hostnet0 -device e1000,netdev=hostnet0,mac=52:83:66:77:88:68,id=net0 -boot c -uuid 5b959a71-e33f-4419-97b4-da6fe8fb7062 -rtc driftfix=slew -global kvm-pit.lost_tick_policy=discard -monitor stdio -name TRIM -enable-kvm -vga qxl -drive file=$DSK,format=qcow2,if=none,id=drive-virtio-disk0,cache=none,aio=native,discard=unmap -device virtio-blk-pci,scsi=off,bus=pci.0,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=-1 -drive file=$ISO,format=raw,if=none,id=drive-ide0-0-1,readonly=on,cache=none -device ide-cd,bus=ide.0,unit=1,drive=drive-ide0-0-1,id=ide0-0-1

Created a new qcow2 image qemu-img create -f qcow2 /images/images/disk1.qcow2 5G

After installing virtio-blk driver I formatted the new volume with "Quick Format" disabled and checked the disk size [vrozenfe@huan autounattend]$ du -h /images/images/disk1.qcow2 5.0G /images/images/disk1.qcow2

As expected it was 5G. Then I switched to VM and re-trimmed the volume as defrag.exe e: /l /u /v Total space trimmed was 1.99G I checked the disk size again and it was [vrozenfe@huan autounattend]$ du -h /images/images/disk1.qcow2 2.9G /images/images/disk1.qcow2

Stopped VM and rechecked the disk size one more time

[vrozenfe@huan autounattend]$ qemu-img info /images/images/disk1.qcow2 image: /images/images/disk1.qcow2 file format: qcow2 virtual size: 5.0G (5368709120 bytes) disk size: 2.8G cluster_size: 65536 Format specific information: compat: 1.1 lazy refcounts: false refcount bits: 16 corrupt: false

vrozenfe avatar Sep 06 '19 07:09 vrozenfe

Same problem with defrag.exe, my qemu command line is as follows

/usr/bin/qemu-system-x86_64 -name guest=win10-home-passthrough-games,debug-threads=on -S -object secret,id=masterKey0,format=raw,file=/var/lib/libvirt/qemu/domain-5-win10-home-passthrou/master-key.aes -machine pc-q35-3.1,accel=kvm,usb=off,vmport=off,dump-guest-core=off -cpu host,topoext=on,hv_time,hv_relaxed,hv_vapic,hv_spinlocks=0x1fff,hv_vendor_id=1234567890ab,kvm=off -drive file=/usr/share/ovmf/x64/OVMF_CODE.fd,if=pflash,format=raw,unit=0,readonly=on -drive file=/var/lib/libvirt/qemu/nvram/win10-home-passthrough-games_VARS.fd,if=pflash,format=raw,unit=1 -m 12288 -overcommit mem-lock=off -smp 12,sockets=1,cores=6,threads=2 -uuid cc3ca07a-fa73-487c-ad02-76a4da9222b9 -display none -no-user-config -nodefaults -chardev socket,id=charmonitor,fd=26,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=localtime,driftfix=slew -global kvm-pit.lost_tick_policy=delay -no-hpet -no-shutdown -global ICH9-LPC.disable_s3=1 -global ICH9-LPC.disable_s4=1 -boot menu=on,strict=on -device pcie-root-port,port=0x10,chassis=1,id=pci.1,bus=pcie.0,multifunction=on,addr=0x2 -device pcie-root-port,port=0x11,chassis=2,id=pci.2,bus=pcie.0,addr=0x2.0x1 -device pcie-root-port,port=0x12,chassis=3,id=pci.3,bus=pcie.0,addr=0x2.0x2 -device pcie-root-port,port=0x13,chassis=4,id=pci.4,bus=pcie.0,addr=0x2.0x3 -device pcie-root-port,port=0x8,chassis=5,id=pci.5,bus=pcie.0,multifunction=on,addr=0x1 -device pcie-root-port,port=0x9,chassis=6,id=pci.6,bus=pcie.0,addr=0x1.0x1 -device pcie-pci-bridge,id=pci.7,bus=pci.6,addr=0x0 -device pcie-root-port,port=0xa,chassis=8,id=pci.8,bus=pcie.0,addr=0x1.0x2 -device pcie-root-port,port=0xb,chassis=9,id=pci.9,bus=pcie.0,addr=0x1.0x3 -device pcie-root-port,port=0xc,chassis=10,id=pci.10,bus=pcie.0,addr=0x1.0x4 -device pcie-root-port,port=0xd,chassis=11,id=pci.11,bus=pcie.0,addr=0x1.0x5 -device pcie-root-port,port=0xe,chassis=12,id=pci.12,bus=pcie.0,addr=0x1.0x6 -device qemu-xhci,p2=15,p3=15,id=usb,bus=pci.2,addr=0x0 -drive file=/var/lib/libvirt/images/win10-home-passthrough-games.qcow2,format=qcow2,if=none,id=drive-virtio-disk0,discard=unmap,detect-zeroes=unmap -device virtio-blk-pci,scsi=off,num-queues=4,bus=pci.8,addr=0x0,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 -drive file=/mnt/ssd/vm-images/win10-games.qcow2,format=qcow2,if=none,id=drive-virtio-disk1,discard=unmap,detect-zeroes=unmap -device virtio-blk-pci,scsi=off,num-queues=4,bus=pci.11,addr=0x0,drive=drive-virtio-disk1,id=virtio-disk1 -netdev tap,fd=28,id=hostnet0,vhost=on,vhostfd=29 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:d3:e0:3b,bus=pci.1,addr=0x0 -netdev tap,fd=30,id=hostnet1,vhost=on,vhostfd=31 -device virtio-net-pci,netdev=hostnet1,id=net1,mac=52:54:00:96:4c:0c,bus=pci.10,addr=0x0 -device usb-host,hostbus=5,hostaddr=8,id=hostdev0,bus=usb.0,port=1 -device vfio-pci,host=1e:00.0,id=hostdev1,bus=pci.4,addr=0x0 -device vfio-pci,host=1e:00.1,id=hostdev2,bus=pci.5,addr=0x0 -device vfio-pci,host=1e:00.2,id=hostdev3,bus=pci.9,addr=0x0 -device vfio-pci,host=1e:00.3,id=hostdev4,bus=pci.12,addr=0x0 -device virtio-balloon-pci,id=balloon0,bus=pci.3,addr=0x0 -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny -object memory-backend-file,id=shmmem-shmem0,mem-path=/dev/shm/looking-glass,size=33554432,share=yes -device ivshmem-plain,id=shmem0,memdev=shmmem-shmem0,bus=pci.7,addr=0x1 -object memory-backend-file,id=shmmem-shmem1,mem-path=/dev/shm/scream,size=2097152,share=yes -device ivshmem-plain,id=shmem1,memdev=shmmem-shmem1,bus=pcie.0,addr=0x11 -msg timestamp=on

and qemu-img info output

image: win10-home-passthrough-games.qcow2
file format: qcow2
virtual size: 80 GiB (85899345920 bytes)
disk size: 59 GiB
cluster_size: 65536
backing file: win10-home-passthrough-games-base.qcow2
Format specific information:
    compat: 1.1
    lazy refcounts: false
    refcount bits: 16
    corrupt: false

I'll recheck on a fresh VM when I have some time to spare.

vorph1 avatar Sep 06 '19 10:09 vorph1

Using viostor from virtio-win-0.1.185.iso with virtio-blk, trim works for me:

# qemu-img info /var/lib/libvirt/images/win10pro.qcow2
image: /var/lib/libvirt/images/win10pro.qcow2
file format: qcow2
virtual size: 100 GiB (107374182400 bytes)
disk size: 16.2 GiB
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: true
    refcount bits: 16
    corrupt: false

After removing a 5GB file of random data and running Optimize-Volume -DriveLetter C -ReTrim -Verbose:

# qemu-img info /var/lib/libvirt/images/win10pro.qcow2
image: /var/lib/libvirt/images/win10pro.qcow2
file format: qcow2
virtual size: 100 GiB (107374182400 bytes)
disk size: 10.5 GiB
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: true
    refcount bits: 16
    corrupt: false

Could you clarify what "preliminary support" (in #399) includes and what users should consider when choosing between viostor and vioscsi based on trim support?

kevinoid avatar Jun 06 '20 18:06 kevinoid

@kevinoid It was not clear if #399 is enough to make UNMAP(TRIM) working properly or any other changes will be requires, This is the reason why I called it "preliminary". Right now, after this feature was fully WHQL an functional tested by QE, it looks as viostor an vioscsi on par in what is related to UNMAP support.

Vadim.

vrozenfe avatar Jun 07 '20 02:06 vrozenfe

That's great! Thanks again Vladim.

kevinoid avatar Jun 07 '20 02:06 kevinoid