mirror: fix request throttling in drive-mirror
PATCH 1/1 mirror: fix request throttling in drive-mirror
There are 2 deficiencies here:
- mirror_iteration could start several requests inside. Thus we could simply have more in_flight requests than MAX_IN_FLIGHT.
- keeping this in mind throttling in mirror_run which is checking s->in_flight == MAX_IN_FLIGHT is wrong.
The patch adds the check and throttling into mirror_iteration and fixes the check in mirror_run() to be sure.
--- block/mirror.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
block/mirror.c +6 -1
@@ -399,6 +399,11 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s) } } +while (s->in_flight >=MAX_IN_FLIGHT ) { +trace_mirror_yield_in_flight (s, sector_num, s->in_flight); +mirror_wait_for_io (s); + } +mirror_clip_sectors (s, sector_num, &io_sectors);switch (mirror_method) {case MIRROR_METHOD_COPY :
@@ -634,7 +639,7 @@ static void coroutine_fn mirror_run(void *opaque)*/ if (qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) - last_pause_ns <SLICE_TIME && s->common.iostatus ==BLOCK_DEVICE_IO_STATUS_OK ) { -if (s->in_flight ==MAX_IN_FLIGHT || s->buf_free_count ==0 || +if (s->in_flight >=MAX_IN_FLIGHT || s->buf_free_count ==0 || (cnt ==0 && s->in_flight >0 )) {trace_mirror_yield (s, s->in_flight, s->buf_free_count, cnt);mirror_wait_for_io (s);
Signature · 1 line
2.1.4
Quoted 34 lines · Denis V. Lunev
There are 2 deficiencies here:
-mirror_iterationcould start several requests inside. Thus we could simply have morein_flightrequests thanMAX_IN_FLIGHT.
- keeping this in mind throttling inmirror_runwhich is checkings->in_flight==MAX_IN_FLIGHTis wrong.The patch adds the check and throttling into
mirror_iterationand fixes the check inmirror_run()to be sure.Signed-off-by Denis V. Lunev <[email protected]>CC Jeff Cody <[email protected]>CC Kevin Wolf <[email protected]>CC Max Reitz <[email protected]>--- block/mirror.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)block/mirror.c +5
-0@@ -399,6 +399,11 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s) } } +while (s->in_flight >=MAX_IN_FLIGHT ) { +trace_mirror_yield_in_flight (s, sector_num, s->in_flight); +mirror_wait_for_io (s); + } +mirror_clip_sectors (s, sector_num, &io_sectors);switch (mirror_method) {case MIRROR_METHOD_COPY :
block/mirror.c static void coroutine_fn mirror_run(void *opaque) · line 645
Quoted 8 lines
block/mirror.c +1
-1@@ -634,7 +639,7 @@ static void coroutine_fn mirror_run(void *opaque)*/ if (qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) - last_pause_ns <SLICE_TIME && s->common.iostatus ==BLOCK_DEVICE_IO_STATUS_OK ) { -if (s->in_flight ==MAX_IN_FLIGHT || s->buf_free_count ==0 || +if (s->in_flight >=MAX_IN_FLIGHT || s->buf_free_count ==0 || (cnt ==0 && s->in_flight >0 )) {trace_mirror_yield (s, s->in_flight, s->buf_free_count, cnt);mirror_wait_for_io (s);
ping
Quoted 35 lines · Denis V. Lunev
There are 2 deficiencies here:
-mirror_iterationcould start several requests inside. Thus we could simply have morein_flightrequests thanMAX_IN_FLIGHT.
- keeping this in mind throttling inmirror_runwhich is checkings->in_flight==MAX_IN_FLIGHTis wrong.The patch adds the check and throttling into
mirror_iterationand fixes the check inmirror_run()to be sure.Signed-off-by Denis V. Lunev <[email protected]>CC Jeff Cody <[email protected]>CC Kevin Wolf <[email protected]>CC Max Reitz <[email protected]>--- block/mirror.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)block/mirror.c +5
-0@@ -399,6 +399,11 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s) } } +while (s->in_flight >=MAX_IN_FLIGHT ) { +trace_mirror_yield_in_flight (s, sector_num, s->in_flight); +mirror_wait_for_io (s); + } +mirror_clip_sectors (s, sector_num, &io_sectors);switch (mirror_method) {case MIRROR_METHOD_COPY :
block/mirror.c static void coroutine_fn mirror_run(void *opaque) · line 645
Quoted 8 lines
block/mirror.c +1
-1@@ -634,7 +639,7 @@ static void coroutine_fn mirror_run(void *opaque)*/ if (qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) - last_pause_ns <SLICE_TIME && s->common.iostatus ==BLOCK_DEVICE_IO_STATUS_OK ) { -if (s->in_flight ==MAX_IN_FLIGHT || s->buf_free_count ==0 || +if (s->in_flight >=MAX_IN_FLIGHT || s->buf_free_count ==0 || (cnt ==0 && s->in_flight >0 )) {trace_mirror_yield (s, s->in_flight, s->buf_free_count, cnt);mirror_wait_for_io (s);
Using >= seems fine to me, but with the first hunk applied I can't imagine how s->in_flight should grow beyond MAX_IN_FLIGHT. Don't get me wrong, I myself like to use >= even where the > case should never happen, I'm just wondering if I'm missing something here.
Quoted 49 lines · Max Reitz
Quoted 35 lines · Denis V. Lunev
There are 2 deficiencies here:
-mirror_iterationcould start several requests inside. Thus we could simply have morein_flightrequests thanMAX_IN_FLIGHT.
- keeping this in mind throttling inmirror_runwhich is checkings->in_flight==MAX_IN_FLIGHTis wrong.The patch adds the check and throttling into
mirror_iterationand fixes the check inmirror_run()to be sure.Signed-off-by Denis V. Lunev <[email protected]>CC Jeff Cody <[email protected]>CC Kevin Wolf <[email protected]>CC Max Reitz <[email protected]>--- block/mirror.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)block/mirror.c +5
-0@@ -399,6 +399,11 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s) } } +while (s->in_flight >=MAX_IN_FLIGHT ) { +trace_mirror_yield_in_flight (s, sector_num, s->in_flight); +mirror_wait_for_io (s); + } +mirror_clip_sectors (s, sector_num, &io_sectors);switch (mirror_method) {case MIRROR_METHOD_COPY :block/mirror.c static void coroutine_fn mirror_run(void *opaque) · line 645
Quoted 8 lines
block/mirror.c +1
-1@@ -634,7 +639,7 @@ static void coroutine_fn mirror_run(void *opaque)*/ if (qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) - last_pause_ns <SLICE_TIME && s->common.iostatus ==BLOCK_DEVICE_IO_STATUS_OK ) { -if (s->in_flight ==MAX_IN_FLIGHT || s->buf_free_count ==0 || +if (s->in_flight >=MAX_IN_FLIGHT || s->buf_free_count ==0 || (cnt ==0 && s->in_flight >0 )) {trace_mirror_yield (s, s->in_flight, s->buf_free_count, cnt);mirror_wait_for_io (s);Using >= seems fine to me, but with the first hunk applied I can't imagine how
s->in_flightshould grow beyondMAX_IN_FLIGHT. Don't get me wrong, I myself like to use >= even where the > case should never happen, I'm just wondering if I'm missing something here.
Quoted 2 lines
Reviewed-by Max Reitz <[email protected]>
I think that this should not happen anymore,
but I'd like to stay on the safe side.
Den
Quoted 45 lines · Denis V. Lunev
There are 2 deficiencies here:
-mirror_iterationcould start several requests inside. Thus we could simply have morein_flightrequests thanMAX_IN_FLIGHT.
- keeping this in mind throttling inmirror_runwhich is checkings->in_flight==MAX_IN_FLIGHTis wrong.The patch adds the check and throttling into
mirror_iterationand fixes the check inmirror_run()to be sure.Signed-off-by Denis V. Lunev <[email protected]>CC Jeff Cody <[email protected]>CC Kevin Wolf <[email protected]>CC Max Reitz <[email protected]>--- block/mirror.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)block/mirror.c +6
-1@@ -399,6 +399,11 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s) } } +while (s->in_flight >=MAX_IN_FLIGHT ) { +trace_mirror_yield_in_flight (s, sector_num, s->in_flight); +mirror_wait_for_io (s); + } +mirror_clip_sectors (s, sector_num, &io_sectors);switch (mirror_method) {case MIRROR_METHOD_COPY :@@ -634,7 +639,7 @@ static void coroutine_fn mirror_run(void *opaque)*/ if (qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) - last_pause_ns <SLICE_TIME && s->common.iostatus ==BLOCK_DEVICE_IO_STATUS_OK ) { -if (s->in_flight ==MAX_IN_FLIGHT || s->buf_free_count ==0 || +if (s->in_flight >=MAX_IN_FLIGHT || s->buf_free_count ==0 || (cnt ==0 && s->in_flight >0 )) {trace_mirror_yield (s, s->in_flight, s->buf_free_count, cnt);mirror_wait_for_io (s);Signature · 1 line
2.1.4
Jeff Cody
AppliedQuoted 45 lines · Denis V. Lunev
There are 2 deficiencies here:
-mirror_iterationcould start several requests inside. Thus we could simply have morein_flightrequests thanMAX_IN_FLIGHT.
- keeping this in mind throttling inmirror_runwhich is checkings->in_flight==MAX_IN_FLIGHTis wrong.The patch adds the check and throttling into
mirror_iterationand fixes the check inmirror_run()to be sure.Signed-off-by Denis V. Lunev <[email protected]>CC Jeff Cody <[email protected]>CC Kevin Wolf <[email protected]>CC Max Reitz <[email protected]>--- block/mirror.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)block/mirror.c +6
-1@@ -399,6 +399,11 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s) } } +while (s->in_flight >=MAX_IN_FLIGHT ) { +trace_mirror_yield_in_flight (s, sector_num, s->in_flight); +mirror_wait_for_io (s); + } +mirror_clip_sectors (s, sector_num, &io_sectors);switch (mirror_method) {case MIRROR_METHOD_COPY :@@ -634,7 +639,7 @@ static void coroutine_fn mirror_run(void *opaque)*/ if (qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) - last_pause_ns <SLICE_TIME && s->common.iostatus ==BLOCK_DEVICE_IO_STATUS_OK ) { -if (s->in_flight ==MAX_IN_FLIGHT || s->buf_free_count ==0 || +if (s->in_flight >=MAX_IN_FLIGHT || s->buf_free_count ==0 || (cnt ==0 && s->in_flight >0 )) {trace_mirror_yield (s, s->in_flight, s->buf_free_count, cnt);mirror_wait_for_io (s);Signature · 1 line
2.1.4
Thanks,
Applied to my block branch:
git://github.com/codyprime/qemu-kvm-jtc.git block
-Jeff