Skip to content

Commit 600c3b0

Browse files
Christoph Hellwigaxboe
authored andcommitted
blk-mq: open code __blk_mq_alloc_request in blk_mq_alloc_request_hctx
blk_mq_alloc_request_hctx is only used for NVMeoF connect commands, so tailor it to the specific requirements, and don't bother the general fast path code with its special twinkles. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Ming Lei <ming.lei@redhat.com> Reviewed-by: Hannes Reinecke <hare@suse.de Reviewed-by: Daniel Wagner <dwagner@suse.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 7664736 commit 600c3b0

1 file changed

Lines changed: 23 additions & 21 deletions

File tree

‎block/blk-mq.c‎

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -351,21 +351,13 @@ static struct request *__blk_mq_alloc_request(struct blk_mq_alloc_data *data)
351351
{
352352
struct request_queue *q = data->q;
353353
struct elevator_queue *e = q->elevator;
354-
unsigned int tag;
355-
bool clear_ctx_on_error = false;
356354
u64 alloc_time_ns = 0;
355+
unsigned int tag;
357356

358357
/* alloc_time includes depth and tag waits */
359358
if (blk_queue_rq_alloc_time(q))
360359
alloc_time_ns = ktime_get_ns();
361360

362-
if (likely(!data->ctx)) {
363-
data->ctx = blk_mq_get_ctx(q);
364-
clear_ctx_on_error = true;
365-
}
366-
if (likely(!data->hctx))
367-
data->hctx = blk_mq_map_queue(q, data->cmd_flags,
368-
data->ctx);
369361
if (data->cmd_flags & REQ_NOWAIT)
370362
data->flags |= BLK_MQ_REQ_NOWAIT;
371363

@@ -381,17 +373,16 @@ static struct request *__blk_mq_alloc_request(struct blk_mq_alloc_data *data)
381373
e->type->ops.limit_depth &&
382374
!(data->flags & BLK_MQ_REQ_RESERVED))
383375
e->type->ops.limit_depth(data->cmd_flags, data);
384-
} else {
385-
blk_mq_tag_busy(data->hctx);
386376
}
387377

378+
data->ctx = blk_mq_get_ctx(q);
379+
data->hctx = blk_mq_map_queue(q, data->cmd_flags, data->ctx);
380+
if (!(data->flags & BLK_MQ_REQ_INTERNAL))
381+
blk_mq_tag_busy(data->hctx);
382+
388383
tag = blk_mq_get_tag(data);
389-
if (tag == BLK_MQ_NO_TAG) {
390-
if (clear_ctx_on_error)
391-
data->ctx = NULL;
384+
if (tag == BLK_MQ_NO_TAG)
392385
return NULL;
393-
}
394-
395386
return blk_mq_rq_ctx_init(data, tag, alloc_time_ns);
396387
}
397388

@@ -431,17 +422,22 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q,
431422
.flags = flags,
432423
.cmd_flags = op,
433424
};
434-
struct request *rq;
425+
u64 alloc_time_ns = 0;
435426
unsigned int cpu;
427+
unsigned int tag;
436428
int ret;
437429

430+
/* alloc_time includes depth and tag waits */
431+
if (blk_queue_rq_alloc_time(q))
432+
alloc_time_ns = ktime_get_ns();
433+
438434
/*
439435
* If the tag allocator sleeps we could get an allocation for a
440436
* different hardware context. No need to complicate the low level
441437
* allocator for this for the rare use case of a command tied to
442438
* a specific queue.
443439
*/
444-
if (WARN_ON_ONCE(!(flags & BLK_MQ_REQ_NOWAIT)))
440+
if (WARN_ON_ONCE(!(flags & (BLK_MQ_REQ_NOWAIT | BLK_MQ_REQ_RESERVED))))
445441
return ERR_PTR(-EINVAL);
446442

447443
if (hctx_idx >= q->nr_hw_queues)
@@ -462,11 +458,17 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q,
462458
cpu = cpumask_first_and(data.hctx->cpumask, cpu_online_mask);
463459
data.ctx = __blk_mq_get_ctx(q, cpu);
464460

461+
if (q->elevator)
462+
data.flags |= BLK_MQ_REQ_INTERNAL;
463+
else
464+
blk_mq_tag_busy(data.hctx);
465+
465466
ret = -EWOULDBLOCK;
466-
rq = __blk_mq_alloc_request(&data);
467-
if (!rq)
467+
tag = blk_mq_get_tag(&data);
468+
if (tag == BLK_MQ_NO_TAG)
468469
goto out_queue_exit;
469-
return rq;
470+
return blk_mq_rq_ctx_init(&data, tag, alloc_time_ns);
471+
470472
out_queue_exit:
471473
blk_queue_exit(q);
472474
return ERR_PTR(ret);

0 commit comments

Comments
 (0)