From 191d6634e8a692bef15143715c88920987ecaa89 Mon Sep 17 00:00:00 2001 From: Shin'ichiro Kawasaki Date: Thu, 20 Oct 2022 15:38:51 +0900 Subject: [PATCH] verify: fix bytes_done accounting of experimental verify The commit 55312f9f5572 ("Add ->bytes_done[] to struct thread_data") moved bytes_done[] on stack to struct thread_data. However, this unified two bytes_done[] in do_io() and do_verify() stacks into single td->bytes_done[]. This caused wrong condition check in do_verify() in experimental verify path since td->bytes_done[] holds values for do_io() not for do_verify(). This caused unexpected loop break in do_verify() and verify read skip when experimental_verify=1 option is specified. To fix this, add bytes_verified to struct thread_data for do_verify() in same manner as bytes_done[] for do_io(). Introduce a helper function io_u_update_bytes_done() to factor out same code for bytes_done[] and bytes_verified[]. Fixes: 55312f9f5572 ("Add ->bytes_done[] to struct thread_data") Signed-off-by: Shin'ichiro Kawasaki Signed-off-by: Vincent Fu --- backend.c | 2 +- fio.h | 1 + io_u.c | 23 +++++++++++++++++------ libfio.c | 1 + rate-submit.c | 2 ++ 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/backend.c b/backend.c index d8f4f2a5..15c6e0b3 100644 --- a/backend.c +++ b/backend.c @@ -682,7 +682,7 @@ static void do_verify(struct thread_data *td, uint64_t verify_bytes) break; } } else { - if (ddir_rw_sum(td->bytes_done) + td->o.rw_min_bs > verify_bytes) + if (td->bytes_verified + td->o.rw_min_bs > verify_bytes) break; while ((io_u = get_io_u(td)) != NULL) { diff --git a/fio.h b/fio.h index de7eca79..0592a4c3 100644 --- a/fio.h +++ b/fio.h @@ -370,6 +370,7 @@ struct thread_data { uint64_t zone_bytes; struct fio_sem *sem; uint64_t bytes_done[DDIR_RWDIR_CNT]; + uint64_t bytes_verified; uint64_t *thinktime_blocks_counter; struct timespec last_thinktime; diff --git a/io_u.c b/io_u.c index 91f1a358..8035f4b7 100644 --- a/io_u.c +++ b/io_u.c @@ -2121,13 +2121,26 @@ static void ios_completed(struct thread_data *td, } } +static void io_u_update_bytes_done(struct thread_data *td, + struct io_completion_data *icd) +{ + int ddir; + + if (td->runstate == TD_VERIFYING) { + td->bytes_verified += icd->bytes_done[DDIR_READ]; + return; + } + + for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) + td->bytes_done[ddir] += icd->bytes_done[ddir]; +} + /* * Complete a single io_u for the sync engines. */ int io_u_sync_complete(struct thread_data *td, struct io_u *io_u) { struct io_completion_data icd; - int ddir; init_icd(td, &icd, 1); io_completed(td, &io_u, &icd); @@ -2140,8 +2153,7 @@ int io_u_sync_complete(struct thread_data *td, struct io_u *io_u) return -1; } - for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) - td->bytes_done[ddir] += icd.bytes_done[ddir]; + io_u_update_bytes_done(td, &icd); return 0; } @@ -2153,7 +2165,7 @@ int io_u_queued_complete(struct thread_data *td, int min_evts) { struct io_completion_data icd; struct timespec *tvp = NULL; - int ret, ddir; + int ret; struct timespec ts = { .tv_sec = 0, .tv_nsec = 0, }; dprint(FD_IO, "io_u_queued_complete: min=%d\n", min_evts); @@ -2179,8 +2191,7 @@ int io_u_queued_complete(struct thread_data *td, int min_evts) return -1; } - for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) - td->bytes_done[ddir] += icd.bytes_done[ddir]; + io_u_update_bytes_done(td, &icd); return ret; } diff --git a/libfio.c b/libfio.c index 1a891776..ac521974 100644 --- a/libfio.c +++ b/libfio.c @@ -94,6 +94,7 @@ static void reset_io_counters(struct thread_data *td, int all) td->rate_next_io_time[ddir] = 0; td->last_usec[ddir] = 0; } + td->bytes_verified = 0; } td->zone_bytes = 0; diff --git a/rate-submit.c b/rate-submit.c index 268356d1..2fe768c0 100644 --- a/rate-submit.c +++ b/rate-submit.c @@ -263,6 +263,8 @@ static void sum_ddir(struct thread_data *dst, struct thread_data *src, sum_val(&dst->this_io_blocks[ddir], &src->this_io_blocks[ddir]); sum_val(&dst->this_io_bytes[ddir], &src->this_io_bytes[ddir]); sum_val(&dst->bytes_done[ddir], &src->bytes_done[ddir]); + if (ddir == DDIR_READ) + sum_val(&dst->bytes_verified, &src->bytes_verified); pthread_double_unlock(&dst->io_wq.stat_lock, &src->io_wq.stat_lock); } -- 2.25.1