qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] qcow2: Add full image preallocation option
Date: Fri, 28 Jan 2011 10:49:22 +0000	[thread overview]
Message-ID: <20110128104922.GA26309@redhat.com> (raw)
In-Reply-To: <4D427CD7.8040208@redhat.com>

On Fri, Jan 28, 2011 at 09:22:47AM +0100, Kevin Wolf wrote:
> Am 27.01.2011 16:58, schrieb Daniel P. Berrange:
> > On Thu, Jan 27, 2011 at 04:52:14PM +0100, Kevin Wolf wrote:
> >> This adds a preallocation=full mode to qcow2 image creation, which does not
> >> only allocate metadata for the whole image, but also writes zeros to it,
> >> creating a non-sparse image file.
> >>
> >> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> 
> > Is there a way you can calculate the total size of the qcow2
> > file upfront, and just use a single posix_fallocate() call to
> > do the zero-filled allocation of all the data blocks. It is
> > many orders of magnitude faster than truely writing blocks of
> > zero'd data on modern filesystems.  I guess if you're using
> > compression or encryption, we'd really have to go the slow
> > path, but for regular usage it'd be better to take a fast
> > path.
> 
> Encryption doesn't really change anything with respect to cluster
> allocations, but combining compression with preallocation doesn't make
> any sense. We should probably forbid that.
> 
> To get the size of the image, it should be enough to get the offset of
> the last cluster as the allocation is done sequentially. However, we
> don't have a bdrv_fallocate (yet). I'm not sure how to emulate this for
> drivers that don't support it directly, but maybe we could just ignore
> it for them.

FWIW in libvirt code we ended up with 'posix_fallocate()' as our
first choice. If that wasn't available, then we do a sequence of
'ftruncate()+mmap()+memset()+munmap()' for the region as second
choice. And if mmap doesn't exist, as the catch-all portable
option for any OS we do a write() of 1MB chunks in a loop.

Regards,
Daniel

  reply	other threads:[~2011-01-28 10:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-27 15:52 [Qemu-devel] [PATCH] qcow2: Add full image preallocation option Kevin Wolf
2011-01-27 15:58 ` Daniel P. Berrange
2011-01-27 17:50   ` Anthony Liguori
2011-01-28  8:46     ` Kevin Wolf
2011-01-28  8:22   ` Kevin Wolf
2011-01-28 10:49     ` Daniel P. Berrange [this message]
2011-01-27 17:45 ` Anthony Liguori
2011-02-04 10:59   ` Stefan Hajnoczi

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=20110128104922.GA26309@redhat.com \
    --to=berrange@redhat.com \
    --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).