Skip to content

Commit 2eed896

Browse files
Ming Leigregkh
authored andcommitted
blk-mq: insert passthrough request into hctx->dispatch directly
[ Upstream commit 01e99ae ] For some reason, device may be in one situation which can't handle FS request, so STS_RESOURCE is always returned and the FS request will be added to hctx->dispatch. However passthrough request may be required at that time for fixing the problem. If passthrough request is added to scheduler queue, there isn't any chance for blk-mq to dispatch it given we prioritize requests in hctx->dispatch. Then the FS IO request may never be completed, and IO hang is caused. So passthrough request has to be added to hctx->dispatch directly for fixing the IO hang. Fix this issue by inserting passthrough request into hctx->dispatch directly together withing adding FS request to the tail of hctx->dispatch in blk_mq_dispatch_rq_list(). Actually we add FS request to tail of hctx->dispatch at default, see blk_mq_request_bypass_insert(). Then it becomes consistent with original legacy IO request path, in which passthrough request is always added to q->queue_head. Cc: Dongli Zhang <dongli.zhang@oracle.com> Cc: Christoph Hellwig <hch@infradead.org> Cc: Ewan D. Milne <emilne@redhat.com> Signed-off-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 7f35851 commit 2eed896

4 files changed

Lines changed: 29 additions & 16 deletions

File tree

‎block/blk-flush.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ void blk_insert_flush(struct request *rq)
412412
*/
413413
if ((policy & REQ_FSEQ_DATA) &&
414414
!(policy & (REQ_FSEQ_PREFLUSH | REQ_FSEQ_POSTFLUSH))) {
415-
blk_mq_request_bypass_insert(rq, false);
415+
blk_mq_request_bypass_insert(rq, false, false);
416416
return;
417417
}
418418

‎block/blk-mq-sched.c‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,19 @@ static bool blk_mq_sched_bypass_insert(struct blk_mq_hw_ctx *hctx,
361361
bool has_sched,
362362
struct request *rq)
363363
{
364-
/* dispatch flush rq directly */
365-
if (rq->rq_flags & RQF_FLUSH_SEQ) {
366-
spin_lock(&hctx->lock);
367-
list_add(&rq->queuelist, &hctx->dispatch);
368-
spin_unlock(&hctx->lock);
364+
/*
365+
* dispatch flush and passthrough rq directly
366+
*
367+
* passthrough request has to be added to hctx->dispatch directly.
368+
* For some reason, device may be in one situation which can't
369+
* handle FS request, so STS_RESOURCE is always returned and the
370+
* FS request will be added to hctx->dispatch. However passthrough
371+
* request may be required at that time for fixing the problem. If
372+
* passthrough request is added to scheduler queue, there isn't any
373+
* chance to dispatch it given we prioritize requests in hctx->dispatch.
374+
*/
375+
if ((rq->rq_flags & RQF_FLUSH_SEQ) || blk_rq_is_passthrough(rq))
369376
return true;
370-
}
371377

372378
if (has_sched)
373379
rq->rq_flags |= RQF_SORTED;
@@ -391,8 +397,10 @@ void blk_mq_sched_insert_request(struct request *rq, bool at_head,
391397

392398
WARN_ON(e && (rq->tag != -1));
393399

394-
if (blk_mq_sched_bypass_insert(hctx, !!e, rq))
400+
if (blk_mq_sched_bypass_insert(hctx, !!e, rq)) {
401+
blk_mq_request_bypass_insert(rq, at_head, false);
395402
goto run;
403+
}
396404

397405
if (e && e->type->ops.insert_requests) {
398406
LIST_HEAD(list);

‎block/blk-mq.c‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ static void blk_mq_requeue_work(struct work_struct *work)
727727
* merge.
728728
*/
729729
if (rq->rq_flags & RQF_DONTPREP)
730-
blk_mq_request_bypass_insert(rq, false);
730+
blk_mq_request_bypass_insert(rq, false, false);
731731
else
732732
blk_mq_sched_insert_request(rq, true, false, false);
733733
}
@@ -1278,7 +1278,7 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list,
12781278
q->mq_ops->commit_rqs(hctx);
12791279

12801280
spin_lock(&hctx->lock);
1281-
list_splice_init(list, &hctx->dispatch);
1281+
list_splice_tail_init(list, &hctx->dispatch);
12821282
spin_unlock(&hctx->lock);
12831283

12841284
/*
@@ -1629,12 +1629,16 @@ void __blk_mq_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
16291629
* Should only be used carefully, when the caller knows we want to
16301630
* bypass a potential IO scheduler on the target device.
16311631
*/
1632-
void blk_mq_request_bypass_insert(struct request *rq, bool run_queue)
1632+
void blk_mq_request_bypass_insert(struct request *rq, bool at_head,
1633+
bool run_queue)
16331634
{
16341635
struct blk_mq_hw_ctx *hctx = rq->mq_hctx;
16351636

16361637
spin_lock(&hctx->lock);
1637-
list_add_tail(&rq->queuelist, &hctx->dispatch);
1638+
if (at_head)
1639+
list_add(&rq->queuelist, &hctx->dispatch);
1640+
else
1641+
list_add_tail(&rq->queuelist, &hctx->dispatch);
16381642
spin_unlock(&hctx->lock);
16391643

16401644
if (run_queue)
@@ -1824,7 +1828,7 @@ static blk_status_t __blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx,
18241828
if (bypass_insert)
18251829
return BLK_STS_RESOURCE;
18261830

1827-
blk_mq_request_bypass_insert(rq, run_queue);
1831+
blk_mq_request_bypass_insert(rq, false, run_queue);
18281832
return BLK_STS_OK;
18291833
}
18301834

@@ -1840,7 +1844,7 @@ static void blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx,
18401844

18411845
ret = __blk_mq_try_issue_directly(hctx, rq, cookie, false, true);
18421846
if (ret == BLK_STS_RESOURCE || ret == BLK_STS_DEV_RESOURCE)
1843-
blk_mq_request_bypass_insert(rq, true);
1847+
blk_mq_request_bypass_insert(rq, false, true);
18441848
else if (ret != BLK_STS_OK)
18451849
blk_mq_end_request(rq, ret);
18461850

@@ -1874,7 +1878,7 @@ void blk_mq_try_issue_list_directly(struct blk_mq_hw_ctx *hctx,
18741878
if (ret != BLK_STS_OK) {
18751879
if (ret == BLK_STS_RESOURCE ||
18761880
ret == BLK_STS_DEV_RESOURCE) {
1877-
blk_mq_request_bypass_insert(rq,
1881+
blk_mq_request_bypass_insert(rq, false,
18781882
list_empty(list));
18791883
break;
18801884
}

‎block/blk-mq.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ int blk_mq_alloc_rqs(struct blk_mq_tag_set *set, struct blk_mq_tags *tags,
6666
*/
6767
void __blk_mq_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
6868
bool at_head);
69-
void blk_mq_request_bypass_insert(struct request *rq, bool run_queue);
69+
void blk_mq_request_bypass_insert(struct request *rq, bool at_head,
70+
bool run_queue);
7071
void blk_mq_insert_requests(struct blk_mq_hw_ctx *hctx, struct blk_mq_ctx *ctx,
7172
struct list_head *list);
7273

0 commit comments

Comments
 (0)