From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56652) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V7OwZ-0000dO-G8 for qemu-devel@nongnu.org; Thu, 08 Aug 2013 08:03:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V7OtB-0006B2-2Z for qemu-devel@nongnu.org; Thu, 08 Aug 2013 08:01:06 -0400 Received: from mail-wg0-x22e.google.com ([2a00:1450:400c:c00::22e]:64484) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V7OtA-00069o-Qj for qemu-devel@nongnu.org; Thu, 08 Aug 2013 08:00:20 -0400 Received: by mail-wg0-f46.google.com with SMTP id k13so2453405wgh.1 for ; Thu, 08 Aug 2013 05:00:19 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <5203884F.5040805@redhat.com> Date: Thu, 08 Aug 2013 14:00:15 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <5203744F.4010407@ramses-pyramidenbau.de> In-Reply-To: <5203744F.4010407@ramses-pyramidenbau.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] Using TRIM to shrink qcow2 images List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Ralf Ramsauer Cc: qemu-devel@nongnu.org On 08/08/2013 12:34 PM, Ralf Ramsauer wrote: > Hi, > > QCOW2 uses a similar idea like file holes (sparse files) on filesystems [1]. > RAW Images also may use file holes. > > If qemu would support TRIM, then the guest could easily discard and zero > all unused blocks. QEMU supports trim. 1.5 supports it with raw images only, 1.6 will add qcow2 support. Because it has the potential to cause fragmentation, it needs to be enabled explicitly. Just add "discard=on" to the -drive option: qemu-system-x86_64 -enable-kvm -m 2048 ...\ -drive if=virtio,discard=on,file=$HOME/foo.qcow2 It's probably always a good idea if the image is a block device on an SSD, but not necessarily on an image that is backed (for example) by a file or by a thin-provisioned logical volume. > The host system could detect all unused blocks in a (e.g.) qcow2 image > and shrink it down to its minimum size. This depends on the host support for discard (on block device-backed qcow2 images) or hole punching (for file-backed qcow2 images). For files, running fstrim in the guest will shrink down the on-disk footprint of a qcow2 image. Paolo > Did anyone already think about that? > > [1] : https://people.gnome.org/~markmc/qcow-image-format.html > > Regards, >