public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block: throttle: don't add one extra jiffy mistakenly for bps limit
@ 2025-02-20 11:17 Ming Lei
  2025-02-20 13:38 ` Yu Kuai
  0 siblings, 1 reply; 9+ messages in thread
From: Ming Lei @ 2025-02-20 11:17 UTC (permalink / raw)
  To: Jens Axboe, linux-block; +Cc: Ming Lei, Tejun Heo, Yu Kuai

When the current bio needs to be throttled because of bps limit, the wait
time for the extra bytes may be less than 1 jiffy, tg_within_bps_limit()
adds one extra 1 jiffy.

However, when taking roundup time into account, the extra 1 jiffy
may become not necessary, then bps limit becomes not accurate. This way
causes blktests throtl/001 failure in case of CONFIG_HZ_100=y.

Fix it by not adding the 1 jiffy in case that the roundup time can
cover it.

Cc: Tejun Heo <tj@kernel.org>
Cc: Yu Kuai <yukuai3@huawei.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 block/blk-throttle.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index 8d149aff9fd0..8348972c517b 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -729,14 +729,14 @@ static unsigned long tg_within_bps_limit(struct throtl_grp *tg, struct bio *bio,
 	extra_bytes = tg->bytes_disp[rw] + bio_size - bytes_allowed;
 	jiffy_wait = div64_u64(extra_bytes * HZ, bps_limit);
 
-	if (!jiffy_wait)
-		jiffy_wait = 1;
-
 	/*
 	 * This wait time is without taking into consideration the rounding
 	 * up we did. Add that time also.
 	 */
 	jiffy_wait = jiffy_wait + (jiffy_elapsed_rnd - jiffy_elapsed);
+	if (!jiffy_wait)
+		jiffy_wait = 1;
+
 	return jiffy_wait;
 }
 
-- 
2.47.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-02-22  3:01 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-20 11:17 [PATCH] block: throttle: don't add one extra jiffy mistakenly for bps limit Ming Lei
2025-02-20 13:38 ` Yu Kuai
2025-02-21  2:55   ` Ming Lei
2025-02-21  3:16     ` Ming Lei
2025-02-21  3:39     ` Yu Kuai
2025-02-21  4:18       ` Ming Lei
2025-02-21  6:29         ` Yu Kuai
2025-02-21  8:59           ` Ming Lei
2025-02-22  3:01             ` Yu Kuai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox