[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241122072609.29429-1-daikunhai@didiglobal.com>
Date: Fri, 22 Nov 2024 15:26:09 +0800
From: Kunhai Dai <daikunhai@...iglobal.com>
To: <tj@...nel.org>, <josef@...icpanda.com>, <axboe@...nel.dk>
CC: <cgroups@...r.kernel.org>, <linux-block@...r.kernel.org>,
<linux-kernel@...r.kernel.org>, Kunhai Dai <daikunhai@...iglobal.com>
Subject: [PATCH] block: iocost: ensure hweight_inuse is at least 1
The hweight_inuse calculation in transfer_surpluses() could potentially
result in a value of 0, which would lead to division by zero errors in
subsequent calculations that use this value as a divisor.
Signed-off-by: Kunhai Dai <daikunhai@...iglobal.com>
---
block/blk-iocost.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/block/blk-iocost.c b/block/blk-iocost.c
index 384aa15e8260..65cdb55d30cc 100644
--- a/block/blk-iocost.c
+++ b/block/blk-iocost.c
@@ -1999,9 +1999,10 @@ static void transfer_surpluses(struct list_head *surpluses, struct ioc_now *now)
parent = iocg->ancestors[iocg->level - 1];
/* b' = gamma * b_f + b_t' */
- iocg->hweight_inuse = DIV64_U64_ROUND_UP(
- (u64)gamma * (iocg->hweight_active - iocg->hweight_donating),
- WEIGHT_ONE) + iocg->hweight_after_donation;
+ iocg->hweight_inuse = max_t(u64, 1,
+ DIV64_U64_ROUND_UP(
+ (u64)gamma * (iocg->hweight_active - iocg->hweight_donating),
+ WEIGHT_ONE) + iocg->hweight_after_donation);
/* w' = s' * b' / b'_p */
inuse = DIV64_U64_ROUND_UP(
--
2.27.0
Powered by blists - more mailing lists