Skip to content

Commit f9afca4

Browse files
committed
blk-mq: pass in request/bio flags to queue mapping
Prep patch for being able to place request based not just on CPU location, but also on the type of request. Reviewed-by: Hannes Reinecke <hare@suse.com> Reviewed-by: Keith Busch <keith.busch@intel.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent ff2c566 commit f9afca4

7 files changed

Lines changed: 57 additions & 37 deletions

File tree

‎block/blk-flush.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ static void flush_end_io(struct request *flush_rq, blk_status_t error)
215215

216216
/* release the tag's ownership to the req cloned from */
217217
spin_lock_irqsave(&fq->mq_flush_lock, flags);
218-
hctx = blk_mq_map_queue(q, flush_rq->mq_ctx->cpu);
218+
hctx = blk_mq_map_queue(q, flush_rq->cmd_flags, flush_rq->mq_ctx->cpu);
219219
if (!q->elevator) {
220220
blk_mq_tag_set_rq(hctx, flush_rq->tag, fq->orig_rq);
221221
flush_rq->tag = -1;
@@ -301,7 +301,8 @@ static void blk_kick_flush(struct request_queue *q, struct blk_flush_queue *fq,
301301
if (!q->elevator) {
302302
fq->orig_rq = first_rq;
303303
flush_rq->tag = first_rq->tag;
304-
hctx = blk_mq_map_queue(q, first_rq->mq_ctx->cpu);
304+
hctx = blk_mq_map_queue(q, first_rq->cmd_flags,
305+
first_rq->mq_ctx->cpu);
305306
blk_mq_tag_set_rq(hctx, first_rq->tag, flush_rq);
306307
} else {
307308
flush_rq->internal_tag = first_rq->internal_tag;
@@ -324,7 +325,7 @@ static void mq_flush_data_end_io(struct request *rq, blk_status_t error)
324325
unsigned long flags;
325326
struct blk_flush_queue *fq = blk_get_flush_queue(q, ctx);
326327

327-
hctx = blk_mq_map_queue(q, ctx->cpu);
328+
hctx = blk_mq_map_queue(q, rq->cmd_flags, ctx->cpu);
328329

329330
if (q->elevator) {
330331
WARN_ON(rq->tag < 0);

‎block/blk-mq-debugfs.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,10 @@ struct show_busy_params {
427427
static void hctx_show_busy_rq(struct request *rq, void *data, bool reserved)
428428
{
429429
const struct show_busy_params *params = data;
430+
struct blk_mq_hw_ctx *hctx;
430431

431-
if (blk_mq_map_queue(rq->q, rq->mq_ctx->cpu) == params->hctx)
432+
hctx = blk_mq_map_queue(rq->q, rq->cmd_flags, rq->mq_ctx->cpu);
433+
if (hctx == params->hctx)
432434
__blk_mq_debugfs_rq_show(params->m,
433435
list_entry_rq(&rq->queuelist));
434436
}

‎block/blk-mq-sched.c‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ bool __blk_mq_sched_bio_merge(struct request_queue *q, struct bio *bio)
310310
{
311311
struct elevator_queue *e = q->elevator;
312312
struct blk_mq_ctx *ctx = blk_mq_get_ctx(q);
313-
struct blk_mq_hw_ctx *hctx = blk_mq_map_queue(q, ctx->cpu);
313+
struct blk_mq_hw_ctx *hctx = blk_mq_map_queue(q, bio->bi_opf, ctx->cpu);
314314
bool ret = false;
315315

316316
if (e && e->type->ops.bio_merge) {
@@ -366,7 +366,9 @@ void blk_mq_sched_insert_request(struct request *rq, bool at_head,
366366
struct request_queue *q = rq->q;
367367
struct elevator_queue *e = q->elevator;
368368
struct blk_mq_ctx *ctx = rq->mq_ctx;
369-
struct blk_mq_hw_ctx *hctx = blk_mq_map_queue(q, ctx->cpu);
369+
struct blk_mq_hw_ctx *hctx;
370+
371+
hctx = blk_mq_map_queue(q, rq->cmd_flags, ctx->cpu);
370372

371373
/* flush rq in flush machinery need to be dispatched directly */
372374
if (!(rq->rq_flags & RQF_FLUSH_SEQ) && op_is_flush(rq->cmd_flags)) {
@@ -399,9 +401,15 @@ void blk_mq_sched_insert_requests(struct request_queue *q,
399401
struct blk_mq_ctx *ctx,
400402
struct list_head *list, bool run_queue_async)
401403
{
402-
struct blk_mq_hw_ctx *hctx = blk_mq_map_queue(q, ctx->cpu);
403-
struct elevator_queue *e = hctx->queue->elevator;
404+
struct blk_mq_hw_ctx *hctx;
405+
struct elevator_queue *e;
406+
struct request *rq;
407+
408+
/* For list inserts, requests better be on the same hw queue */
409+
rq = list_first_entry(list, struct request, queuelist);
410+
hctx = blk_mq_map_queue(q, rq->cmd_flags, ctx->cpu);
404411

412+
e = hctx->queue->elevator;
405413
if (e && e->type->ops.insert_requests)
406414
e->type->ops.insert_requests(hctx, list, false);
407415
else {

‎block/blk-mq-tag.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ unsigned int blk_mq_get_tag(struct blk_mq_alloc_data *data)
168168
io_schedule();
169169

170170
data->ctx = blk_mq_get_ctx(data->q);
171-
data->hctx = blk_mq_map_queue(data->q, data->ctx->cpu);
171+
data->hctx = blk_mq_map_queue(data->q, data->cmd_flags,
172+
data->ctx->cpu);
172173
tags = blk_mq_tags_from_data(data);
173174
if (data->flags & BLK_MQ_REQ_RESERVED)
174175
bt = &tags->breserved_tags;
@@ -530,7 +531,7 @@ u32 blk_mq_unique_tag(struct request *rq)
530531
struct blk_mq_hw_ctx *hctx;
531532
int hwq = 0;
532533

533-
hctx = blk_mq_map_queue(q, rq->mq_ctx->cpu);
534+
hctx = blk_mq_map_queue(q, rq->cmd_flags, rq->mq_ctx->cpu);
534535
hwq = hctx->queue_num;
535536

536537
return (hwq << BLK_MQ_UNIQUE_TAG_BITS) |

‎block/blk-mq.c‎

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,8 @@ static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data,
331331
}
332332

333333
static struct request *blk_mq_get_request(struct request_queue *q,
334-
struct bio *bio, unsigned int op,
335-
struct blk_mq_alloc_data *data)
334+
struct bio *bio,
335+
struct blk_mq_alloc_data *data)
336336
{
337337
struct elevator_queue *e = q->elevator;
338338
struct request *rq;
@@ -346,8 +346,9 @@ static struct request *blk_mq_get_request(struct request_queue *q,
346346
put_ctx_on_error = true;
347347
}
348348
if (likely(!data->hctx))
349-
data->hctx = blk_mq_map_queue(q, data->ctx->cpu);
350-
if (op & REQ_NOWAIT)
349+
data->hctx = blk_mq_map_queue(q, data->cmd_flags,
350+
data->ctx->cpu);
351+
if (data->cmd_flags & REQ_NOWAIT)
351352
data->flags |= BLK_MQ_REQ_NOWAIT;
352353

353354
if (e) {
@@ -358,9 +359,10 @@ static struct request *blk_mq_get_request(struct request_queue *q,
358359
* dispatch list. Don't include reserved tags in the
359360
* limiting, as it isn't useful.
360361
*/
361-
if (!op_is_flush(op) && e->type->ops.limit_depth &&
362+
if (!op_is_flush(data->cmd_flags) &&
363+
e->type->ops.limit_depth &&
362364
!(data->flags & BLK_MQ_REQ_RESERVED))
363-
e->type->ops.limit_depth(op, data);
365+
e->type->ops.limit_depth(data->cmd_flags, data);
364366
} else {
365367
blk_mq_tag_busy(data->hctx);
366368
}
@@ -375,8 +377,8 @@ static struct request *blk_mq_get_request(struct request_queue *q,
375377
return NULL;
376378
}
377379

378-
rq = blk_mq_rq_ctx_init(data, tag, op);
379-
if (!op_is_flush(op)) {
380+
rq = blk_mq_rq_ctx_init(data, tag, data->cmd_flags);
381+
if (!op_is_flush(data->cmd_flags)) {
380382
rq->elv.icq = NULL;
381383
if (e && e->type->ops.prepare_request) {
382384
if (e->type->icq_cache && rq_ioc(bio))
@@ -393,15 +395,15 @@ static struct request *blk_mq_get_request(struct request_queue *q,
393395
struct request *blk_mq_alloc_request(struct request_queue *q, unsigned int op,
394396
blk_mq_req_flags_t flags)
395397
{
396-
struct blk_mq_alloc_data alloc_data = { .flags = flags };
398+
struct blk_mq_alloc_data alloc_data = { .flags = flags, .cmd_flags = op };
397399
struct request *rq;
398400
int ret;
399401

400402
ret = blk_queue_enter(q, flags);
401403
if (ret)
402404
return ERR_PTR(ret);
403405

404-
rq = blk_mq_get_request(q, NULL, op, &alloc_data);
406+
rq = blk_mq_get_request(q, NULL, &alloc_data);
405407
blk_queue_exit(q);
406408

407409
if (!rq)
@@ -419,7 +421,7 @@ EXPORT_SYMBOL(blk_mq_alloc_request);
419421
struct request *blk_mq_alloc_request_hctx(struct request_queue *q,
420422
unsigned int op, blk_mq_req_flags_t flags, unsigned int hctx_idx)
421423
{
422-
struct blk_mq_alloc_data alloc_data = { .flags = flags };
424+
struct blk_mq_alloc_data alloc_data = { .flags = flags, .cmd_flags = op };
423425
struct request *rq;
424426
unsigned int cpu;
425427
int ret;
@@ -452,7 +454,7 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q,
452454
cpu = cpumask_first_and(alloc_data.hctx->cpumask, cpu_online_mask);
453455
alloc_data.ctx = __blk_mq_get_ctx(q, cpu);
454456

455-
rq = blk_mq_get_request(q, NULL, op, &alloc_data);
457+
rq = blk_mq_get_request(q, NULL, &alloc_data);
456458
blk_queue_exit(q);
457459

458460
if (!rq)
@@ -466,7 +468,7 @@ static void __blk_mq_free_request(struct request *rq)
466468
{
467469
struct request_queue *q = rq->q;
468470
struct blk_mq_ctx *ctx = rq->mq_ctx;
469-
struct blk_mq_hw_ctx *hctx = blk_mq_map_queue(q, ctx->cpu);
471+
struct blk_mq_hw_ctx *hctx = blk_mq_map_queue(q, rq->cmd_flags, ctx->cpu);
470472
const int sched_tag = rq->internal_tag;
471473

472474
blk_pm_mark_last_busy(rq);
@@ -483,7 +485,7 @@ void blk_mq_free_request(struct request *rq)
483485
struct request_queue *q = rq->q;
484486
struct elevator_queue *e = q->elevator;
485487
struct blk_mq_ctx *ctx = rq->mq_ctx;
486-
struct blk_mq_hw_ctx *hctx = blk_mq_map_queue(q, ctx->cpu);
488+
struct blk_mq_hw_ctx *hctx = blk_mq_map_queue(q, rq->cmd_flags, ctx->cpu);
487489

488490
if (rq->rq_flags & RQF_ELVPRIV) {
489491
if (e && e->type->ops.finish_request)
@@ -977,8 +979,9 @@ bool blk_mq_get_driver_tag(struct request *rq)
977979
{
978980
struct blk_mq_alloc_data data = {
979981
.q = rq->q,
980-
.hctx = blk_mq_map_queue(rq->q, rq->mq_ctx->cpu),
982+
.hctx = blk_mq_map_queue(rq->q, rq->cmd_flags, rq->mq_ctx->cpu),
981983
.flags = BLK_MQ_REQ_NOWAIT,
984+
.cmd_flags = rq->cmd_flags,
982985
};
983986
bool shared;
984987

@@ -1142,7 +1145,7 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list,
11421145

11431146
rq = list_first_entry(list, struct request, queuelist);
11441147

1145-
hctx = blk_mq_map_queue(rq->q, rq->mq_ctx->cpu);
1148+
hctx = blk_mq_map_queue(rq->q, rq->cmd_flags, rq->mq_ctx->cpu);
11461149
if (!got_budget && !blk_mq_get_dispatch_budget(hctx))
11471150
break;
11481151

@@ -1573,7 +1576,8 @@ void __blk_mq_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
15731576
void blk_mq_request_bypass_insert(struct request *rq, bool run_queue)
15741577
{
15751578
struct blk_mq_ctx *ctx = rq->mq_ctx;
1576-
struct blk_mq_hw_ctx *hctx = blk_mq_map_queue(rq->q, ctx->cpu);
1579+
struct blk_mq_hw_ctx *hctx = blk_mq_map_queue(rq->q, rq->cmd_flags,
1580+
ctx->cpu);
15771581

15781582
spin_lock(&hctx->lock);
15791583
list_add_tail(&rq->queuelist, &hctx->dispatch);
@@ -1783,7 +1787,8 @@ blk_status_t blk_mq_request_issue_directly(struct request *rq)
17831787
int srcu_idx;
17841788
blk_qc_t unused_cookie;
17851789
struct blk_mq_ctx *ctx = rq->mq_ctx;
1786-
struct blk_mq_hw_ctx *hctx = blk_mq_map_queue(rq->q, ctx->cpu);
1790+
struct blk_mq_hw_ctx *hctx = blk_mq_map_queue(rq->q, rq->cmd_flags,
1791+
ctx->cpu);
17871792

17881793
hctx_lock(hctx, &srcu_idx);
17891794
ret = __blk_mq_try_issue_directly(hctx, rq, &unused_cookie, true);
@@ -1817,7 +1822,7 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
18171822
{
18181823
const int is_sync = op_is_sync(bio->bi_opf);
18191824
const int is_flush_fua = op_is_flush(bio->bi_opf);
1820-
struct blk_mq_alloc_data data = { .flags = 0 };
1825+
struct blk_mq_alloc_data data = { .flags = 0, .cmd_flags = bio->bi_opf };
18211826
struct request *rq;
18221827
unsigned int request_count = 0;
18231828
struct blk_plug *plug;
@@ -1840,7 +1845,7 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
18401845

18411846
rq_qos_throttle(q, bio, NULL);
18421847

1843-
rq = blk_mq_get_request(q, bio, bio->bi_opf, &data);
1848+
rq = blk_mq_get_request(q, bio, &data);
18441849
if (unlikely(!rq)) {
18451850
rq_qos_cleanup(q, bio);
18461851
if (bio->bi_opf & REQ_NOWAIT)
@@ -1909,6 +1914,7 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
19091914

19101915
if (same_queue_rq) {
19111916
data.hctx = blk_mq_map_queue(q,
1917+
same_queue_rq->cmd_flags,
19121918
same_queue_rq->mq_ctx->cpu);
19131919
blk_mq_try_issue_directly(data.hctx, same_queue_rq,
19141920
&cookie);
@@ -2263,7 +2269,7 @@ static void blk_mq_init_cpu_queues(struct request_queue *q,
22632269
* Set local node, IFF we have more than one hw queue. If
22642270
* not, we remain on the home node of the device
22652271
*/
2266-
hctx = blk_mq_map_queue(q, i);
2272+
hctx = blk_mq_map_queue_type(q, 0, i);
22672273
if (nr_hw_queues > 1 && hctx->numa_node == NUMA_NO_NODE)
22682274
hctx->numa_node = local_memory_node(cpu_to_node(i));
22692275
}
@@ -2336,7 +2342,7 @@ static void blk_mq_map_swqueue(struct request_queue *q)
23362342
}
23372343

23382344
ctx = per_cpu_ptr(q->queue_ctx, i);
2339-
hctx = blk_mq_map_queue(q, i);
2345+
hctx = blk_mq_map_queue_type(q, 0, i);
23402346

23412347
cpumask_set_cpu(i, hctx->cpumask);
23422348
ctx->index_hw = hctx->nr_ctx;

‎block/blk-mq.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ void blk_mq_try_issue_list_directly(struct blk_mq_hw_ctx *hctx,
7373
extern int blk_mq_hw_queue_to_node(struct blk_mq_queue_map *qmap, unsigned int);
7474

7575
static inline struct blk_mq_hw_ctx *blk_mq_map_queue(struct request_queue *q,
76+
unsigned int flags,
7677
unsigned int cpu)
7778
{
7879
struct blk_mq_tag_set *set = q->tag_set;
@@ -84,7 +85,7 @@ static inline struct blk_mq_hw_ctx *blk_mq_map_queue_type(struct request_queue *
8485
unsigned int hctx_type,
8586
unsigned int cpu)
8687
{
87-
return blk_mq_map_queue(q, cpu);
88+
return blk_mq_map_queue(q, hctx_type, cpu);
8889
}
8990

9091
/*
@@ -135,6 +136,7 @@ struct blk_mq_alloc_data {
135136
struct request_queue *q;
136137
blk_mq_req_flags_t flags;
137138
unsigned int shallow_depth;
139+
unsigned int cmd_flags;
138140

139141
/* input & output parameter */
140142
struct blk_mq_ctx *ctx;
@@ -209,7 +211,7 @@ static inline void blk_mq_put_driver_tag(struct request *rq)
209211
if (rq->tag == -1 || rq->internal_tag == -1)
210212
return;
211213

212-
hctx = blk_mq_map_queue(rq->q, rq->mq_ctx->cpu);
214+
hctx = blk_mq_map_queue(rq->q, rq->cmd_flags, rq->mq_ctx->cpu);
213215
__blk_mq_put_driver_tag(hctx, rq);
214216
}
215217

‎block/blk.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ static inline void queue_flag_clear(unsigned int flag, struct request_queue *q)
104104
__clear_bit(flag, &q->queue_flags);
105105
}
106106

107-
static inline struct blk_flush_queue *blk_get_flush_queue(
108-
struct request_queue *q, struct blk_mq_ctx *ctx)
107+
static inline struct blk_flush_queue *
108+
blk_get_flush_queue(struct request_queue *q, struct blk_mq_ctx *ctx)
109109
{
110-
return blk_mq_map_queue(q, ctx->cpu)->fq;
110+
return blk_mq_map_queue(q, REQ_OP_FLUSH, ctx->cpu)->fq;
111111
}
112112

113113
static inline void __blk_get_queue(struct request_queue *q)

0 commit comments

Comments
 (0)