Skip to content

Commit

Permalink
hbitmap: cache array lengths
Browse files Browse the repository at this point in the history
As a convenience: between incremental backups, bitmap migrations
and bitmap persistence we seem to need to recalculate these a lot.

Because the lengths are a little bit-twiddly, let's just solidly
cache them and be done with it.

Reviewed-by: Max Reitz <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Signed-off-by: John Snow <[email protected]>
Reviewed-by: Stefan Hajnoczi <[email protected]>
Message-id: [email protected]
Signed-off-by: Stefan Hajnoczi <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
  • Loading branch information
jnsnow authored and kevmw committed Apr 28, 2015
1 parent 592fdd0 commit 8515efb
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions util/hbitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ struct HBitmap {
* bitmap will still allocate HBITMAP_LEVELS arrays.
*/
unsigned long *levels[HBITMAP_LEVELS];

/* The length of each levels[] array. */
uint64_t sizes[HBITMAP_LEVELS];
};

/* Advance hbi to the next nonzero word and return it. hbi->pos
Expand Down Expand Up @@ -384,6 +387,7 @@ HBitmap *hbitmap_alloc(uint64_t size, int granularity)
hb->granularity = granularity;
for (i = HBITMAP_LEVELS; i-- > 0; ) {
size = MAX((size + BITS_PER_LONG - 1) >> BITS_PER_LEVEL, 1);
hb->sizes[i] = size;
hb->levels[i] = g_new0(unsigned long, size);
}

Expand Down

0 comments on commit 8515efb

Please sign in to comment.