[fedora-virt] sparse=false allocation

Cole Robinson crobinso at redhat.com
Sat Nov 16 23:36:29 UTC 2013


On 11/14/2013 03:46 PM, Gene Czarcinski wrote:
> I have been experimenting with putting /var/lib/libvirt/images on a btrfs
> subvolume.  What I found was ... interesting.
> 
> Just doing nothing else, a disk image file can en up with something like
> 50,000 extents or more.  Now, you can go do a btrfs fi defrag and it will
> reduce but when you use the system, it will increase again.
> 
> OK, you cannot turn off "cow" for a subvolume but you can turn it off for a
> new file (or more important) for an new file in a directory:  chattr +C
> /var/lib/libvirt/images and any new disk image file will have no-cow.
> 
> OK, install a system with a new disk file.  The result: a file with 47,000
> extents.  The reason, I used virt-manager and the disk image file allocated
> was a sparse file.  Now in some respects sparse files are good because they do
> not use space unless they need it.  But, with BTRFS, the result is large scale
> fragmentation.  And, btrfs fi defrag does not
> work on this file /directory.
> 
> OK, another try.  Preallocate a file using dd if=/dev/zero
> of=/var/lib/libvirt/images/xxx.img bs=1024 count=12587000 and the result is a
> 12GB (more or less) virtual disk.  Install a system using this as the virtual
> disk. extents=9.  install a second system subvol=root2 (it is a virtual btrfs
> system). extents=9.  And a third one. extents=9.  BTW, these installs were
> about the fastest I have ever seen!
> 
> So, is there a way to do this "sparse=false" disk allocation with
> virt-manager, or do I need to do an RFE?
> 
> For a system where the disk images are going to be on BTRFS, a fully allocated
> disk has definite benefits.
> 

virt-manager already has this option: in the 'new vm' wizard, there's a
checkbox for 'allocate entire disk now' or similar. it is checked by default.
But we just ask libvirt to handle this for us, and it is likely using
fallocate and not writing tons of zeros like dd will do.

Maybe libvirt should skip that fallocate step on btrfs. I've moved your bug
[1] to libvirt for further investigation.

[1] https://bugzilla.redhat.com/show_bug.cgi?id=1031303

- Cole


More information about the virt mailing list