RFE: create qcow2 with 'nocow' option when on Btrfs /home
Submitted by Chris Murphy
Link to original bug (#763189)
Description
Problem: VM images on Btrfs become heavily fragmented, thousands of fragments. In particular, Windows NTFS as a guest on Btrfs is significantly fragmented, tens of thousands of fragments in short order, hundreds of thousands have been reported. This slows things down just as significantly.
Solution: qemu-img supports -o nocow=on which causes xattr 'C' to be set on the file at create time, which makes the file both nodatacow and nodatasum (no Btrfs checksumming). The other option is chattr +C on ~/.local/share/gnome-boxes/ which will cause any images created or copied into that directory to inherit this attribute.
Reference: https://www.redhat.com/archives/libvir-list/2014-July/msg00361.html https://btrfs.wiki.kernel.org/index.php/Gotchas#Fragmentation
Examples:
Install Fedora 24 using default installer options (ext4 on LVM), Boxes host /home is on Btrfs. Note this test are all new writes, almost no overwrites; random overwrites make this much worse.
Without +C -rwxr--r--. 1 chris chris 4679598080 Mar 6 14:59 boxes-unknown [chris@f23m images]$ filefrag boxes-unknown boxes-unknown: 4453 extents found
With +C -rwxr--r--. 1 chris chris 4638703616 Mar 6 15:45 boxes-unknown [chris@f23m images]$ filefrag boxes-unknown boxes-unknown: 109 extents found
Argument against the enhancement:
- xattr C means no Btrfs checksumming for the file either
- Kernel code could change and improve this for both VMs and databases; kernel developers are working on this, but for now the recommendation is xattr C.
- Even on openSUSE using Btrfs by default, /home is on XFS by default which isn't affected since it's not a COW fs. So the problem is narrow in scope and the recommendation could just be "set +C on images/ if you want to use Btrfs".
So if there is a very lightweight change to make this better on Btrfs that's also easy to reverse if Btrfs improves, great.