From: John Snow <jsnow@redhat.com>
To: Eric Blake <eblake@redhat.com>, qemu-devel@nongnu.org
Cc: kwolf@redhat.com, famz@redhat.com, qemu-block@nongnu.org,
Max Reitz <mreitz@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 04/12] dirty-bitmap: Track size in bytes
Date: Wed, 12 Apr 2017 19:32:05 -0400 [thread overview]
Message-ID: <e3d5a41f-46b7-0d57-5ef7-8e97baf0dcb4@redhat.com> (raw)
In-Reply-To: <20170412174920.8744-5-eblake@redhat.com>
On 04/12/2017 01:49 PM, Eric Blake wrote:
> We are still using an internal hbitmap that tracks a size in sectors,
> with the granularity scaled down accordingly, because it lets us
> use a shortcut for our iterators which are currently sector-based.
> But there's no reason we can't track the dirty bitmap size in bytes,
> since it is an internal-only variable.
>
> Signed-off-by: Eric Blake <eblake@redhat.com>
> ---
> block/dirty-bitmap.c | 23 +++++++++++++----------
> 1 file changed, 13 insertions(+), 10 deletions(-)
>
> diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c
> index 32698d5..a413df1 100644
> --- a/block/dirty-bitmap.c
> +++ b/block/dirty-bitmap.c
> @@ -41,7 +41,7 @@ struct BdrvDirtyBitmap {
> HBitmap *meta; /* Meta dirty bitmap */
> BdrvDirtyBitmap *successor; /* Anonymous child; implies frozen status */
> char *name; /* Optional non-empty unique ID */
> - int64_t size; /* Size of the bitmap (Number of sectors) */
> + int64_t size; /* Size of the bitmap, in bytes */
> bool disabled; /* Bitmap is read-only */
> int active_iterators; /* How many iterators are active */
> QLIST_ENTRY(BdrvDirtyBitmap) list;
> @@ -79,24 +79,26 @@ BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
> {
> int64_t bitmap_size;
> BdrvDirtyBitmap *bitmap;
> - uint32_t sector_granularity;
>
> - assert((granularity & (granularity - 1)) == 0);
> + assert(is_power_of_2(granularity) && granularity >= BDRV_SECTOR_SIZE);
>
> if (name && bdrv_find_dirty_bitmap(bs, name)) {
> error_setg(errp, "Bitmap already exists: %s", name);
> return NULL;
> }
> - sector_granularity = granularity >> BDRV_SECTOR_BITS;
> - assert(sector_granularity);
> - bitmap_size = bdrv_nb_sectors(bs);
> + bitmap_size = bdrv_getlength(bs);
> if (bitmap_size < 0) {
> error_setg_errno(errp, -bitmap_size, "could not get length of device");
> errno = -bitmap_size;
> return NULL;
> }
> bitmap = g_new0(BdrvDirtyBitmap, 1);
> - bitmap->bitmap = hbitmap_alloc(bitmap_size, ctz32(sector_granularity));
> + /*
> + * TODO - let hbitmap track full granularity. For now, it is tracking
> + * only sector granularity, as a shortcut for our iterators.
> + */
> + bitmap->bitmap = hbitmap_alloc(bitmap_size >> BDRV_SECTOR_BITS,
> + ctz32(granularity) - BDRV_SECTOR_BITS);
> bitmap->size = bitmap_size;
> bitmap->name = g_strdup(name);
> bitmap->disabled = false;
> @@ -246,12 +248,13 @@ BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDriverState *bs,
> void bdrv_dirty_bitmap_truncate(BlockDriverState *bs)
> {
> BdrvDirtyBitmap *bitmap;
> - uint64_t size = bdrv_nb_sectors(bs);
> + int64_t size = bdrv_getlength(bs);
>
> + assert(size >= 0);
> QLIST_FOREACH(bitmap, &bs->dirty_bitmaps, list) {
> assert(!bdrv_dirty_bitmap_frozen(bitmap));
> assert(!bitmap->active_iterators);
> - hbitmap_truncate(bitmap->bitmap, size);
> + hbitmap_truncate(bitmap->bitmap, size >> BDRV_SECTOR_BITS);
> bitmap->size = size;
> }
> }
> @@ -419,7 +422,7 @@ void bdrv_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap **out)
> hbitmap_reset_all(bitmap->bitmap);
> } else {
> HBitmap *backup = bitmap->bitmap;
> - bitmap->bitmap = hbitmap_alloc(bitmap->size,
> + bitmap->bitmap = hbitmap_alloc(bitmap->size >> BDRV_SECTOR_BITS,
> hbitmap_granularity(backup));
> *out = backup;
> }
>
Reviewed-by: John Snow <jsnow@redhat.com>
next prev parent reply other threads:[~2017-04-12 23:32 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-12 17:49 [Qemu-devel] [PATCH 00/12] make dirty-bitmap byte-based Eric Blake
2017-04-12 17:49 ` [Qemu-devel] [PATCH 01/12] dirty-bitmap: Report BlockDirtyInfo.count in bytes, as documented Eric Blake
2017-04-12 22:43 ` John Snow
2017-04-12 17:49 ` [Qemu-devel] [PATCH 02/12] migration: Don't lose errno across aio context changes Eric Blake
2017-04-12 22:44 ` John Snow
2017-04-18 20:02 ` Juan Quintela
2017-04-12 17:49 ` [Qemu-devel] [PATCH 03/12] dirty-bitmap: Drop unused functions Eric Blake
2017-04-12 22:47 ` John Snow
2017-04-12 23:36 ` Eric Blake
2017-04-12 23:40 ` John Snow
2017-04-13 9:19 ` Vladimir Sementsov-Ogievskiy
2017-04-13 16:57 ` John Snow
2017-04-12 17:49 ` [Qemu-devel] [PATCH 04/12] dirty-bitmap: Track size in bytes Eric Blake
2017-04-12 23:32 ` John Snow [this message]
2017-04-12 17:49 ` [Qemu-devel] [PATCH 05/12] dirty-bitmap: Set iterator start by offset, not sector Eric Blake
2017-04-13 0:00 ` John Snow
2017-04-12 17:49 ` [Qemu-devel] [PATCH 06/12] dirty-bitmap: Change bdrv_dirty_iter_next() to report byte offset Eric Blake
2017-04-13 0:10 ` John Snow
2017-04-12 17:49 ` [Qemu-devel] [PATCH 07/12] dirty-bitmap: Change bdrv_get_dirty_count() to report bytes Eric Blake
2017-04-13 0:19 ` John Snow
2017-04-13 0:22 ` John Snow
2017-04-12 17:49 ` [Qemu-devel] [PATCH 08/12] dirty-bitmap: Change bdrv_get_dirty() to take bytes Eric Blake
2017-04-13 0:25 ` John Snow
2017-04-13 0:48 ` Eric Blake
2017-04-12 17:49 ` [Qemu-devel] [PATCH 09/12] dirty-bitmap: Change bdrv_[re]set_dirty_bitmap() to use bytes Eric Blake
2017-04-13 0:29 ` John Snow
2017-04-12 17:49 ` [Qemu-devel] [PATCH 10/12] mirror: Switch mirror_dirty_init() to byte-based iteration Eric Blake
2017-04-13 1:24 ` John Snow
2017-04-12 17:49 ` [Qemu-devel] [PATCH 11/12] dirty-bitmap: Switch bdrv_set_dirty() to bytes Eric Blake
2017-04-13 1:28 ` John Snow
2017-04-12 17:49 ` [Qemu-devel] [PATCH 12/12] dirty-bitmap: Convert internal hbitmap size/granularity Eric Blake
2017-04-13 1:38 ` John Snow
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=e3d5a41f-46b7-0d57-5ef7-8e97baf0dcb4@redhat.com \
--to=jsnow@redhat.com \
--cc=eblake@redhat.com \
--cc=famz@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@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).