From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
qemu-block@nongnu.org, Markus Armbruster <armbru@redhat.com>,
Max Reitz <mreitz@redhat.com>,
nsoffer@redhat.com, jsnow@redhat.com
Subject: Re: [PATCH] qcow2: Expose bitmaps' size during measure
Date: Thu, 16 Apr 2020 16:47:48 -0500 [thread overview]
Message-ID: <df0c78ec-19f6-9fa6-1ca6-896f80026614@redhat.com> (raw)
In-Reply-To: <20200416212349.731404-1-eblake@redhat.com>
On 4/16/20 4:23 PM, Eric Blake wrote:
> It's useful to know how much space can be occupied by qcow2 persistent
> bitmaps, even though such metadata is unrelated to the guest-visible
> data. Report this value as an additional field.
>
> Reported-by: Nir Soffer <nsoffer@redhat.com>
> Signed-off-by: Eric Blake <eblake@redhat.com>
> ---
>
Per https://bugzilla.redhat.com/show_bug.cgi?id=1779904#c0, I didn't
quite round up in enough places:
> @@ -4739,6 +4742,26 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts, BlockDriverState *in_bs,
> goto err;
> }
>
> + FOR_EACH_DIRTY_BITMAP(in_bs, bm) {
> + if (bdrv_dirty_bitmap_get_persistence(bm)) {
> + uint64_t bmsize = bdrv_dirty_bitmap_size(bm);
> + uint32_t granularity = bdrv_dirty_bitmap_granularity(bm);
> + const char *name = bdrv_dirty_bitmap_name(bm);
> + uint64_t bmclusters = DIV_ROUND_UP(bmsize / granularity
> + / CHAR_BIT, cluster_size);
All of these divisions need to round up. For example, in an image with
512-byte clusters and granularity, and a bitmap covering 512*512*8+512
bytes (2097664), we need 2 clusters, not 1, for the bitmap itself.
Fortunately, it is an edge case, and we usually have enough slop in the
final round up to cluster size that most users won't trip on this.
> +
> + /* Assume the entire bitmap is allocated */
> + bitmaps_size += bmclusters * cluster_size;
> + /* Also reserve space for the bitmap table entries */
> + bitmaps_size += ROUND_UP(bmclusters * sizeof(uint64_t),
> + cluster_size);
> + /* Guess at contribution to bitmap directory size */
> + bitmap_overhead += ROUND_UP(strlen(name) + 24,
And I don't like this magic number, but sizeof(Qcow2BitmapDirEntry) from
qcow2-bitmap.c is a private struct not accessible here.
> + sizeof(uint64_t));
> + }
> + }
> + bitmaps_size += ROUND_UP(bitmap_overhead, cluster_size);
> +
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
next prev parent reply other threads:[~2020-04-16 21:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-16 21:23 [PATCH] qcow2: Expose bitmaps' size during measure Eric Blake
2020-04-16 21:47 ` Eric Blake [this message]
2020-04-16 22:49 ` no-reply
2020-04-17 0:17 ` Eric Blake
2020-04-17 13:20 ` Eric Blake
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=df0c78ec-19f6-9fa6-1ca6-896f80026614@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=nsoffer@redhat.com \
--cc=qemu-block@nongnu.org \
--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).