Skip to contentSkip to conversation

btrfs-progs: scrub: improve Rate reporting for sub-second durations

PATCH In review David Disseldorp 3 participants 4 messages Dec 7, 2023 – Dec 8, 2023 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs-progs: scrub: improve Rate reporting for sub-second durations

Scrubs which complete in under one second may carry a duration rounded down to zero. This subsequently results in a bytes_per_sec value of zero, which corresponds to the Rate metric output, causing intermittent tests/btrfs/282 failures.

This change ensures that Rate reflects any sub-second bytes processed. Time left and ETA metrics are also affected by this change, in that they increase to account for (sub-second) bytes_per_sec.

---
 cmds/scrub.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
cmds/scrub.c +8 -1
index 4a741355..72ea3b67 100644
@@ -152,7 +152,14 @@ static void print_scrub_summary(struct btrfs_scrub_progress *p, struct scrub_sta
 	time_t sec_eta;
 
 	bytes_scrubbed = p->data_bytes_scrubbed + p->tree_bytes_scrubbed;
-	if (s->duration > 0)
+	/*
+	 * If duration is zero seconds (rounded down), then the Rate metric
+	 * should still reflect the amount of bytes that have been processed
+	 * in under a second.
+	 */
+	if (s->duration == 0)
+		bytes_per_sec = bytes_scrubbed;
+	else
 		bytes_per_sec = bytes_scrubbed / s->duration;
 	if (bytes_per_sec > 0)
 		sec_left = (bytes_total - bytes_scrubbed) / bytes_per_sec;
Signature · 1 line
2.35.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · David Disseldorp

Scrubs which complete in under one second may carry a duration rounded down to zero. This subsequently results in a bytes_per_sec value of zero, which corresponds to the Rate metric output, causing intermittent tests/btrfs/282 failures.

This change ensures that Rate reflects any sub-second bytes processed. Time left and ETA metrics are also affected by this change, in that they increase to account for (sub-second) bytes_per_sec.

Looks good to me.

In the future we should also increase the resolution to proper time stamp level.

Thanks,
Qu

Quoted 24 lines
---
  cmds/scrub.c | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)
cmds/scrub.c +8 -1
index 4a741355..72ea3b67 100644
@@ -152,7 +152,14 @@ static void print_scrub_summary(struct btrfs_scrub_progress *p, struct scrub_sta
  	time_t sec_eta;
 
  	bytes_scrubbed = p->data_bytes_scrubbed + p->tree_bytes_scrubbed;
-	if (s->duration > 0)
+	/*
+	 * If duration is zero seconds (rounded down), then the Rate metric
+	 * should still reflect the amount of bytes that have been processed
+	 * in under a second.
+	 */
+	if (s->duration == 0)
+		bytes_per_sec = bytes_scrubbed;
+	else
  		bytes_per_sec = bytes_scrubbed / s->duration;
  	if (bytes_per_sec > 0)
  		sec_left = (bytes_total - bytes_scrubbed) / bytes_per_sec;
#2 lore raw
Quoted 12 lines · Qu Wenruo
Quoted 9 lines · David Disseldorp

Scrubs which complete in under one second may carry a duration rounded down to zero. This subsequently results in a bytes_per_sec value of zero, which corresponds to the Rate metric output, causing intermittent tests/btrfs/282 failures.

This change ensures that Rate reflects any sub-second bytes processed. Time left and ETA metrics are also affected by this change, in that they increase to account for (sub-second) bytes_per_sec.

Quoted 6 lines
Quoted 1 line

Looks good to me.

In the future we should also increase the resolution to proper time stamp level.

It seems possible, we have some of the timestamps as time_te which is in seconds but the end time measured in scrub_one_dev() uses gettimeofday() so we would have the sub-second precision. However I'm not sure we need this, most scrubs run for a long time, I'd be fine with the simple fix like in this patch.

#3 lore raw
In reply to David Disseldorp
Quoted 10 lines · David Disseldorp

Scrubs which complete in under one second may carry a duration rounded down to zero. This subsequently results in a bytes_per_sec value of zero, which corresponds to the Rate metric output, causing intermittent tests/btrfs/282 failures.

This change ensures that Rate reflects any sub-second bytes processed. Time left and ETA metrics are also affected by this change, in that they increase to account for (sub-second) bytes_per_sec.

Added to devel, thanks.