Skip to content

Commit bb94aea

Browse files
Jianchao Wangaxboe
authored andcommitted
blk-mq: save default hctx into ctx->hctxs for not-supported type
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 <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 8ccdf4a commit bb94aea

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

block/blk-mq.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2431,8 +2431,11 @@ static void blk_mq_map_swqueue(struct request_queue *q)
24312431

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

24372440
hctx = blk_mq_map_queue_type(q, j, i);
24382441
ctx->hctxs[j] = hctx;
@@ -2455,6 +2458,10 @@ static void blk_mq_map_swqueue(struct request_queue *q)
24552458
*/
24562459
BUG_ON(!hctx->nr_ctx);
24572460
}
2461+
2462+
for (; j < HCTX_MAX_TYPES; j++)
2463+
ctx->hctxs[j] = blk_mq_map_queue_type(q,
2464+
HCTX_TYPE_DEFAULT, i);
24582465
}
24592466

24602467
mutex_unlock(&q->sysfs_lock);

block/blk-mq.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,12 @@ static inline struct blk_mq_hw_ctx *blk_mq_map_queue(struct request_queue *q,
106106
{
107107
enum hctx_type type = HCTX_TYPE_DEFAULT;
108108

109-
if ((flags & REQ_HIPRI) &&
110-
q->tag_set->nr_maps > HCTX_TYPE_POLL &&
111-
q->tag_set->map[HCTX_TYPE_POLL].nr_queues &&
112-
test_bit(QUEUE_FLAG_POLL, &q->queue_flags))
109+
/*
110+
* The caller ensure that if REQ_HIPRI, poll must be enabled.
111+
*/
112+
if (flags & REQ_HIPRI)
113113
type = HCTX_TYPE_POLL;
114-
115-
else if (((flags & REQ_OP_MASK) == REQ_OP_READ) &&
116-
q->tag_set->nr_maps > HCTX_TYPE_READ &&
117-
q->tag_set->map[HCTX_TYPE_READ].nr_queues)
114+
else if ((flags & REQ_OP_MASK) == REQ_OP_READ)
118115
type = HCTX_TYPE_READ;
119116

120117
return ctx->hctxs[type];

0 commit comments

Comments
 (0)