kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Easy way to track Qcow2 space consumption
@ 2019-10-08 18:01 freebsd
  2019-10-09  9:32 ` Stefan Hajnoczi
  0 siblings, 1 reply; 2+ messages in thread
From: freebsd @ 2019-10-08 18:01 UTC (permalink / raw)
  To: kvm

Hello List,

I'm using a fairly old KVM version

ii  pve-qemu-kvm                          2.2-28                         
     amd64        Full virtualization on x86 hardware

don't see much point upgrading either since everything works but I could 
still use a feature to keep track of the actual space used by the VMs 
without SSHing into all of them and doing a df -h.

The VM images (especially the DBs with high rw operation will just grow 
and grow with time), for this to free up space the standard process was:

1, Zero-fill the drive (dd if=/dev/zero of=/some/file until you run out 
of space)
1B, sdelete -z c: < windows VM
2, Shut down the VM
3, cd to where the images for the VM are kept and run qemu-img convert 
-O qcow2 original_image.qcow2 deduplicated_image.qcow2

I wonder if there were any improvements done in the KVM for addressing 
this space issue. A lot of us using qcow2 because it's easier to backup 
due to the small size (eg: a basic configured webserver might only uses 
3-4 Gb vs a 40GB preallocated empty image full of 0s).

Thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Easy way to track Qcow2 space consumption
  2019-10-08 18:01 Easy way to track Qcow2 space consumption freebsd
@ 2019-10-09  9:32 ` Stefan Hajnoczi
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Hajnoczi @ 2019-10-09  9:32 UTC (permalink / raw)
  To: freebsd; +Cc: kvm, qemu-devel, Kevin Wolf

[-- Attachment #1: Type: text/plain, Size: 1946 bytes --]

On Tue, Oct 08, 2019 at 08:01:11PM +0200, freebsd@tango.lu wrote:
> Hello List,
> 
> I'm using a fairly old KVM version
> 
> ii  pve-qemu-kvm                          2.2-28
> amd64        Full virtualization on x86 hardware
> 
> don't see much point upgrading either since everything works but I could
> still use a feature to keep track of the actual space used by the VMs
> without SSHing into all of them and doing a df -h.
> 
> The VM images (especially the DBs with high rw operation will just grow and
> grow with time), for this to free up space the standard process was:
> 
> 1, Zero-fill the drive (dd if=/dev/zero of=/some/file until you run out of
> space)
> 1B, sdelete -z c: < windows VM
> 2, Shut down the VM
> 3, cd to where the images for the VM are kept and run qemu-img convert -O
> qcow2 original_image.qcow2 deduplicated_image.qcow2
> 
> I wonder if there were any improvements done in the KVM for addressing this
> space issue. A lot of us using qcow2 because it's easier to backup due to
> the small size (eg: a basic configured webserver might only uses 3-4 Gb vs a
> 40GB preallocated empty image full of 0s).

Hi,
I'm CCing the QEMU mailing list and Kevin Wolf, the qcow2 maintainer.

QEMU and qcow2 have support for the discard/trim command that allows the
guest to report unused regions of the disk.  virtio-scsi and recent
virtio-blk devices support this feature.

Set the -drive discard=unmap QEMU command-line option in order to enable
discard.

Run the fstrim(8) Linux command inside the guest.  Other operating
systems may have equivalent commands.

You should find that the qcow2 file has fewer allocated blocks after
this operation.  Consider this an efficient replacement for zero filling
the device.  It is still necessary to shutdown the VM and use qemu-img
convert unless you want to switch to a fancier online backup process
using block job commands.

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-10-09  9:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-08 18:01 Easy way to track Qcow2 space consumption freebsd
2019-10-09  9:32 ` Stefan Hajnoczi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).