[PATCH 02/17] block, bfq: try preemption if bfqq has higher weight and the same priority class

From: Kemeng Shi
Date: Sat Feb 18 2023 - 21:41:42 EST


We will compare priority class and weight of current bfqq with
in_service_queue to check if bfqq could preempt in_service_queue.
Currently we will try to preempt in_service_queue if bfqq has higher
weight than in_service_queue even with lower priority class. Actually,
we will only serve bfqq with higher priority class (see
bfq_lookup_next_entity), so bfqq with higher weight and lower priority
class will not be a candidate to preempt in_service_queue.
Compare weight of bfqqs with the same priority in
bfq_bfqq_higher_class_or_weight to make preemption check more reasonable.

Signed-off-by: Kemeng Shi <shikemeng@xxxxxxxxxxxxxxx>
---
block/bfq-iosched.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index 3f5c740664ce..4868538c9745 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -1768,6 +1768,10 @@ static bool bfq_bfqq_higher_class_or_weight(struct bfq_queue *bfqq,
if (bfqq->ioprio_class < in_serv_bfqq->ioprio_class)
return true;

+ /* only try weight comparison with same priority class */
+ if (bfqq->ioprio_class != in_serv_bfqq->ioprio_class)
+ return false;
+
if (in_serv_bfqq->entity.parent == bfqq->entity.parent) {
bfqq_weight = bfqq->entity.weight;
in_serv_weight = in_serv_bfqq->entity.weight;
--
2.30.0