Skip to content

Commit

Permalink
blk-mq: save default hctx into ctx->hctxs for not-supported type
Browse files Browse the repository at this point in the history
Currently, we check whether the hctx type is supported every time
in hot path. Actually, this is not necessary, we could save the
default hctx into ctx->hctxs if the type is not supported when
map swqueues and use it directly with ctx->hctxs[type].

We also needn't check whether the poll is enabled or not, because
the caller would clear the REQ_HIPRI in that case.

Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Jianchao Wang authored and Jens Axboe committed Feb 1, 2019
1 parent 8ccdf4a commit bb94aea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
9 changes: 8 additions & 1 deletion block/blk-mq.c
Original file line number Diff line number Diff line change
Expand Up @@ -2431,8 +2431,11 @@ static void blk_mq_map_swqueue(struct request_queue *q)

ctx = per_cpu_ptr(q->queue_ctx, i);
for (j = 0; j < set->nr_maps; j++) {
if (!set->map[j].nr_queues)
if (!set->map[j].nr_queues) {
ctx->hctxs[j] = blk_mq_map_queue_type(q,
HCTX_TYPE_DEFAULT, i);
continue;
}

hctx = blk_mq_map_queue_type(q, j, i);
ctx->hctxs[j] = hctx;
Expand All @@ -2455,6 +2458,10 @@ static void blk_mq_map_swqueue(struct request_queue *q)
*/
BUG_ON(!hctx->nr_ctx);
}

for (; j < HCTX_MAX_TYPES; j++)
ctx->hctxs[j] = blk_mq_map_queue_type(q,
HCTX_TYPE_DEFAULT, i);
}

mutex_unlock(&q->sysfs_lock);
Expand Down
13 changes: 5 additions & 8 deletions block/blk-mq.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,12 @@ static inline struct blk_mq_hw_ctx *blk_mq_map_queue(struct request_queue *q,
{
enum hctx_type type = HCTX_TYPE_DEFAULT;

if ((flags & REQ_HIPRI) &&
q->tag_set->nr_maps > HCTX_TYPE_POLL &&
q->tag_set->map[HCTX_TYPE_POLL].nr_queues &&
test_bit(QUEUE_FLAG_POLL, &q->queue_flags))
/*
* The caller ensure that if REQ_HIPRI, poll must be enabled.
*/
if (flags & REQ_HIPRI)
type = HCTX_TYPE_POLL;

else if (((flags & REQ_OP_MASK) == REQ_OP_READ) &&
q->tag_set->nr_maps > HCTX_TYPE_READ &&
q->tag_set->map[HCTX_TYPE_READ].nr_queues)
else if ((flags & REQ_OP_MASK) == REQ_OP_READ)
type = HCTX_TYPE_READ;

return ctx->hctxs[type];
Expand Down

0 comments on commit bb94aea

Please sign in to comment.