From: Tejun Heo <tj@kernel.org>
To: Jens Axboe <axboe@kernel.dk>, Shaohua Li <shaohua.li@intel.com>
Cc: Vivek Goyal <vgoyal@redhat.com>,
lkml <linux-kernel@vger.kernel.org>,
Knut Petersen <Knut_Petersen@t-online.de>,
mroos@linux.ee, Linus Torvalds <torvalds@linux-foundation.org>
Subject: [PATCH block/for-linus 2/3] block: simplify ioc_release_fn()
Date: Tue, 14 Feb 2012 10:16:23 -0800 [thread overview]
Message-ID: <20120214181623.GT12117@google.com> (raw)
In-Reply-To: <20120214181245.GS12117@google.com>
Reverse double lock dancing in ioc_release_fn() can be simplified by
just using trylock on the queue_lock and back out from ioc lock on
trylock failure. Simplify it.
Signed-off-by: Tejun Heo <tj@kernel.org>
---
block/blk-ioc.c | 44 +++++++++-----------------------------------
1 file changed, 9 insertions(+), 35 deletions(-)
Index: work/block/blk-ioc.c
===================================================================
--- work.orig/block/blk-ioc.c
+++ work/block/blk-ioc.c
@@ -79,7 +79,6 @@ static void ioc_release_fn(struct work_s
{
struct io_context *ioc = container_of(work, struct io_context,
release_work);
- struct request_queue *last_q = NULL;
unsigned long flags;
/*
@@ -93,44 +92,19 @@ static void ioc_release_fn(struct work_s
while (!hlist_empty(&ioc->icq_list)) {
struct io_cq *icq = hlist_entry(ioc->icq_list.first,
struct io_cq, ioc_node);
- struct request_queue *this_q = icq->q;
+ struct request_queue *q = icq->q;
- if (this_q != last_q) {
- /*
- * Need to switch to @this_q. Once we release
- * @ioc->lock, it can go away along with @cic.
- * Hold on to it.
- */
- __blk_get_queue(this_q);
-
- /*
- * blk_put_queue() might sleep thanks to kobject
- * idiocy. Always release both locks, put and
- * restart.
- */
- if (last_q) {
- spin_unlock(last_q->queue_lock);
- spin_unlock_irqrestore(&ioc->lock, flags);
- blk_put_queue(last_q);
- } else {
- spin_unlock_irqrestore(&ioc->lock, flags);
- }
-
- last_q = this_q;
- spin_lock_irqsave(this_q->queue_lock, flags);
- spin_lock_nested(&ioc->lock, 1);
- continue;
+ if (spin_trylock(q->queue_lock)) {
+ ioc_exit_icq(icq);
+ spin_unlock(q->queue_lock);
+ } else {
+ spin_unlock_irqrestore(&ioc->lock, flags);
+ cpu_relax();
+ spin_lock_irqsave_nested(&ioc->lock, flags, 1);
}
- ioc_exit_icq(icq);
}
- if (last_q) {
- spin_unlock(last_q->queue_lock);
- spin_unlock_irqrestore(&ioc->lock, flags);
- blk_put_queue(last_q);
- } else {
- spin_unlock_irqrestore(&ioc->lock, flags);
- }
+ spin_unlock_irqrestore(&ioc->lock, flags);
kmem_cache_free(iocontext_cachep, ioc);
}
next prev parent reply other threads:[~2012-02-14 18:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-14 18:12 [PATCH block/for-linus 1/3] block: replace icq->changed with icq->flags Tejun Heo
2012-02-14 18:16 ` Tejun Heo [this message]
2012-02-14 18:17 ` [PATCH block/for-linus 3/3] block: exit_io_context() should call elevator_exit_icq_fn() Tejun Heo
2012-02-15 1:09 ` [PATCH block/for-linus 1/3] block: replace icq->changed with icq->flags Shaohua Li
2012-02-15 8:43 ` Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120214181623.GT12117@google.com \
--to=tj@kernel.org \
--cc=Knut_Petersen@t-online.de \
--cc=axboe@kernel.dk \
--cc=linux-kernel@vger.kernel.org \
--cc=mroos@linux.ee \
--cc=shaohua.li@intel.com \
--cc=torvalds@linux-foundation.org \
--cc=vgoyal@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox