* [PATCH v2 1/3] iolog: refactor read_iolog()
2026-12-02 2:13 [PATCH v2 0/3] Cleanup and fix iolog replay Damien Le Moal
@ 2026-12-02 2:13 ` Damien Le Moal
2026-12-02 2:13 ` [PATCH v2 2/3] iolog: avoid potential overflows in iolog_items_to_fetch() Damien Le Moal
2026-12-02 2:13 ` [PATCH v2 3/3] iolog: fix iolog_items_to_fetch() Damien Le Moal
2 siblings, 0 replies; 4+ messages in thread
From: Damien Le Moal @ 2026-12-02 2:13 UTC (permalink / raw)
To: fio, Vincent Fu, Jens Axboe
In read_iolog(), use a switch-case for handling an iolog item rw type.
This is cleaner and more efficient than a series of if-else-if.
No functional change.
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
---
iolog.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/iolog.c b/iolog.c
index 41a3102c6c5c..54fb8283b766 100644
--- a/iolog.c
+++ b/iolog.c
@@ -582,30 +582,38 @@ static bool read_iolog(struct thread_data *td)
continue;
}
- if (rw == DDIR_READ)
+ switch (rw) {
+ case DDIR_READ:
reads++;
- else if (rw == DDIR_WRITE) {
+ break;
+ case DDIR_WRITE:
/*
* Don't add a write for ro mode
*/
if (read_only)
continue;
writes++;
- } else if (rw == DDIR_TRIM) {
+ break;
+ case DDIR_TRIM:
/*
* Don't add a trim for ro mode
*/
if (read_only)
continue;
trims++;
- } else if (rw == DDIR_WAIT) {
+ break;
+ case DDIR_WAIT:
if (td->o.no_stall)
continue;
waits++;
- } else if (rw == DDIR_INVAL) {
- } else if (ddir_sync(rw)) {
- syncs++;
- } else {
+ break;
+ case DDIR_INVAL:
+ break;
+ default:
+ if (ddir_sync(rw)) {
+ syncs++;
+ break;
+ }
log_err("bad ddir: %d\n", rw);
continue;
}
--
2.56.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v2 2/3] iolog: avoid potential overflows in iolog_items_to_fetch()
2026-12-02 2:13 [PATCH v2 0/3] Cleanup and fix iolog replay Damien Le Moal
2026-12-02 2:13 ` [PATCH v2 1/3] iolog: refactor read_iolog() Damien Le Moal
@ 2026-12-02 2:13 ` Damien Le Moal
2026-12-02 2:13 ` [PATCH v2 3/3] iolog: fix iolog_items_to_fetch() Damien Le Moal
2 siblings, 0 replies; 4+ messages in thread
From: Damien Le Moal @ 2026-12-02 2:13 UTC (permalink / raw)
To: fio, Vincent Fu, Jens Axboe
A thread data io_log_highmark and io_log_current are both unsigned int.
In iolog_items_to_fetch(), multiplying their difference by 1000000000
can thus potentially result in an int overflow. Avoid this using the
local signed 64-bits variable items_consumed for the difference of
io_log_highmark and io_log_current and multiply this by 1000000000LL.
The variable for_1s is also renamed items_rate and while at it, the
function code style is fixed too (extra blank line and missing curly
brackets).
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
---
iolog.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/iolog.c b/iolog.c
index 54fb8283b766..288df27f7760 100644
--- a/iolog.c
+++ b/iolog.c
@@ -422,22 +422,22 @@ int64_t iolog_items_to_fetch(struct thread_data *td)
{
struct timespec now;
uint64_t elapsed;
- uint64_t for_1s;
- int64_t items_to_fetch;
+ int64_t items_rate, items_to_fetch, items_consumed;
if (!td->io_log_highmark)
return 10;
-
fio_gettime(&now, NULL);
elapsed = ntime_since(&td->io_log_highmark_time, &now);
if (elapsed) {
- for_1s = (td->io_log_highmark - td->io_log_current) * 1000000000 / elapsed;
- items_to_fetch = for_1s - td->io_log_current;
+ items_consumed = td->io_log_highmark - td->io_log_current;
+ items_rate = items_consumed * 1000000000LL / elapsed;
+ items_to_fetch = items_rate - td->io_log_current;
if (items_to_fetch < 0)
items_to_fetch = 0;
- } else
+ } else {
items_to_fetch = 0;
+ }
td->io_log_highmark = td->io_log_current + items_to_fetch;
td->io_log_checkmark = (td->io_log_highmark + 1) / 2;
--
2.56.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v2 3/3] iolog: fix iolog_items_to_fetch()
2026-12-02 2:13 [PATCH v2 0/3] Cleanup and fix iolog replay Damien Le Moal
2026-12-02 2:13 ` [PATCH v2 1/3] iolog: refactor read_iolog() Damien Le Moal
2026-12-02 2:13 ` [PATCH v2 2/3] iolog: avoid potential overflows in iolog_items_to_fetch() Damien Le Moal
@ 2026-12-02 2:13 ` Damien Le Moal
2 siblings, 0 replies; 4+ messages in thread
From: Damien Le Moal @ 2026-12-02 2:13 UTC (permalink / raw)
To: fio, Vincent Fu, Jens Axboe
When replaying an iolog with read_iolog_chunked=true, if the iolog
describes a workload hat has very low IOPS intervals (IOPS < 1),
iolog_items_to_fetch() may return 0 due to the rate calculation it does
based on the last time the iolog file was read (td->io_log_highmark_time).
This causes read_iolog() to do nothing and the job to end, even if the
iolog file is not yet fully replayed.
Avoid this by returning the default 10 items (now defined as
IOLOG_DEFAULT_ITEMS_TO_FETCH) when the calculation leads to a value that
is 0 or less. When the iolog file is fully replayed, read_iolog() will
still do nothing and the job ends normally after replaying the entire
iolog file.
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
---
iolog.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/iolog.c b/iolog.c
index 288df27f7760..8026d5e87296 100644
--- a/iolog.c
+++ b/iolog.c
@@ -418,6 +418,8 @@ void write_iolog_close(struct thread_data *td)
td->iolog_buf = NULL;
}
+#define IOLOG_DEFAULT_ITEMS_TO_FETCH 10
+
int64_t iolog_items_to_fetch(struct thread_data *td)
{
struct timespec now;
@@ -425,7 +427,7 @@ int64_t iolog_items_to_fetch(struct thread_data *td)
int64_t items_rate, items_to_fetch, items_consumed;
if (!td->io_log_highmark)
- return 10;
+ return IOLOG_DEFAULT_ITEMS_TO_FETCH;
fio_gettime(&now, NULL);
elapsed = ntime_since(&td->io_log_highmark_time, &now);
@@ -433,8 +435,8 @@ int64_t iolog_items_to_fetch(struct thread_data *td)
items_consumed = td->io_log_highmark - td->io_log_current;
items_rate = items_consumed * 1000000000LL / elapsed;
items_to_fetch = items_rate - td->io_log_current;
- if (items_to_fetch < 0)
- items_to_fetch = 0;
+ if (items_to_fetch <= 0)
+ items_to_fetch = IOLOG_DEFAULT_ITEMS_TO_FETCH;
} else {
items_to_fetch = 0;
}
--
2.56.1
^ permalink raw reply related [flat|nested] 4+ messages in thread