qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Fam Zheng <famz@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Jeff Cody <jcody@redhat.com>,
	qemu-block@nongnu.org
Subject: [Qemu-devel] [PATCH 3/3] mirror: Speed up bitmap initial scanning
Date: Thu,  9 Jul 2015 11:47:58 +0800	[thread overview]
Message-ID: <1436413678-7114-4-git-send-email-famz@redhat.com> (raw)
In-Reply-To: <1436413678-7114-1-git-send-email-famz@redhat.com>

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 <famz@redhat.com>
---
 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

  parent reply	other threads:[~2015-07-09  3:48 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-09  3:47 [Qemu-devel] [PATCH 0/3] mirror: Fix guest responsiveness during bitmap scan Fam Zheng
2015-07-09  3:47 ` [Qemu-devel] [PATCH 1/3] blockjob: Introduce block_job_relax_cpu Fam Zheng
2015-07-09 12:54   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2015-07-10  3:42     ` Alexandre DERUMIER
2015-07-14 12:31       ` Stefan Hajnoczi
2015-07-15 10:32         ` Fam Zheng
2015-07-16 13:21           ` Stefan Hajnoczi
2015-07-09  3:47 ` [Qemu-devel] [PATCH 2/3] mirror: Use block_job_relax_cpu during bitmap scanning Fam Zheng
2015-07-09 13:00   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2015-07-09  3:47 ` Fam Zheng [this message]
2015-07-09 13:00   ` [Qemu-devel] [PATCH 3/3] mirror: Speed up bitmap initial scanning Stefan Hajnoczi
2015-07-14 13:21   ` Stefan Hajnoczi
2015-07-09 11:51 ` [Qemu-devel] [PATCH 0/3] mirror: Fix guest responsiveness during bitmap scan Alexandre DERUMIER
2015-07-09 13:02 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2015-07-09 13:18   ` Alexandre DERUMIER
2015-07-10  6:43   ` Fam Zheng
2015-07-10  6:54     ` Alexandre DERUMIER
2015-07-10  7:13       ` Fam Zheng
2015-07-10 10:36         ` Alexandre DERUMIER
2015-07-10 12:16           ` Alexandre DERUMIER
2015-07-13  5:08             ` Fam Zheng
2015-07-14 12:40               ` Stefan Hajnoczi

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=1436413678-7114-4-git-send-email-famz@redhat.com \
    --to=famz@redhat.com \
    --cc=jcody@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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).