block/mirror: Sleep periodically during bitmap scanning
PATCH 1/1 block/mirror: Sleep periodically during bitmap scanning
Before, we only yield after initializing dirty bitmap, where the QMP command would return. That may take very long, and guest IO will be blocked.
Add sleep points like the later mirror iterations.
--- block/mirror.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
block/mirror.c +12 -1
@@ -467,11 +467,23 @@ static void coroutine_fn mirror_run(void *opaque) sectors_per_chunk = s->granularity >>BDRV_SECTOR_BITS ;mirror_free_init (s); + last_pause_ns =qemu_clock_get_ns (QEMU_CLOCK_REALTIME );if (!s->is_none_mode) {/* 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 ; +int64_t now =qemu_clock_get_ns (QEMU_CLOCK_REALTIME ); + +if (now - last_pause_ns >SLICE_TIME ) { + last_pause_ns = now; +block_job_sleep_ns (&s->common,QEMU_CLOCK_REALTIME ,0 ); + } + +if (block_job_is_cancelled (&s->common)) { + goto immediate_exit; + } + ret =bdrv_is_allocated_above (bs, base, sector_num, next - sector_num, &n);
@@ -490,7 +502,6 @@ static void coroutine_fn mirror_run(void *opaque) }bdrv_dirty_iter_init (s->dirty_bitmap, &s->hbi); - last_pause_ns =qemu_clock_get_ns (QEMU_CLOCK_REALTIME );for (;;) {uint64_t delay_ns =0 ;int64_t cnt;
Signature · 1 line
2.4.0
Quoted 3 lines · Fam Zheng
Before, we only yield after initializing dirty bitmap, where the QMP command would return. That may take very long, and guest IO will be blocked.
Do you have such case to reproduce it? If the disk image is too larger, and I think qemu doesn't cache all metedata in the memory. So we will yield in bdrv_is_allocated_above() when we read the metedata from the disk.
Thanks
Wen Congyang
Quoted 45 lines
Add sleep points like the later mirror iterations.
Signed-off-by Fam Zheng <[email protected]>--- block/mirror.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)block/mirror.c +12
-1@@ -467,11 +467,23 @@ static void coroutine_fn mirror_run(void *opaque) sectors_per_chunk = s->granularity >>BDRV_SECTOR_BITS ;mirror_free_init (s); + last_pause_ns =qemu_clock_get_ns (QEMU_CLOCK_REALTIME );if (!s->is_none_mode) {/* 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 ; +int64_t now =qemu_clock_get_ns (QEMU_CLOCK_REALTIME ); + +if (now - last_pause_ns >SLICE_TIME ) { + last_pause_ns = now; +block_job_sleep_ns (&s->common,QEMU_CLOCK_REALTIME ,0 ); + } + +if (block_job_is_cancelled (&s->common)) { + goto immediate_exit; + } + ret =bdrv_is_allocated_above (bs, base, sector_num, next - sector_num, &n);@@ -490,7 +502,6 @@ static void coroutine_fn mirror_run(void *opaque) }bdrv_dirty_iter_init (s->dirty_bitmap, &s->hbi); - last_pause_ns =qemu_clock_get_ns (QEMU_CLOCK_REALTIME );for (;;) {uint64_t delay_ns =0 ;int64_t cnt;
Quoted 9 lines · Wen Congyang
Quoted 3 lines · Fam Zheng
Before, we only yield after initializing dirty bitmap, where the QMP command would return. That may take very long, and guest IO will be blocked.
Do you have such case to reproduce it? If the disk image is too larger, and I think qemu doesn't cache all metedata in the memory. So we will yield in
bdrv_is_allocated_above()when we read the metedata from the disk.
True for qcow2, but raw-posix has no such yield points, because it uses lseek(..., SEEK_HOLE). I do have a reproducer - just try a big raw image on your ext4.
Fam
Quoted 50 lines
Thanks
Wen CongyangQuoted 45 lines
Add sleep points like the later mirror iterations.
Signed-off-by Fam Zheng <[email protected]>--- block/mirror.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)block/mirror.c +12
-1@@ -467,11 +467,23 @@ static void coroutine_fn mirror_run(void *opaque) sectors_per_chunk = s->granularity >>BDRV_SECTOR_BITS ;mirror_free_init (s); + last_pause_ns =qemu_clock_get_ns (QEMU_CLOCK_REALTIME );if (!s->is_none_mode) {/* 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 ; +int64_t now =qemu_clock_get_ns (QEMU_CLOCK_REALTIME ); + +if (now - last_pause_ns >SLICE_TIME ) { + last_pause_ns = now; +block_job_sleep_ns (&s->common,QEMU_CLOCK_REALTIME ,0 ); + } + +if (block_job_is_cancelled (&s->common)) { + goto immediate_exit; + } + ret =bdrv_is_allocated_above (bs, base, sector_num, next - sector_num, &n);@@ -490,7 +502,6 @@ static void coroutine_fn mirror_run(void *opaque) }bdrv_dirty_iter_init (s->dirty_bitmap, &s->hbi); - last_pause_ns =qemu_clock_get_ns (QEMU_CLOCK_REALTIME );for (;;) {uint64_t delay_ns =0 ;int64_t cnt;
Quoted 6 lines · Fam Zheng
Quoted 5 lines · Wen Congyang
Quoted 3 lines · Fam Zheng
Before, we only yield after initializing dirty bitmap, where the QMP command would return. That may take very long, and guest IO will be blocked.
Quoted 8 lines
Quoted 4 lines
Do you have such case to reproduce it? If the disk image is too larger, and I think qemu doesn't cache all metedata in the memory. So we will yield in
bdrv_is_allocated_above()when we read the metedata from the disk.True for qcow2, but raw-posix has no such yield points, because it uses
lseek(..., SEEK_HOLE). I do have a reproducer - just try a big raw image on your ext4.
It is the filesystem's problem. If we mirror a big empty raw image, lseek(..., SEEK_DATA) may needs some seconds(about 5s for 500G empty raw image). Even if the granularity is 64K, we need to call this syscall 8192000(500G/64K) times. We may need more than half year...
So I think we should allow bdrv_is_allocated() and other APIs to return a larger p_num than nb_sectors.
Thanks
Wen Congyang
Quoted 55 lines
Fam
Quoted 43 lines
Thanks
Wen CongyangQuoted 39 lines
Add sleep points like the later mirror iterations.
Signed-off-by Fam Zheng <[email protected]>--- block/mirror.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)block/mirror.c +12
-0@@ -467,11 +467,23 @@ static void coroutine_fn mirror_run(void *opaque) sectors_per_chunk = s->granularity >>BDRV_SECTOR_BITS ;mirror_free_init (s); + last_pause_ns =qemu_clock_get_ns (QEMU_CLOCK_REALTIME );if (!s->is_none_mode) {/* 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 ; +int64_t now =qemu_clock_get_ns (QEMU_CLOCK_REALTIME ); + +if (now - last_pause_ns >SLICE_TIME ) { + last_pause_ns = now; +block_job_sleep_ns (&s->common,QEMU_CLOCK_REALTIME ,0 ); + } + +if (block_job_is_cancelled (&s->common)) { + goto immediate_exit; + } + ret =bdrv_is_allocated_above (bs, base, sector_num, next - sector_num, &n);@@ -490,7 +502,6 @@ static void coroutine_fn mirror_run(void *opaque) }Quoted 7 lines
block/mirror.c static void coroutine_fn mirror_run(void *opaque) · line 507
Quoted 6 lines
block/mirror.c +0
-1bdrv_dirty_iter_init (s->dirty_bitmap, &s->hbi); - last_pause_ns =qemu_clock_get_ns (QEMU_CLOCK_REALTIME );for (;;) {uint64_t delay_ns =0 ;int64_t cnt;.
Quoted 7 lines · Fam Zheng
Before, we only yield after initializing dirty bitmap, where the QMP command would return. That may take very long, and guest IO will be blocked.
Add sleep points like the later mirror iterations.
Signed-off-by Fam Zheng <[email protected]>
Quoted 41 lines
--- block/mirror.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)block/mirror.c +12
-1@@ -467,11 +467,23 @@ static void coroutine_fn mirror_run(void *opaque) sectors_per_chunk = s->granularity >>BDRV_SECTOR_BITS ;mirror_free_init (s); + last_pause_ns =qemu_clock_get_ns (QEMU_CLOCK_REALTIME );if (!s->is_none_mode) {/* 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 ; +int64_t now =qemu_clock_get_ns (QEMU_CLOCK_REALTIME ); + +if (now - last_pause_ns >SLICE_TIME ) { + last_pause_ns = now; +block_job_sleep_ns (&s->common,QEMU_CLOCK_REALTIME ,0 ); + } + +if (block_job_is_cancelled (&s->common)) { + goto immediate_exit; + } + ret =bdrv_is_allocated_above (bs, base, sector_num, next - sector_num, &n);@@ -490,7 +502,6 @@ static void coroutine_fn mirror_run(void *opaque) }bdrv_dirty_iter_init (s->dirty_bitmap, &s->hbi); - last_pause_ns =qemu_clock_get_ns (QEMU_CLOCK_REALTIME );for (;;) {uint64_t delay_ns =0 ;int64_t cnt;
Quoted 5 lines · Fam Zheng
Before, we only yield after initializing dirty bitmap, where the QMP command would return. That may take very long, and guest IO will be blocked.
Add sleep points like the later mirror iterations.
You were also planning to let bdrv_co_is_allocated/get_block_status return a larger p_num than nb_sectors---which maybe could make nb_sectors obsolete completely, I don't know. But this is already an improvement.
Thanks,
Paolo
Quoted 43 lines
Signed-off-by Fam Zheng <[email protected]>--- block/mirror.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)block/mirror.c +12
-1@@ -467,11 +467,23 @@ static void coroutine_fn mirror_run(void *opaque) sectors_per_chunk = s->granularity >>BDRV_SECTOR_BITS ;mirror_free_init (s); + last_pause_ns =qemu_clock_get_ns (QEMU_CLOCK_REALTIME );if (!s->is_none_mode) {/* 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 ; +int64_t now =qemu_clock_get_ns (QEMU_CLOCK_REALTIME ); + +if (now - last_pause_ns >SLICE_TIME ) { + last_pause_ns = now; +block_job_sleep_ns (&s->common,QEMU_CLOCK_REALTIME ,0 ); + } + +if (block_job_is_cancelled (&s->common)) { + goto immediate_exit; + } + ret =bdrv_is_allocated_above (bs, base, sector_num, next - sector_num, &n);@@ -490,7 +502,6 @@ static void coroutine_fn mirror_run(void *opaque) }bdrv_dirty_iter_init (s->dirty_bitmap, &s->hbi); - last_pause_ns =qemu_clock_get_ns (QEMU_CLOCK_REALTIME );for (;;) {uint64_t delay_ns =0 ;int64_t cnt;
Quoted 10 lines · Fam Zheng
Before, we only yield after initializing dirty bitmap, where the QMP command would return. That may take very long, and guest IO will be blocked.
Add sleep points like the later mirror iterations.
Signed-off-by Fam Zheng <[email protected]>--- block/mirror.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
CCing Jeff Cody for block jobs.
Quoted 41 lines
block/mirror.c +12
-1@@ -467,11 +467,23 @@ static void coroutine_fn mirror_run(void *opaque) sectors_per_chunk = s->granularity >>BDRV_SECTOR_BITS ;mirror_free_init (s); + last_pause_ns =qemu_clock_get_ns (QEMU_CLOCK_REALTIME );if (!s->is_none_mode) {/* 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 ; +int64_t now =qemu_clock_get_ns (QEMU_CLOCK_REALTIME ); + +if (now - last_pause_ns >SLICE_TIME ) { + last_pause_ns = now; +block_job_sleep_ns (&s->common,QEMU_CLOCK_REALTIME ,0 ); + } + +if (block_job_is_cancelled (&s->common)) { + goto immediate_exit; + } + ret =bdrv_is_allocated_above (bs, base, sector_num, next - sector_num, &n);@@ -490,7 +502,6 @@ static void coroutine_fn mirror_run(void *opaque) }bdrv_dirty_iter_init (s->dirty_bitmap, &s->hbi); - last_pause_ns =qemu_clock_get_ns (QEMU_CLOCK_REALTIME );for (;;) {uint64_t delay_ns =0 ;int64_t cnt;Signature · 1 line
2.4.0
Quoted 10 lines · Fam Zheng
Before, we only yield after initializing dirty bitmap, where the QMP command would return. That may take very long, and guest IO will be blocked.
Add sleep points like the later mirror iterations.
Signed-off-by Fam Zheng <[email protected]>--- block/mirror.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
Ping for Jeff
Jeff Cody
AppliedQuoted 50 lines · Fam Zheng
Before, we only yield after initializing dirty bitmap, where the QMP command would return. That may take very long, and guest IO will be blocked.
Add sleep points like the later mirror iterations.
Signed-off-by Fam Zheng <[email protected]>--- block/mirror.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)block/mirror.c +12
-1@@ -467,11 +467,23 @@ static void coroutine_fn mirror_run(void *opaque) sectors_per_chunk = s->granularity >>BDRV_SECTOR_BITS ;mirror_free_init (s); + last_pause_ns =qemu_clock_get_ns (QEMU_CLOCK_REALTIME );if (!s->is_none_mode) {/* 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 ; +int64_t now =qemu_clock_get_ns (QEMU_CLOCK_REALTIME ); + +if (now - last_pause_ns >SLICE_TIME ) { + last_pause_ns = now; +block_job_sleep_ns (&s->common,QEMU_CLOCK_REALTIME ,0 ); + } + +if (block_job_is_cancelled (&s->common)) { + goto immediate_exit; + } + ret =bdrv_is_allocated_above (bs, base, sector_num, next - sector_num, &n);@@ -490,7 +502,6 @@ static void coroutine_fn mirror_run(void *opaque) }bdrv_dirty_iter_init (s->dirty_bitmap, &s->hbi); - last_pause_ns =qemu_clock_get_ns (QEMU_CLOCK_REALTIME );for (;;) {uint64_t delay_ns =0 ;int64_t cnt;Signature · 1 line
2.4.0
Thanks, applied to my block tree:
https://github.com/codyprime/qemu-kvm-jtc/commits/block
Jeff
Alexandre DERUMIER
AppliedHi,
I'm currently testing this patch,
and it still hanging for me (mirroring a raw file from nfs)
I just wonder why block_job_sleep_ns is set to 0 ?
+ block_job_sleep_ns(&s->common, QEMU_CLOCK_REALTIME, 0);
I have tried to increasing it to a bigger value
+ block_job_sleep_ns(&s->common, QEMU_CLOCK_REALTIME, 100000000);
And now it's working fine for me, no more qemu hang
----- Mail original -----
De: "Jeff Cody" <[email protected]>
À: "Fam Zheng" <[email protected]>
Cc: "Kevin Wolf" <[email protected]>, "pbonzini" <[email protected]>, "qemu-devel" <[email protected]>, [email protected] Envoyé: Mardi 16 Juin 2015 06:06:25
Objet: Re: [Qemu-devel] [PATCH] block/mirror: Sleep periodically during bitmap scanning
Quoted 50 lines · Fam Zheng
Before, we only yield after initializing dirty bitmap, where the QMP command would return. That may take very long, and guest IO will be blocked.
Add sleep points like the later mirror iterations.
Signed-off-by Fam Zheng <[email protected]>---
block/mirror.c| 13 ++++++++++++-1 file changed, 12 insertions(+), 1 deletion(-)block/mirror.c +12
-1@@ -467,11 +467,23 @@ static void coroutine_fn mirror_run(void *opaque) sectors_per_chunk = s->granularity >>BDRV_SECTOR_BITS ;mirror_free_init (s); + last_pause_ns =qemu_clock_get_ns (QEMU_CLOCK_REALTIME );if (!s->is_none_mode) {/* 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 ; +int64_t now =qemu_clock_get_ns (QEMU_CLOCK_REALTIME ); + +if (now - last_pause_ns >SLICE_TIME ) { + last_pause_ns = now; +block_job_sleep_ns (&s->common,QEMU_CLOCK_REALTIME ,0 ); + } + +if (block_job_is_cancelled (&s->common)) { + goto immediate_exit; + } + ret =bdrv_is_allocated_above (bs, base, sector_num, next - sector_num, &n);@@ -490,7 +502,6 @@ static void coroutine_fn mirror_run(void *opaque) }bdrv_dirty_iter_init (s->dirty_bitmap, &s->hbi); - last_pause_ns =qemu_clock_get_ns (QEMU_CLOCK_REALTIME );for (;;) {uint64_t delay_ns =0 ;int64_t cnt;Signature · 1 line
2.4.0
Thanks, applied to my block tree:
https://github.com/codyprime/qemu-kvm-jtc/commits/block
Jeff