From: Max Reitz <mreitz@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
qemu-block@nongnu.org
Cc: kwolf@redhat.com, jsnow@redhat.com, qemu-devel@nongnu.org,
den@openvz.org
Subject: Re: [PATCH v3 07/10] block/dirty-bitmap: improve _next_dirty_area API
Date: Mon, 20 Jan 2020 14:58:47 +0100 [thread overview]
Message-ID: <19eb1ec8-4532-5287-0c20-6b7749491da1@redhat.com> (raw)
In-Reply-To: <20191219100348.24827-8-vsementsov@virtuozzo.com>
[-- Attachment #1.1: Type: text/plain, Size: 4935 bytes --]
On 19.12.19 11:03, Vladimir Sementsov-Ogievskiy wrote:
> Firstly, _next_dirty_area is for scenarios when we may contiguously
> search for next dirty area inside some limited region, so it is more
> comfortable to specify "end" which should not be recalculated on each
> iteration.
>
> Secondly, let's add a possibility to limit resulting area size, not
> limiting searching area. This will be used in NBD code in further
> commit. (Note that now bdrv_dirty_bitmap_next_dirty_area is unused)
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
> include/block/dirty-bitmap.h | 3 ++-
> include/qemu/hbitmap.h | 25 ++++++++++++---------
> block/dirty-bitmap.c | 6 +++--
> tests/test-hbitmap.c | 43 +++++++++++++++++++++++-------------
> util/hbitmap.c | 41 +++++++++++++++++++++-------------
> 5 files changed, 74 insertions(+), 44 deletions(-)
[...]
> /**
> diff --git a/tests/test-hbitmap.c b/tests/test-hbitmap.c
> index e3f1b3f361..d75e84a76a 100644
> --- a/tests/test-hbitmap.c
> +++ b/tests/test-hbitmap.c
> @@ -920,18 +920,19 @@ static void test_hbitmap_next_x_after_truncate(TestHBitmapData *data,
> test_hbitmap_next_x_check(data, 0);
> }
>
> -static void test_hbitmap_next_dirty_area_check(TestHBitmapData *data,
> - int64_t offset,
> - int64_t count)
> +static void test_hbitmap_next_dirty_area_check_limited(TestHBitmapData *data,
> + int64_t offset,
> + int64_t count,
> + int64_t max_dirty)
> {
> int64_t off1, off2;
> int64_t len1 = 0, len2;
> bool ret1, ret2;
> int64_t end;
>
> - off1 = offset;
> - len1 = count;
> - ret1 = hbitmap_next_dirty_area(data->hb, &off1, &len1);
> + ret1 = hbitmap_next_dirty_area(data->hb,
> + offset, count == INT64_MAX ? INT64_MAX : offset + count, max_dirty,
> + &off1, &len1);
>
> end = offset > data->size || data->size - offset < count ? data->size :
> offset + count;
> @@ -940,21 +941,25 @@ static void test_hbitmap_next_dirty_area_check(TestHBitmapData *data,
> ;
These empty statements look a bit weird to me. But they’re
pre-existing, obviously.
> }
>
> - for (len2 = 1; off2 + len2 < end && hbitmap_get(data->hb, off2 + len2);
> - len2++) {
> + for (len2 = 1; (off2 + len2 < end && len2 < max_dirty &&
> + hbitmap_get(data->hb, off2 + len2)); len2++)
> + {
> ;
> }
[...]
> diff --git a/util/hbitmap.c b/util/hbitmap.c
> index d23f4b9678..2a1661ec1d 100644
> --- a/util/hbitmap.c
> +++ b/util/hbitmap.c
> @@ -270,22 +270,34 @@ int64_t hbitmap_next_zero(const HBitmap *hb, int64_t start, int64_t count)
> return res;
> }
>
> -bool hbitmap_next_dirty_area(const HBitmap *hb, int64_t *start, int64_t *count)
> +bool hbitmap_next_dirty_area(const HBitmap *hb, int64_t start, int64_t end,
> + int64_t max_dirty_count,
> + int64_t *dirty_start, int64_t *dirty_count)
> {
> - int64_t area_start, area_end;
> + int64_t next_zero;
>
> - area_start = hbitmap_next_dirty(hb, *start, *count);
> - if (area_start < 0) {
> + assert(start >= 0 && end >= 0 && max_dirty_count > 0);
> +
> + if (start >= hb->orig_size || end <= start) {
> + return false;
> + }
> +
> + end = MIN(end, hb->orig_size);
You could put this assignment before the if () and then drop the “start”
check from the condition. (But that’s mostly me itching to do
optimizations. I don’t think it’d make the code easier to read.)
[...]
> @@ -844,13 +856,12 @@ static void hbitmap_sparse_merge(HBitmap *dst, const HBitmap *src)
> int64_t offset = 0;
> int64_t count = src->orig_size;
These initializations are now unnecessary. I’d drop them because I find
at least the one for @count a tiny bit confusing now. (Because as a
reader, I’d wonder where this value is used.)
With that done (or maybe not because you disagree):
Reviewed-by: Max Reitz <mreitz@redhat.com>
>
> - while (hbitmap_next_dirty_area(src, &offset, &count)) {
> + for (offset = 0;
> + hbitmap_next_dirty_area(src, offset, src->orig_size, INT64_MAX,
> + &offset, &count);
> + offset += count)
> + {
> hbitmap_set(dst, offset, count);
> - offset += count;
> - if (offset >= src->orig_size) {
> - break;
> - }
> - count = src->orig_size - offset;
> }
> }
>
>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2020-01-20 14:02 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-19 10:03 [PATCH v3 00/10] Further bitmaps improvements Vladimir Sementsov-Ogievskiy
2019-12-19 10:03 ` [PATCH v3 01/10] hbitmap: assert that we don't create bitmap larger than INT64_MAX Vladimir Sementsov-Ogievskiy
2020-01-20 10:51 ` Max Reitz
2019-12-19 10:03 ` [PATCH v3 02/10] hbitmap: move hbitmap_iter_next_word to hbitmap.c Vladimir Sementsov-Ogievskiy
2020-01-20 10:55 ` Max Reitz
2020-01-20 16:14 ` Vladimir Sementsov-Ogievskiy
2019-12-19 10:03 ` [PATCH v3 03/10] hbitmap: unpublish hbitmap_iter_skip_words Vladimir Sementsov-Ogievskiy
2020-01-20 10:59 ` Max Reitz
2019-12-19 10:03 ` [PATCH v3 04/10] hbitmap: drop meta bitmaps as they are unused Vladimir Sementsov-Ogievskiy
2020-01-20 11:13 ` Max Reitz
2020-01-20 16:20 ` Vladimir Sementsov-Ogievskiy
2020-01-20 17:05 ` Max Reitz
2020-01-20 17:28 ` Vladimir Sementsov-Ogievskiy
2020-01-20 19:53 ` Eric Blake
2020-01-21 9:15 ` Vladimir Sementsov-Ogievskiy
2019-12-19 10:03 ` [PATCH v3 05/10] block/dirty-bitmap: switch _next_dirty_area and _next_zero to int64_t Vladimir Sementsov-Ogievskiy
2020-01-20 11:59 ` Max Reitz
2020-01-20 12:28 ` Vladimir Sementsov-Ogievskiy
2020-01-20 12:53 ` Max Reitz
2020-01-20 19:56 ` Eric Blake
2019-12-19 10:03 ` [PATCH v3 06/10] block/dirty-bitmap: add _next_dirty API Vladimir Sementsov-Ogievskiy
2020-01-20 13:14 ` Max Reitz
2020-01-20 16:30 ` Vladimir Sementsov-Ogievskiy
2020-01-21 9:35 ` Vladimir Sementsov-Ogievskiy
2019-12-19 10:03 ` [PATCH v3 07/10] block/dirty-bitmap: improve _next_dirty_area API Vladimir Sementsov-Ogievskiy
2020-01-20 13:58 ` Max Reitz [this message]
2020-01-20 16:26 ` Vladimir Sementsov-Ogievskiy
2019-12-19 10:03 ` [PATCH v3 08/10] nbd/server: introduce NBDExtentArray Vladimir Sementsov-Ogievskiy
2020-01-20 20:20 ` Eric Blake
2020-01-21 10:25 ` Vladimir Sementsov-Ogievskiy
2019-12-19 10:03 ` [PATCH v3 09/10] nbd/server: use bdrv_dirty_bitmap_next_dirty_area Vladimir Sementsov-Ogievskiy
2020-01-20 20:23 ` Eric Blake
2019-12-19 10:03 ` [PATCH v3 10/10] block/qcow2-bitmap: use bdrv_dirty_bitmap_next_dirty Vladimir Sementsov-Ogievskiy
2020-01-20 14:18 ` Max Reitz
2020-01-20 16:05 ` Vladimir Sementsov-Ogievskiy
2020-01-20 9:08 ` [PATCH v3 00/10] Further bitmaps improvements Vladimir Sementsov-Ogievskiy
2020-01-20 14:20 ` Max Reitz
2020-01-20 16:33 ` Vladimir Sementsov-Ogievskiy
2020-01-20 20:25 ` 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=19eb1ec8-4532-5287-0c20-6b7749491da1@redhat.com \
--to=mreitz@redhat.com \
--cc=den@openvz.org \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=vsementsov@virtuozzo.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 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).