Skip to content

Commit 53548d2

Browse files
Christoph Hellwigaxboe
authored andcommitted
blk-mq: refactor passthrough vs flush handling in blk_mq_insert_request
While both passthrough and flush requests call directly into blk_mq_request_bypass_insert, the parameters aren't the same. Split the handling into two separate conditionals and turn the whole function into an if/elif/elif/else flow instead of the gotos. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Bart Van Assche <bvanassche@acm.org> Reviewed-by: Damien Le Moal <dlemoal@kernel.org> Link: https://lore.kernel.org/r/20230413064057.707578-11-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent a4fa57f commit 53548d2

1 file changed

Lines changed: 18 additions & 32 deletions

File tree

block/blk-mq.c

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2506,37 +2506,26 @@ static void blk_mq_insert_requests(struct blk_mq_hw_ctx *hctx,
25062506
blk_mq_run_hw_queue(hctx, run_queue_async);
25072507
}
25082508

2509-
static bool blk_mq_sched_bypass_insert(struct blk_mq_hw_ctx *hctx,
2510-
struct request *rq)
2511-
{
2512-
/*
2513-
* dispatch flush and passthrough rq directly
2514-
*
2515-
* passthrough request has to be added to hctx->dispatch directly.
2516-
* For some reason, device may be in one situation which can't
2517-
* handle FS request, so STS_RESOURCE is always returned and the
2518-
* FS request will be added to hctx->dispatch. However passthrough
2519-
* request may be required at that time for fixing the problem. If
2520-
* passthrough request is added to scheduler queue, there isn't any
2521-
* chance to dispatch it given we prioritize requests in hctx->dispatch.
2522-
*/
2523-
if ((rq->rq_flags & RQF_FLUSH_SEQ) || blk_rq_is_passthrough(rq))
2524-
return true;
2525-
2526-
return false;
2527-
}
2528-
25292509
static void blk_mq_insert_request(struct request *rq, bool at_head,
25302510
bool run_queue, bool async)
25312511
{
25322512
struct request_queue *q = rq->q;
2533-
struct elevator_queue *e = q->elevator;
25342513
struct blk_mq_ctx *ctx = rq->mq_ctx;
25352514
struct blk_mq_hw_ctx *hctx = rq->mq_hctx;
25362515

2537-
WARN_ON(e && (rq->tag != BLK_MQ_NO_TAG));
2538-
2539-
if (blk_mq_sched_bypass_insert(hctx, rq)) {
2516+
if (blk_rq_is_passthrough(rq)) {
2517+
/*
2518+
* Passthrough request have to be added to hctx->dispatch
2519+
* directly. The device may be in a situation where it can't
2520+
* handle FS request, and always returns BLK_STS_RESOURCE for
2521+
* them, which gets them added to hctx->dispatch.
2522+
*
2523+
* If a passthrough request is required to unblock the queues,
2524+
* and it is added to the scheduler queue, there is no chance to
2525+
* dispatch it given we prioritize requests in hctx->dispatch.
2526+
*/
2527+
blk_mq_request_bypass_insert(rq, at_head, false);
2528+
} else if (rq->rq_flags & RQF_FLUSH_SEQ) {
25402529
/*
25412530
* Firstly normal IO request is inserted to scheduler queue or
25422531
* sw queue, meantime we add flush request to dispatch queue(
@@ -2558,16 +2547,14 @@ static void blk_mq_insert_request(struct request *rq, bool at_head,
25582547
* Simply queue flush rq to the front of hctx->dispatch so that
25592548
* intensive flush workloads can benefit in case of NCQ HW.
25602549
*/
2561-
at_head = (rq->rq_flags & RQF_FLUSH_SEQ) ? true : at_head;
2562-
blk_mq_request_bypass_insert(rq, at_head, false);
2563-
goto run;
2564-
}
2565-
2566-
if (e) {
2550+
blk_mq_request_bypass_insert(rq, true, false);
2551+
} else if (q->elevator) {
25672552
LIST_HEAD(list);
25682553

2554+
WARN_ON_ONCE(rq->tag != BLK_MQ_NO_TAG);
2555+
25692556
list_add(&rq->queuelist, &list);
2570-
e->type->ops.insert_requests(hctx, &list, at_head);
2557+
q->elevator->type->ops.insert_requests(hctx, &list, at_head);
25712558
} else {
25722559
trace_block_rq_insert(rq);
25732560

@@ -2581,7 +2568,6 @@ static void blk_mq_insert_request(struct request *rq, bool at_head,
25812568
spin_unlock(&ctx->lock);
25822569
}
25832570

2584-
run:
25852571
if (run_queue)
25862572
blk_mq_run_hw_queue(hctx, async);
25872573
}

0 commit comments

Comments
 (0)