Skip to content

Commit 8ccdf4a

Browse files
Jianchao Wangaxboe
authored andcommitted
blk-mq: save queue mapping result into ctx directly
Currently, the queue mapping result is saved in a two-dimensional array. In the hot path, to get a hctx, we need do following: q->queue_hw_ctx[q->tag_set->map[type].mq_map[cpu]] This isn't very efficient. We could save the queue mapping result into ctx directly with different hctx type, like, ctx->hctxs[type] Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 058fdec commit 8ccdf4a

5 files changed

Lines changed: 9 additions & 8 deletions

File tree

‎block/blk-mq-sched.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ bool __blk_mq_sched_bio_merge(struct request_queue *q, struct bio *bio)
321321
{
322322
struct elevator_queue *e = q->elevator;
323323
struct blk_mq_ctx *ctx = blk_mq_get_ctx(q);
324-
struct blk_mq_hw_ctx *hctx = blk_mq_map_queue(q, bio->bi_opf, ctx->cpu);
324+
struct blk_mq_hw_ctx *hctx = blk_mq_map_queue(q, bio->bi_opf, ctx);
325325
bool ret = false;
326326
enum hctx_type type;
327327

‎block/blk-mq-tag.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ unsigned int blk_mq_get_tag(struct blk_mq_alloc_data *data)
170170

171171
data->ctx = blk_mq_get_ctx(data->q);
172172
data->hctx = blk_mq_map_queue(data->q, data->cmd_flags,
173-
data->ctx->cpu);
173+
data->ctx);
174174
tags = blk_mq_tags_from_data(data);
175175
if (data->flags & BLK_MQ_REQ_RESERVED)
176176
bt = &tags->breserved_tags;

‎block/blk-mq.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ static struct request *blk_mq_get_request(struct request_queue *q,
364364
}
365365
if (likely(!data->hctx))
366366
data->hctx = blk_mq_map_queue(q, data->cmd_flags,
367-
data->ctx->cpu);
367+
data->ctx);
368368
if (data->cmd_flags & REQ_NOWAIT)
369369
data->flags |= BLK_MQ_REQ_NOWAIT;
370370

@@ -2435,7 +2435,7 @@ static void blk_mq_map_swqueue(struct request_queue *q)
24352435
continue;
24362436

24372437
hctx = blk_mq_map_queue_type(q, j, i);
2438-
2438+
ctx->hctxs[j] = hctx;
24392439
/*
24402440
* If the CPU is already set in the mask, then we've
24412441
* mapped this one already. This can happen if

‎block/blk-mq.h‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct blk_mq_ctx {
2323

2424
unsigned int cpu;
2525
unsigned short index_hw[HCTX_MAX_TYPES];
26+
struct blk_mq_hw_ctx *hctxs[HCTX_MAX_TYPES];
2627

2728
/* incremented at dispatch time */
2829
unsigned long rq_dispatched[2];
@@ -97,11 +98,11 @@ static inline struct blk_mq_hw_ctx *blk_mq_map_queue_type(struct request_queue *
9798
* blk_mq_map_queue() - map (cmd_flags,type) to hardware queue
9899
* @q: request queue
99100
* @flags: request command flags
100-
* @cpu: CPU
101+
* @cpu: cpu ctx
101102
*/
102103
static inline struct blk_mq_hw_ctx *blk_mq_map_queue(struct request_queue *q,
103104
unsigned int flags,
104-
unsigned int cpu)
105+
struct blk_mq_ctx *ctx)
105106
{
106107
enum hctx_type type = HCTX_TYPE_DEFAULT;
107108

@@ -116,7 +117,7 @@ static inline struct blk_mq_hw_ctx *blk_mq_map_queue(struct request_queue *q,
116117
q->tag_set->map[HCTX_TYPE_READ].nr_queues)
117118
type = HCTX_TYPE_READ;
118119

119-
return blk_mq_map_queue_type(q, type, cpu);
120+
return ctx->hctxs[type];
120121
}
121122

122123
/*

‎block/blk.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ extern struct ida blk_queue_ida;
3838
static inline struct blk_flush_queue *
3939
blk_get_flush_queue(struct request_queue *q, struct blk_mq_ctx *ctx)
4040
{
41-
return blk_mq_map_queue(q, REQ_OP_FLUSH, ctx->cpu)->fq;
41+
return blk_mq_map_queue(q, REQ_OP_FLUSH, ctx)->fq;
4242
}
4343

4444
static inline void __blk_get_queue(struct request_queue *q)

0 commit comments

Comments
 (0)