From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55387) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZD2oq-00078r-My for qemu-devel@nongnu.org; Wed, 08 Jul 2015 23:48:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZD2op-0004hr-MC for qemu-devel@nongnu.org; Wed, 08 Jul 2015 23:48:16 -0400 From: Fam Zheng Date: Thu, 9 Jul 2015 11:47:58 +0800 Message-Id: <1436413678-7114-4-git-send-email-famz@redhat.com> In-Reply-To: <1436413678-7114-1-git-send-email-famz@redhat.com> References: <1436413678-7114-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH 3/3] mirror: Speed up bitmap initial scanning List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Jeff Cody , qemu-block@nongnu.org Limiting to sectors_per_chunk for each bdrv_is_allocated_above is slow, because the underlying protocol driver would issue much more queries than necessary. We should coalesce the query. Signed-off-by: Fam Zheng --- block/mirror.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index ca55578..e8cb592 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -371,7 +371,7 @@ static void coroutine_fn mirror_run(void *opaque) MirrorBlockJob *s = opaque; MirrorExitData *data; BlockDriverState *bs = s->common.bs; - int64_t sector_num, end, sectors_per_chunk, length; + int64_t sector_num, end, length; uint64_t last_pause_ns; BlockDriverInfo bdi; char backing_filename[2]; /* we only need 2 characters because we are only @@ -425,7 +425,6 @@ static void coroutine_fn mirror_run(void *opaque) goto immediate_exit; } - sectors_per_chunk = s->granularity >> BDRV_SECTOR_BITS; mirror_free_init(s); last_pause_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); @@ -433,7 +432,9 @@ static void coroutine_fn mirror_run(void *opaque) /* First part, loop on the sectors and initialize the dirty bitmap. */ BlockDriverState *base = s->base; for (sector_num = 0; sector_num < end; ) { - int64_t next = (sector_num | (sectors_per_chunk - 1)) + 1; + /* Just to make sure we are not exceeding int limit. */ + int nb_sectors = MIN(INT_MAX >> BDRV_SECTOR_BITS, + end - sector_num); int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); if (now - last_pause_ns > SLICE_TIME) { @@ -444,9 +445,7 @@ static void coroutine_fn mirror_run(void *opaque) if (block_job_is_cancelled(&s->common)) { goto immediate_exit; } - - ret = bdrv_is_allocated_above(bs, base, - sector_num, next - sector_num, &n); + ret = bdrv_is_allocated_above(bs, base, sector_num, nb_sectors, &n); if (ret < 0) { goto immediate_exit; @@ -455,10 +454,8 @@ static void coroutine_fn mirror_run(void *opaque) assert(n > 0); if (ret == 1) { bdrv_set_dirty_bitmap(s->dirty_bitmap, sector_num, n); - sector_num = next; - } else { - sector_num += n; } + sector_num += n; } } -- 2.4.3