From: Eric Blake <eblake@redhat.com>
To: John Snow <jsnow@redhat.com>, qemu-block@nongnu.org
Cc: kwolf@redhat.com, famz@redhat.com, qemu-devel@nongnu.org,
armbru@redhat.com, vsementsov@parallels.com, stefanha@redhat.com,
mreitz@redhat.com
Subject: Re: [Qemu-devel] [PATCH v5 07/21] hbitmap: add hbitmap_merge
Date: Fri, 17 Apr 2015 09:23:42 -0600 [thread overview]
Message-ID: <5531257E.6090809@redhat.com> (raw)
In-Reply-To: <1428531604-9428-8-git-send-email-jsnow@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 2232 bytes --]
On 04/08/2015 04:19 PM, John Snow wrote:
> We add a bitmap merge operation to assist in error cases
> where we wish to combine two bitmaps together.
>
> This is algorithmically O(bits) provided HBITMAP_LEVELS remains
> constant. For a full bitmap on a 64bit machine:
> sum(bits/64^k, k, 0, HBITMAP_LEVELS) ~= 1.01587 * bits
>
> We may be able to improve running speed for particularly sparse
> bitmaps by using iterators, but the running time for dense maps
> will be worse.
>
> We present the simpler solution first, and we can refine it later
> if needed.
>
> Signed-off-by: John Snow <jsnow@redhat.com>
> Reviewed-by: Max Reitz <mreitz@redhat.com>
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
> /**
> + * hbitmap_merge:
> + * @a: The bitmap to store the result in.
> + * @b: The bitmap to merge into @a.
> + *
> + * Merge two bitmaps together.
> + * A := A (BITOR) B.
> + * B is left unmodified.
> + */
> +bool hbitmap_merge(HBitmap *a, const HBitmap *b);
No mention of what the return value means.
> +bool hbitmap_merge(HBitmap *a, const HBitmap *b)
> +{
> + int i, j;
> +
> + if ((a->size != b->size) || (a->granularity != b->granularity)) {
> + return false;
> + }
> +
> + if (hbitmap_count(b) == 0) {
> + return true;
> + }
> +
> + /* This merge is O(size), as BITS_PER_LONG and HBITMAP_LEVELS are constant.
> + * It may be possible to improve running times for sparsely populated maps
> + * by using hbitmap_iter_next, but this is suboptimal for dense maps.
> + */
> + for (i = HBITMAP_LEVELS - 1; i >= 0; i--) {
> + for (j = 0; j < a->sizes[i]; j++) {
j is 'int', but a->sizes[i] is uint64_t. If we can ever have a bitmap
large enough that its size exceeds 2G at the largest level, then we have
an inf-loop due to overflow problem.
I'd feel safer if you make j be uint64_t here; but it might also be
possible to fix 6/21 to store sizes in a smaller data type along with
appropriate assertions that our bitmaps are never big enough to need a
level with more than 2G size.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
next prev parent reply other threads:[~2015-04-17 15:23 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-08 22:19 [Qemu-devel] [PATCH v5 00/21] block: transactionless incremental backup series John Snow
2015-04-08 22:19 ` [Qemu-devel] [PATCH v5 01/21] docs: incremental backup documentation John Snow
2015-04-17 15:06 ` Eric Blake
2015-04-17 15:50 ` John Snow
2015-04-17 16:36 ` Eric Blake
2015-04-08 22:19 ` [Qemu-devel] [PATCH v5 02/21] qapi: Add optional field "name" to block dirty bitmap John Snow
2015-04-08 22:19 ` [Qemu-devel] [PATCH v5 03/21] qmp: Ensure consistent granularity type John Snow
2015-04-08 22:19 ` [Qemu-devel] [PATCH v5 04/21] qmp: Add block-dirty-bitmap-add and block-dirty-bitmap-remove John Snow
2015-04-17 14:54 ` Eric Blake
2015-04-08 22:19 ` [Qemu-devel] [PATCH v5 05/21] block: Introduce bdrv_dirty_bitmap_granularity() John Snow
2015-04-08 22:19 ` [Qemu-devel] [PATCH v5 06/21] hbitmap: cache array lengths John Snow
2015-04-17 15:18 ` Eric Blake
2015-04-08 22:19 ` [Qemu-devel] [PATCH v5 07/21] hbitmap: add hbitmap_merge John Snow
2015-04-17 15:23 ` Eric Blake [this message]
2015-04-17 21:30 ` John Snow
2015-04-08 22:19 ` [Qemu-devel] [PATCH v5 08/21] block: Add bitmap disabled status John Snow
2015-04-08 22:19 ` [Qemu-devel] [PATCH v5 09/21] block: Add bitmap successors John Snow
2015-04-17 22:43 ` Eric Blake
2015-04-17 22:56 ` John Snow
2015-04-08 22:19 ` [Qemu-devel] [PATCH v5 10/21] qmp: Add support of "dirty-bitmap" sync mode for drive-backup John Snow
2015-04-17 13:17 ` Max Reitz
2015-04-17 16:21 ` John Snow
2015-04-17 22:51 ` Eric Blake
2015-04-17 23:02 ` John Snow
2015-04-17 23:10 ` Eric Blake
2015-04-08 22:19 ` [Qemu-devel] [PATCH v5 11/21] qmp: add block-dirty-bitmap-clear John Snow
2015-04-17 22:55 ` Eric Blake
2015-04-08 22:19 ` [Qemu-devel] [PATCH v5 12/21] qmp: Add dirty bitmap status field in query-block John Snow
2015-04-17 22:55 ` Eric Blake
2015-04-08 22:19 ` [Qemu-devel] [PATCH v5 13/21] block: add BdrvDirtyBitmap documentation John Snow
2015-04-08 22:19 ` [Qemu-devel] [PATCH v5 14/21] block: Ensure consistent bitmap function prototypes John Snow
2015-04-08 22:19 ` [Qemu-devel] [PATCH v5 15/21] block: Resize bitmaps on bdrv_truncate John Snow
2015-04-09 14:38 ` Stefan Hajnoczi
2015-04-17 13:25 ` Max Reitz
2015-04-17 16:51 ` John Snow
2015-04-08 22:19 ` [Qemu-devel] [PATCH v5 16/21] hbitmap: truncate tests John Snow
2015-04-08 22:20 ` [Qemu-devel] [PATCH v5 17/21] iotests: add invalid input incremental backup tests John Snow
2015-04-08 22:20 ` [Qemu-devel] [PATCH v5 18/21] iotests: add QMP event waiting queue John Snow
2015-04-17 13:33 ` Max Reitz
2015-04-17 18:23 ` John Snow
2015-04-22 15:04 ` Max Reitz
2015-04-08 22:20 ` [Qemu-devel] [PATCH v5 19/21] iotests: add simple incremental backup case John Snow
2015-04-17 14:33 ` Max Reitz
2015-04-17 16:56 ` John Snow
2015-04-08 22:20 ` [Qemu-devel] [PATCH v5 20/21] iotests: add incremental backup failure recovery test John Snow
2015-04-17 14:33 ` Max Reitz
2015-04-08 22:20 ` [Qemu-devel] [PATCH v5 21/21] iotests: add incremental backup granularity tests John Snow
2015-04-17 14:36 ` Max Reitz
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=5531257E.6090809@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=famz@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=vsementsov@parallels.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).