linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] blk-throttle: Calculate allowed value only when the throttle is enabled
@ 2023-09-28  1:58 linan666
  2023-10-04 19:31 ` Tejun Heo
  2023-10-04 20:44 ` Khazhy Kumykov
  0 siblings, 2 replies; 16+ messages in thread
From: linan666 @ 2023-09-28  1:58 UTC (permalink / raw)
  To: tj, josef, axboe, yukuai3
  Cc: cgroups, linux-block, linux-kernel, linan122, yi.zhang, houtao1,
	yangerkun

From: Li Nan <linan122@huawei.com>

When the throttle of bps is not enabled, tg_bps_limit() returns U64_MAX,
which is be used in calculate_bytes_allowed(), and divide 0 error will
happen.

To fix it, only calculate allowed value when the throttle of bps/iops is
enabled and the value will be used.

Fixes: e8368b57c006 ("blk-throttle: use calculate_io/bytes_allowed() for throtl_trim_slice()")
Reported-by: Changhui Zhong <czhong@redhat.com>
Closes: https://lore.kernel.org/all/CAGVVp+Vt6idZtxfU9jF=VSbu145Wi-d-WnAZx_hEfOL8yLZgBA@mail.gmail.com
Signed-off-by: Li Nan <linan122@huawei.com>
---
 block/blk-throttle.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index 38a881cf97d0..3c9a74ab9f0e 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -730,8 +730,10 @@ static u64 calculate_bytes_allowed(u64 bps_limit, unsigned long jiffy_elapsed)
 static inline void throtl_trim_slice(struct throtl_grp *tg, bool rw)
 {
 	unsigned long time_elapsed;
-	long long bytes_trim;
-	int io_trim;
+	long long bytes_trim = 0;
+	int io_trim = 0;
+	u64 bps_limit;
+	u32 iops_limit;
 
 	BUG_ON(time_before(tg->slice_end[rw], tg->slice_start[rw]));
 
@@ -758,11 +760,14 @@ static inline void throtl_trim_slice(struct throtl_grp *tg, bool rw)
 	if (!time_elapsed)
 		return;
 
-	bytes_trim = calculate_bytes_allowed(tg_bps_limit(tg, rw),
-					     time_elapsed) +
-		     tg->carryover_bytes[rw];
-	io_trim = calculate_io_allowed(tg_iops_limit(tg, rw), time_elapsed) +
-		  tg->carryover_ios[rw];
+	bps_limit = tg_bps_limit(tg, rw);
+	iops_limit = tg_iops_limit(tg, rw);
+	if (tg->bytes_disp[rw] > 0 && bps_limit != U64_MAX)
+		bytes_trim = calculate_bytes_allowed(bps_limit,
+			     time_elapsed) + tg->carryover_bytes[rw];
+	if (tg->io_disp[rw] > 0 && iops_limit != UINT_MAX)
+		io_trim = calculate_io_allowed(iops_limit, time_elapsed) +
+			  tg->carryover_ios[rw];
 	if (bytes_trim <= 0 && io_trim <= 0)
 		return;
 
-- 
2.39.2


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

end of thread, other threads:[~2023-10-17  2:38 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-28  1:58 [PATCH] blk-throttle: Calculate allowed value only when the throttle is enabled linan666
2023-10-04 19:31 ` Tejun Heo
2023-10-04 20:30   ` Khazhy Kumykov
2023-10-04 20:44 ` Khazhy Kumykov
     [not found]   ` <4ace01e8-6815-29d0-70ce-4632818ca701@huaweicloud.com>
2023-10-05 16:24     ` Oleg Nesterov
2023-10-07  1:23       ` Yu Kuai
2023-10-07 15:16         ` Oleg Nesterov
2023-10-08  1:26           ` Yu Kuai
2023-10-08 11:36             ` Oleg Nesterov
2023-10-13 21:51               ` Khazhy Kumykov
2023-10-16  1:46                 ` Yu Kuai
2023-10-16 20:06                   ` Khazhy Kumykov
2023-10-16 21:48                     ` Khazhy Kumykov
2023-10-17  2:38                     ` Yu Kuai
2023-10-05 17:04     ` Oleg Nesterov
2023-10-05 17:15       ` Khazhy Kumykov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).