From: Kevin Wolf <kwolf@redhat.com>
To: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Cc: Khoa Huynh <khoa@us.ibm.com>,
Anthony Liguori <aliguori@us.ibm.com>,
qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2 5/7] qcow2: implement lazy refcounts
Date: Thu, 26 Jul 2012 15:15:14 +0200 [thread overview]
Message-ID: <501142E2.6080602@redhat.com> (raw)
In-Reply-To: <1343218884-14980-6-git-send-email-stefanha@linux.vnet.ibm.com>
Am 25.07.2012 14:21, schrieb Stefan Hajnoczi:
> Lazy refcounts is a performance optimization for qcow2 that postpones
> refcount metadata updates and instead marks the image dirty. In the
> case of crash or power failure the image will be left in a dirty state
> and repaired next time it is opened.
>
> Reducing metadata I/O is important for cache=writethrough and
> cache=directsync because these modes guarantee that data is on disk
> after each write (hence we cannot take advantage of caching updates in
> RAM). Refcount metadata is not needed for guest->file block address
> translation and therefore does not need to be on-disk at the time of
> write completion - this is the motivation behind the lazy refcount
> optimization.
>
> The lazy refcount optimization must be enabled at image creation time:
>
> qemu-img create -f qcow2 -o compat=1.1,lazy_refcounts=on a.qcow2 10G
> qemu-system-x86_64 -drive if=virtio,file=a.qcow2,cache=writethrough
>
> Update qemu-iotests 031 and 036 since the extension header size changes
> when we add feature bit table entries.
>
> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
> ---
> block/qcow2-cluster.c | 5 +++-
> block/qcow2.c | 71 +++++++++++++++++++++++++++++++++++++++++---
> block/qcow2.h | 13 ++++++++
> block_int.h | 26 ++++++++--------
> tests/qemu-iotests/031.out | 12 ++++----
> tests/qemu-iotests/036.out | 2 +-
> 6 files changed, 105 insertions(+), 24 deletions(-)
>
> diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
> index d7e0e19..e179211 100644
> --- a/block/qcow2-cluster.c
> +++ b/block/qcow2-cluster.c
> @@ -662,7 +662,10 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m)
> qcow2_cache_depends_on_flush(s->l2_table_cache);
> }
>
> - qcow2_cache_set_dependency(bs, s->l2_table_cache, s->refcount_block_cache);
> + if (qcow2_need_accurate_refcounts(s)) {
> + qcow2_cache_set_dependency(bs, s->l2_table_cache,
> + s->refcount_block_cache);
> + }
> ret = get_cluster_table(bs, m->offset, &l2_table, &l2_index);
> if (ret < 0) {
> goto err;
> diff --git a/block/qcow2.c b/block/qcow2.c
> index 7fe1567..d48527f7 100644
> --- a/block/qcow2.c
> +++ b/block/qcow2.c
> @@ -215,6 +215,39 @@ static void report_unsupported_feature(BlockDriverState *bs,
> }
>
> /*
> + * Sets the dirty bit and flushes afterwards if necessary.
> + *
> + * The incompatible_features bit is only set if the image file header was
> + * updated successfully. Therefore it is not required to check the return
> + * value of this function.
> + */
> +static int qcow2_mark_dirty(BlockDriverState *bs)
> +{
> + BDRVQcowState *s = bs->opaque;
> + uint64_t val;
> + int ret;
> +
> + if (s->incompatible_features & QCOW2_INCOMPAT_DIRTY) {
> + return 0; /* already dirty */
> + }
> +
> + val = cpu_to_be64(s->incompatible_features | QCOW2_INCOMPAT_DIRTY);
> + ret = bdrv_pwrite(bs->file, offsetof(QCowHeader, incompatible_features),
> + &val, sizeof(val));
If you respin, I think would be nice to have either an assert(s->version
== 3) before writing to qcow3 header fields, or to use
qcow2_update_header() in the first place.
Kevin
next prev parent reply other threads:[~2012-07-26 13:16 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-25 12:21 [Qemu-devel] [PATCH v2 0/7] qcow2: implement lazy refcounts optimization Stefan Hajnoczi
2012-07-25 12:21 ` [Qemu-devel] [PATCH v2 1/7] docs: add dirty bit to qcow2 specification Stefan Hajnoczi
2012-07-25 12:21 ` [Qemu-devel] [PATCH v2 2/7] qcow2: introduce dirty bit Stefan Hajnoczi
2012-07-25 12:21 ` [Qemu-devel] [PATCH v2 3/7] docs: add lazy refcounts bit to qcow2 specification Stefan Hajnoczi
2012-07-26 12:57 ` Kevin Wolf
2012-07-26 15:36 ` Stefan Hajnoczi
2012-07-25 12:21 ` [Qemu-devel] [PATCH v2 4/7] qemu-iotests: ignore qemu-img create lazy_refcounts output Stefan Hajnoczi
2012-07-25 12:21 ` [Qemu-devel] [PATCH v2 5/7] qcow2: implement lazy refcounts Stefan Hajnoczi
2012-07-26 13:15 ` Kevin Wolf [this message]
2012-07-25 12:21 ` [Qemu-devel] [PATCH v2 6/7] qemu-io: add "abort" command to simulate program crash Stefan Hajnoczi
2012-07-25 12:21 ` [Qemu-devel] [PATCH v2 7/7] qemu-iotests: add 039 qcow2 lazy refcounts test Stefan Hajnoczi
2012-07-25 17:54 ` Eric Blake
2012-07-25 22:45 ` Stefan Hajnoczi
2012-07-25 23:41 ` Eric Blake
2012-07-26 13:28 ` Kevin Wolf
2012-07-27 7:56 ` Stefan Hajnoczi
2012-07-27 8:07 ` Kevin Wolf
2012-07-30 10:09 ` 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=501142E2.6080602@redhat.com \
--to=kwolf@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=khoa@us.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@linux.vnet.ibm.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.