From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41033) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yn725-0001KU-5L for qemu-devel@nongnu.org; Tue, 28 Apr 2015 11:02:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yn720-0002ML-At for qemu-devel@nongnu.org; Tue, 28 Apr 2015 11:02:45 -0400 From: Kevin Wolf Date: Tue, 28 Apr 2015 17:00:36 +0200 Message-Id: <1430233258-31807-55-git-send-email-kwolf@redhat.com> In-Reply-To: <1430233258-31807-1-git-send-email-kwolf@redhat.com> References: <1430233258-31807-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PULL 54/76] hbitmap: cache array lengths List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: John Snow 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 Reviewed-by: Eric Blake Signed-off-by: John Snow Reviewed-by: Stefan Hajnoczi Message-id: 1429314609-29776-7-git-send-email-jsnow@redhat.com Signed-off-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- util/hbitmap.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/util/hbitmap.c b/util/hbitmap.c index ab13971..5b78613 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -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 @@ -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); } -- 1.8.3.1