Skip to content

Commit 9ba52e5

Browse files
shligitaxboe
authored andcommitted
blk-mq: don't lose requests if a stopped queue restarts
Normally if driver is busy to dispatch a request the logic is like below: block layer: driver: __blk_mq_run_hw_queue a. blk_mq_stop_hw_queue b. rq add to ctx->dispatch later: 1. blk_mq_start_hw_queue 2. __blk_mq_run_hw_queue But it's possible step 1-2 runs between a and b. And since rq isn't in ctx->dispatch yet, step 2 will not run rq. The rq might get lost if there are no subsequent requests kick in. Signed-off-by: Shaohua Li <shli@fb.com> Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent b2387dd commit 9ba52e5

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

block/blk-mq.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,16 @@ static void __blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx)
858858
spin_lock(&hctx->lock);
859859
list_splice(&rq_list, &hctx->dispatch);
860860
spin_unlock(&hctx->lock);
861+
/*
862+
* the queue is expected stopped with BLK_MQ_RQ_QUEUE_BUSY, but
863+
* it's possible the queue is stopped and restarted again
864+
* before this. Queue restart will dispatch requests. And since
865+
* requests in rq_list aren't added into hctx->dispatch yet,
866+
* the requests in rq_list might get lost.
867+
*
868+
* blk_mq_run_hw_queue() already checks the STOPPED bit
869+
**/
870+
blk_mq_run_hw_queue(hctx, true);
861871
}
862872
}
863873

0 commit comments

Comments
 (0)