diff options
author | Asias He <asias@redhat.com> | 2012-06-15 02:45:25 -0400 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2012-06-15 02:45:25 -0400 |
commit | 458f27a9823a0841acb4ca59e0e7f33e181f85e2 (patch) | |
tree | 04a481fce485854e96cbcef7f7bf860f85a18d55 /block | |
parent | 6d407cfaf5a56b3030b9e55d0f542601e173c5d2 (diff) |
block: Avoid missed wakeup in request waitqueue
After hot-unplug a stressed disk, I found that rl->wait[] is not empty
while rl->count[] is empty and there are theads still sleeping on
get_request after the queue cleanup. With simple debug code, I found
there are exactly nr_sleep - nr_wakeup of theads in D state. So there
are missed wakeup.
$ dmesg | grep nr_sleep
[ 52.917115] ---> nr_sleep=1046, nr_wakeup=873, delta=173
$ vmstat 1
1 173 0 712640 24292 96172 0 0 0 0 419 757 0 0 0 100 0
To quote Tejun:
Ah, okay, freed_request() wakes up single waiter with the assumption
that after the wakeup there will at least be one successful allocation
which in turn will continue the wakeup chain until the wait list is
empty - ie. waiter wakeup is dependent on successful request
allocation happening after each wakeup. With queue marked dead, any
woken up waiter fails the allocation path, so the wakeup chaining is
lost and we're left with hung waiters. What we need is wake_up_all()
after drain completion.
This patch fixes the missed wakeup by waking up all the theads which
are sleeping on wait queue after queue drain.
Changes in v2: Drop waitqueue_active() optimization
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Asias He <asias@redhat.com>
Fixed a bug by me, where stacked devices would oops on calling
blk_drain_queue() since ->rq.wait[] do not get initialized unless
it's a full queue setup.
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block')
-rw-r--r-- | block/blk-core.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/block/blk-core.c b/block/blk-core.c index 3c923a7aeb56..ce7fbf8d85a6 100644 --- a/block/blk-core.c +++ b/block/blk-core.c | |||
@@ -361,9 +361,10 @@ EXPORT_SYMBOL(blk_put_queue); | |||
361 | */ | 361 | */ |
362 | void blk_drain_queue(struct request_queue *q, bool drain_all) | 362 | void blk_drain_queue(struct request_queue *q, bool drain_all) |
363 | { | 363 | { |
364 | int i; | ||
365 | |||
364 | while (true) { | 366 | while (true) { |
365 | bool drain = false; | 367 | bool drain = false; |
366 | int i; | ||
367 | 368 | ||
368 | spin_lock_irq(q->queue_lock); | 369 | spin_lock_irq(q->queue_lock); |
369 | 370 | ||
@@ -408,6 +409,18 @@ void blk_drain_queue(struct request_queue *q, bool drain_all) | |||
408 | break; | 409 | break; |
409 | msleep(10); | 410 | msleep(10); |
410 | } | 411 | } |
412 | |||
413 | /* | ||
414 | * With queue marked dead, any woken up waiter will fail the | ||
415 | * allocation path, so the wakeup chaining is lost and we're | ||
416 | * left with hung waiters. We need to wake up those waiters. | ||
417 | */ | ||
418 | if (q->request_fn) { | ||
419 | spin_lock_irq(q->queue_lock); | ||
420 | for (i = 0; i < ARRAY_SIZE(q->rq.wait); i++) | ||
421 | wake_up_all(&q->rq.wait[i]); | ||
422 | spin_unlock_irq(q->queue_lock); | ||
423 | } | ||
411 | } | 424 | } |
412 | 425 | ||
413 | /** | 426 | /** |