block, bfq: improve arithmetic division in bfq_delta()
authorWen Yang <wenyang@linux.alibaba.com>
Mon, 20 Jan 2020 10:04:43 +0000 (18:04 +0800)
committerJens Axboe <axboe@kernel.dk>
Wed, 22 Jan 2020 17:34:11 +0000 (10:34 -0700)
do_div() does a 64-by-32 division. Use div64_ul() instead of it
if the divisor is unsigned long, to avoid truncation to 32-bit.
And as a nice side effect also cleans up the function a bit.

Signed-off-by: Wen Yang <wenyang@linux.alibaba.com>
Cc: Paolo Valente <paolo.valente@linaro.org>
Cc: Jens Axboe <axboe@fb.com>
Cc: linux-block@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/bfq-wf2q.c

index 05f0bf4..ffe9ce9 100644 (file)
@@ -277,10 +277,7 @@ struct bfq_queue *bfq_entity_to_bfqq(struct bfq_entity *entity)
  */
 static u64 bfq_delta(unsigned long service, unsigned long weight)
 {
-       u64 d = (u64)service << WFQ_SERVICE_SHIFT;
-
-       do_div(d, weight);
-       return d;
+       return div64_ul((u64)service << WFQ_SERVICE_SHIFT, weight);
 }
 
 /**