[PATCH 2/3] block, bfq: convert to use ioc_lookup_icq_rcu()

From: Yu Kuai
Date: Fri Jul 25 2025 - 03:13:25 EST


From: Yu Kuai <yukuai3@xxxxxxxxxx>

ioc_lookup_icq() are all called from IO issue path with queue_lock held,
convert to use ioc_lookup_icq_rcu() to get rid of the disk level spin
lock.

Signed-off-by: Yu Kuai <yukuai3@xxxxxxxxxx>
---
block/bfq-iosched.c | 23 ++++++-----------------
1 file changed, 6 insertions(+), 17 deletions(-)

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index 0cb1e9873aab..b3b9dbbc16d2 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -454,17 +454,13 @@ static struct bfq_io_cq *icq_to_bic(struct io_cq *icq)
*/
static struct bfq_io_cq *bfq_bic_lookup(struct request_queue *q)
{
- struct bfq_io_cq *icq;
- unsigned long flags;
-
- if (!current->io_context)
- return NULL;
+ struct io_cq *icq;

- spin_lock_irqsave(&q->queue_lock, flags);
- icq = icq_to_bic(ioc_lookup_icq(q));
- spin_unlock_irqrestore(&q->queue_lock, flags);
+ rcu_read_lock();
+ icq = ioc_lookup_icq_rcu(q);
+ rcu_read_unlock();

- return icq;
+ return icq_to_bic(icq);
}

/*
@@ -2457,15 +2453,8 @@ static bool bfq_bio_merge(struct request_queue *q, struct bio *bio,
unsigned int nr_segs)
{
struct bfq_data *bfqd = q->elevator->elevator_data;
- struct request *free = NULL;
- /*
- * bfq_bic_lookup grabs the queue_lock: invoke it now and
- * store its return value for later use, to avoid nesting
- * queue_lock inside the bfqd->lock. We assume that the bic
- * returned by bfq_bic_lookup does not go away before
- * bfqd->lock is taken.
- */
struct bfq_io_cq *bic = bfq_bic_lookup(q);
+ struct request *free = NULL;
bool ret;

spin_lock_irq(&bfqd->lock);
--
2.39.2