coreos / fedora-coreos-tracker

Issue tracker for Fedora CoreOS
https://fedoraproject.org/coreos/
264 stars 59 forks source link

Configure qemu to pass down discards when building images #1069

Open cmurf opened 2 years ago

cmurf commented 2 years ago

Describe the enhancement Configure qemu to pass down discards when building images, e.g.

<disk type="file" device="disk">
  <driver name="qemu" type="raw" cache="unsafe" discard="unmap" detect_zeroes="unmap"/>
  <source file="/var/lib/libvirt/images/fedorasilverbluerawhide20211206-default.raw"/>
  <target dev="vda" bus="virtio"/>
  <boot order="2"/>
  <address type="pci" domain="0x0000" bus="0x04" slot="0x00" function="0x0"/>
</disk>

Key portion is -> discard="unmap"

System details

fedora-coreos-35.20220103.2.1-metal.x86_64.raw

Additional information

As downloaded
2537472 -rw-r--r--. 1 root root   2598371328 Jan 16 15:07 fedora-coreos-35.20220103.2.1-metal.x86_64.raw
Following loop mount and fstrim of partition 4 (XFS)
1971072 -rw-r--r--. 1 root root   2598371328 Jan 16 15:07 fedora-coreos-35.20220103.2.1-metal.x86_64.raw

On IRC, Colin is pretty sure coreos assembler does fstrim before the final teardown/umount, and that most likely reason the image is made smaller manually (above) is qemu io devices by default do not pass down discards, rendering the fstrim prior to umount ineffective.

bgilbert commented 2 years ago

Remember that a downloaded raw image won't be sparse at all. I just tried fstrim on partition 4 of a locally built image:

1815280 -r--r--r--. 1 bgilbert bgilbert 2943352832 Jan 17 14:31 fedora-coreos-35.20220117.dev.0-metal.x86_64.raw
1805848 -rw-r--r--. 1 bgilbert bgilbert 2943352832 Jan 17 14:38 fedora-coreos-35.20220117.dev.0-metal.x86_64.raw.fstrim

So yes, there's room for some improvement, but it's not quite as bad.