qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@gmail.com>
To: freebsd@tango.lu
Cc: Kevin Wolf <kwolf@redhat.com>,
	qemu-devel@nongnu.org, kvm@vger.kernel.org
Subject: Re: Easy way to track Qcow2 space consumption
Date: Wed, 9 Oct 2019 10:32:49 +0100	[thread overview]
Message-ID: <20191009093249.GA5747@stefanha-x1.localdomain> (raw)
In-Reply-To: <ab1bd1a234b7b9d18433d539f179f602@tango.lu>

[-- 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 --]

           reply	other threads:[~2019-10-09 17:48 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <ab1bd1a234b7b9d18433d539f179f602@tango.lu>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191009093249.GA5747@stefanha-x1.localdomain \
    --to=stefanha@gmail.com \
    --cc=freebsd@tango.lu \
    --cc=kvm@vger.kernel.org \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).