Skip to content

Commit 16469a8

Browse files
YuKuai-huaweikawasaki
authored andcommitted
blk-ioc: convert to use ioc_lookup_icq_rcu()
Now ioc_lookup_icq() is only called from bfq_prepare_request() from IO issue path, if it's the first time current issue IO to the disk, 'queue_lock' will be held to creat new icq, otherwise it's safe to use the new helper. Noted if multiple task share one ioc, and ioc_create_icq() raced, queue_lock is used to serialize them and only the first one can succeed inserting icq to ioc. Also remove ioc_lookup_icq() that is not used now. Signed-off-by: Yu Kuai <[email protected]>
1 parent 24595ca commit 16469a8

File tree

2 files changed

+4
-41
lines changed

2 files changed

+4
-41
lines changed

block/blk-ioc.c

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -307,42 +307,6 @@ int __copy_io(unsigned long clone_flags, struct task_struct *tsk)
307307
}
308308

309309
#ifdef CONFIG_BLK_ICQ
310-
/**
311-
* ioc_lookup_icq - lookup io_cq from ioc
312-
* @q: the associated request_queue
313-
*
314-
* Look up io_cq associated with @ioc - @q pair from @ioc. Must be called
315-
* with @q->queue_lock held.
316-
*/
317-
struct io_cq *ioc_lookup_icq(struct request_queue *q)
318-
{
319-
struct io_context *ioc = current->io_context;
320-
struct io_cq *icq;
321-
322-
lockdep_assert_held(&q->queue_lock);
323-
324-
/*
325-
* icq's are indexed from @ioc using radix tree and hint pointer,
326-
* both of which are protected with RCU. All removals are done
327-
* holding both q and ioc locks, and we're holding q lock - if we
328-
* find a icq which points to us, it's guaranteed to be valid.
329-
*/
330-
rcu_read_lock();
331-
icq = rcu_dereference(ioc->icq_hint);
332-
if (icq && icq->q == q)
333-
goto out;
334-
335-
icq = radix_tree_lookup(&ioc->icq_tree, q->id);
336-
if (icq && icq->q == q)
337-
rcu_assign_pointer(ioc->icq_hint, icq); /* allowed to race */
338-
else
339-
icq = NULL;
340-
out:
341-
rcu_read_unlock();
342-
return icq;
343-
}
344-
EXPORT_SYMBOL(ioc_lookup_icq);
345-
346310
/**
347311
* ioc_lookup_icq_rcu - lookup io_cq from ioc in io path
348312
* @q: the associated request_queue
@@ -420,7 +384,7 @@ static struct io_cq *ioc_create_icq(struct request_queue *q)
420384
et->ops.init_icq(icq);
421385
} else {
422386
kmem_cache_free(et->icq_cache, icq);
423-
icq = ioc_lookup_icq(q);
387+
icq = ioc_lookup_icq_rcu(q);
424388
if (!icq)
425389
printk(KERN_ERR "cfq: icq link failed!\n");
426390
}
@@ -454,9 +418,9 @@ struct io_cq *ioc_find_get_icq(struct request_queue *q)
454418
} else {
455419
get_io_context(ioc);
456420

457-
spin_lock_irq(&q->queue_lock);
458-
icq = ioc_lookup_icq(q);
459-
spin_unlock_irq(&q->queue_lock);
421+
rcu_read_lock();
422+
icq = ioc_lookup_icq_rcu(q);
423+
rcu_read_unlock();
460424
}
461425

462426
if (!icq) {

block/blk.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,6 @@ static inline void req_set_nomerge(struct request_queue *q, struct request *req)
460460
* Internal io_context interface
461461
*/
462462
struct io_cq *ioc_find_get_icq(struct request_queue *q);
463-
struct io_cq *ioc_lookup_icq(struct request_queue *q);
464463
struct io_cq *ioc_lookup_icq_rcu(struct request_queue *q);
465464
#ifdef CONFIG_BLK_ICQ
466465
void ioc_clear_queue(struct request_queue *q);

0 commit comments

Comments
 (0)