summaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2020-09-12 01:40:49 +0300
committerJens Axboe <axboe@kernel.dk>2020-09-12 01:41:47 +0300
commit769b628de0b9a7ab0b81e6eecca5ee7bf66e978d (patch)
tree39ebaa9dc4a2a062fe38ea3aebfdce8d1c642cc9 /block
parent0806e60f31ec10822cd230d12603169d1bb7840e (diff)
downloadlinux-769b628de0b9a7ab0b81e6eecca5ee7bf66e978d.tar.xz
blk-iocost: fix divide-by-zero in transfer_surpluses()
Conceptually, root_iocg->hweight_donating must be less than WEIGHT_ONE but all hweight calculations round up and thus it may end up >= WEIGHT_ONE triggering divide-by-zero and other issues. Bound the value to avoid surprises. Fixes: e08d02aa5fc9 ("blk-iocost: implement Andy's method for donation weight updates") Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block')
-rw-r--r--block/blk-iocost.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/block/blk-iocost.c b/block/blk-iocost.c
index fc897bb142bc..6e29b4dcf356 100644
--- a/block/blk-iocost.c
+++ b/block/blk-iocost.c
@@ -1881,15 +1881,21 @@ static void transfer_surpluses(struct list_head *surpluses, struct ioc_now *now)
/*
* Calculate the global donation rate (gamma) - the rate to adjust
- * non-donating budgets by. No need to use 64bit multiplication here as
- * the first operand is guaranteed to be smaller than WEIGHT_ONE
- * (1<<16).
+ * non-donating budgets by.
+ *
+ * No need to use 64bit multiplication here as the first operand is
+ * guaranteed to be smaller than WEIGHT_ONE (1<<16).
+ *
+ * We know that there are beneficiary nodes and the sum of the donating
+ * hweights can't be whole; however, due to the round-ups during hweight
+ * calculations, root_iocg->hweight_donating might still end up equal to
+ * or greater than whole. Limit the range when calculating the divider.
*
* gamma = (1 - t_r') / (1 - t_r)
*/
gamma = DIV_ROUND_UP(
(WEIGHT_ONE - root_iocg->hweight_after_donation) * WEIGHT_ONE,
- WEIGHT_ONE - root_iocg->hweight_donating);
+ WEIGHT_ONE - min_t(u32, root_iocg->hweight_donating, WEIGHT_ONE - 1));
/*
* Calculate adjusted hwi, child_adjusted_sum and inuse for the inner