Skip to contentSkip to conversation

block, bfq: improve arithmetic division in bfq_delta()

PATCH Applied Wen Yang 2 participants 2 messages Jan 20, 2020 – Jan 22, 2020

Subsystems (2)
lore
Share & tools
lore

Wen Yang

author
#0 lore raw

PATCH 1/1 block, bfq: improve arithmetic division in bfq_delta()

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.

---
 block/bfq-wf2q.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
block/bfq-wf2q.c +1 -4
index 05f0bf4a1144..ffe9ce9faa89 100644
@@ -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);
 }
 
 /**
Signature · 1 line
2.23.0
Applied
#1 lore raw
Quoted 3 lines · Wen Yang

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.

Applied, thanks.

Signature · 1 line
Jens Axboe