Skip to content

Commit b4ab5c2

Browse files
YuKuai-huaweikawasaki
authored andcommitted
blk-ioc: add a new helper ioc_lookup_icq_rcu()
ioc_lookup_icq() is used by bfq to lookup bfqq from IO path, the helper have to be protected by queue_lock, which is too heavy. Hence add a new helper that is lookless, this is safe because both request_queue and ioc can be pinged by IO that is still issuing. Signed-off-by: Yu Kuai <[email protected]>
1 parent bb733b3 commit b4ab5c2

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

block/blk-ioc.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,40 @@ struct io_cq *ioc_lookup_icq(struct request_queue *q)
343343
}
344344
EXPORT_SYMBOL(ioc_lookup_icq);
345345

346+
/**
347+
* ioc_lookup_icq_rcu - lookup io_cq from ioc in io path
348+
* @q: the associated request_queue
349+
*
350+
* Look up io_cq associated with @ioc - @q pair from @ioc. Must be called from
351+
* io issue path, either return NULL if current issue io to @q for the first
352+
* time, or return a valid icq.
353+
*/
354+
struct io_cq *ioc_lookup_icq_rcu(struct request_queue *q)
355+
{
356+
struct io_context *ioc = current->io_context;
357+
struct io_cq *icq;
358+
359+
WARN_ON_ONCE(percpu_ref_is_zero(&q->q_usage_counter));
360+
361+
if (!ioc)
362+
return NULL;
363+
364+
icq = rcu_dereference(ioc->icq_hint);
365+
if (icq && icq->q == q)
366+
return icq;
367+
368+
icq = radix_tree_lookup(&ioc->icq_tree, q->id);
369+
if (!icq)
370+
return NULL;
371+
372+
if (WARN_ON_ONCE(icq->q != q))
373+
return NULL;
374+
375+
rcu_assign_pointer(ioc->icq_hint, icq);
376+
return icq;
377+
}
378+
EXPORT_SYMBOL(ioc_lookup_icq_rcu);
379+
346380
/**
347381
* ioc_create_icq - create and link io_cq
348382
* @q: request_queue of interest

block/blk.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ static inline void req_set_nomerge(struct request_queue *q, struct request *req)
461461
*/
462462
struct io_cq *ioc_find_get_icq(struct request_queue *q);
463463
struct io_cq *ioc_lookup_icq(struct request_queue *q);
464+
struct io_cq *ioc_lookup_icq_rcu(struct request_queue *q);
464465
#ifdef CONFIG_BLK_ICQ
465466
void ioc_clear_queue(struct request_queue *q);
466467
#else

0 commit comments

Comments
 (0)