1 From 2540abec85433596dd04640b14f75ceb13bbb342 Mon Sep 17 00:00:00 2001
2 From: Fam Zheng <famz@redhat.com>
3 Date: Wed, 13 May 2015 11:11:13 +0800
4 Subject: [PATCH] block/mirror: Sleep periodically during bitmap scanning
6 Before, we only yield after initializing dirty bitmap, where the QMP
7 command would return. That may take very long, and guest IO will be
10 Add sleep points like the later mirror iterations.
12 Signed-off-by: Fam Zheng <famz@redhat.com>
13 Reviewed-by: Wen Congyang <wency@cn.fujitsu.com>
14 Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
15 Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
17 block/mirror.c | 13 ++++++++++++-
18 1 file changed, 12 insertions(+), 1 deletion(-)
20 diff --git a/block/mirror.c b/block/mirror.c
21 index 4056164..0a05971 100644
24 @@ -444,11 +444,23 @@ static void coroutine_fn mirror_run(void *opaque)
25 sectors_per_chunk = s->granularity >> BDRV_SECTOR_BITS;
28 + last_pause_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
29 if (!s->is_none_mode) {
30 /* First part, loop on the sectors and initialize the dirty bitmap. */
31 BlockDriverState *base = s->base;
32 for (sector_num = 0; sector_num < end; ) {
33 int64_t next = (sector_num | (sectors_per_chunk - 1)) + 1;
34 + int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
36 + if (now - last_pause_ns > SLICE_TIME) {
37 + last_pause_ns = now;
38 + block_job_sleep_ns(&s->common, QEMU_CLOCK_REALTIME, 0);
41 + if (block_job_is_cancelled(&s->common)) {
42 + goto immediate_exit;
45 ret = bdrv_is_allocated_above(bs, base,
46 sector_num, next - sector_num, &n);
48 @@ -455,7 +467,6 @@ static void coroutine_fn mirror_run(void *opaque)
51 bdrv_dirty_iter_init(s->dirty_bitmap, &s->hbi);
52 - last_pause_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
54 uint64_t delay_ns = 0;