qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] qcow2: Expose bitmaps' size during measure


From: Eric Blake
Subject: Re: [PATCH] qcow2: Expose bitmaps' size during measure
Date: Thu, 16 Apr 2020 16:47:48 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0

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 <address@hidden>
Signed-off-by: Eric Blake <address@hidden>
---


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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]