Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

blk-mq-sched: unify request prepare methods

This patch makes sure we always allocate requests in the core blk-mq
code and use a common prepare_request method to initialize them for
both mq I/O schedulers. For Kyber and additional limit_depth method
is added that is called before allocating the request.

Also because none of the intializations can really fail the new method
does not return an error - instead the bfq finish method is hardened
to deal with the no-IOC case.

Last but not least this removes the abuse of RQF_QUEUE by the blk-mq
scheduling code as RQF_ELFPRIV is all that is needed now.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christoph Hellwig and committed by
Jens Axboe
5bbf4e5a 44e8c2bf

+32 -38
+12 -7
block/bfq-iosched.c
··· 4292 4292 4293 4293 static void bfq_finish_request(struct request *rq) 4294 4294 { 4295 - struct bfq_queue *bfqq = RQ_BFQQ(rq); 4296 - struct bfq_data *bfqd = bfqq->bfqd; 4295 + struct bfq_queue *bfqq; 4296 + struct bfq_data *bfqd; 4297 + 4298 + if (!rq->elv.icq) 4299 + return; 4300 + 4301 + bfqq = RQ_BFQQ(rq); 4302 + bfqd = bfqq->bfqd; 4297 4303 4298 4304 if (rq->rq_flags & RQF_STARTED) 4299 4305 bfqg_stats_update_completion(bfqq_group(bfqq), ··· 4400 4394 /* 4401 4395 * Allocate bfq data structures associated with this request. 4402 4396 */ 4403 - static int bfq_get_rq_private(struct request_queue *q, struct request *rq, 4404 - struct bio *bio) 4397 + static void bfq_prepare_request(struct request *rq, struct bio *bio) 4405 4398 { 4399 + struct request_queue *q = rq->q; 4406 4400 struct bfq_data *bfqd = q->elevator->elevator_data; 4407 4401 struct bfq_io_cq *bic; 4408 4402 const int is_sync = rq_is_sync(rq); ··· 4411 4405 bool split = false; 4412 4406 4413 4407 if (!rq->elv.icq) 4414 - return 1; 4408 + return; 4415 4409 bic = icq_to_bic(rq->elv.icq); 4416 4410 4417 4411 spin_lock_irq(&bfqd->lock); ··· 4472 4466 bfq_handle_burst(bfqd, bfqq); 4473 4467 4474 4468 spin_unlock_irq(&bfqd->lock); 4475 - return 0; 4476 4469 } 4477 4470 4478 4471 static void bfq_idle_slice_timer_body(struct bfq_queue *bfqq) ··· 4950 4945 4951 4946 static struct elevator_type iosched_bfq_mq = { 4952 4947 .ops.mq = { 4953 - .get_rq_priv = bfq_get_rq_private, 4948 + .prepare_request = bfq_prepare_request, 4954 4949 .finish_request = bfq_finish_request, 4955 4950 .exit_icq = bfq_exit_icq, 4956 4951 .insert_requests = bfq_insert_requests,
+6 -16
block/blk-mq.c
··· 298 298 * Flush requests are special and go directly to the 299 299 * dispatch list. 300 300 */ 301 - if (!op_is_flush(op) && e->type->ops.mq.get_request) { 302 - rq = e->type->ops.mq.get_request(q, op, data); 303 - if (rq) 304 - rq->rq_flags |= RQF_QUEUED; 305 - goto allocated; 306 - } 301 + if (!op_is_flush(op) && e->type->ops.mq.limit_depth) 302 + e->type->ops.mq.limit_depth(op, data); 307 303 } 308 304 309 305 rq = __blk_mq_alloc_request(data, op); 310 - allocated: 311 306 if (!rq) { 312 307 blk_queue_exit(q); 313 308 return NULL; ··· 310 315 311 316 if (!op_is_flush(op)) { 312 317 rq->elv.icq = NULL; 313 - if (e && e->type->ops.mq.get_rq_priv) { 318 + if (e && e->type->ops.mq.prepare_request) { 314 319 if (e->type->icq_cache && rq_ioc(bio)) 315 320 blk_mq_sched_assign_ioc(rq, bio); 316 321 317 - if (e->type->ops.mq.get_rq_priv(q, rq, bio)) { 318 - if (rq->elv.icq) 319 - put_io_context(rq->elv.icq->ioc); 320 - rq->elv.icq = NULL; 321 - } else { 322 - rq->rq_flags |= RQF_ELVPRIV; 323 - } 322 + e->type->ops.mq.prepare_request(rq, bio); 323 + rq->rq_flags |= RQF_ELVPRIV; 324 324 } 325 325 } 326 326 data->hctx->queued++; ··· 403 413 struct blk_mq_hw_ctx *hctx = blk_mq_map_queue(q, ctx->cpu); 404 414 const int sched_tag = rq->internal_tag; 405 415 406 - if (rq->rq_flags & (RQF_ELVPRIV | RQF_QUEUED)) { 416 + if (rq->rq_flags & RQF_ELVPRIV) { 407 417 if (e && e->type->ops.mq.finish_request) 408 418 e->type->ops.mq.finish_request(rq); 409 419 if (rq->elv.icq) {
+12 -13
block/kyber-iosched.c
··· 426 426 } 427 427 } 428 428 429 - static struct request *kyber_get_request(struct request_queue *q, 430 - unsigned int op, 431 - struct blk_mq_alloc_data *data) 429 + static void kyber_limit_depth(unsigned int op, struct blk_mq_alloc_data *data) 432 430 { 433 - struct kyber_queue_data *kqd = q->elevator->elevator_data; 434 - struct request *rq; 435 - 436 431 /* 437 432 * We use the scheduler tags as per-hardware queue queueing tokens. 438 433 * Async requests can be limited at this stage. 439 434 */ 440 - if (!op_is_sync(op)) 441 - data->shallow_depth = kqd->async_depth; 435 + if (!op_is_sync(op)) { 436 + struct kyber_queue_data *kqd = data->q->elevator->elevator_data; 442 437 443 - rq = __blk_mq_alloc_request(data, op); 444 - if (rq) 445 - rq_set_domain_token(rq, -1); 446 - return rq; 438 + data->shallow_depth = kqd->async_depth; 439 + } 440 + } 441 + 442 + static void kyber_prepare_request(struct request *rq, struct bio *bio) 443 + { 444 + rq_set_domain_token(rq, -1); 447 445 } 448 446 449 447 static void kyber_finish_request(struct request *rq) ··· 811 813 .exit_sched = kyber_exit_sched, 812 814 .init_hctx = kyber_init_hctx, 813 815 .exit_hctx = kyber_exit_hctx, 814 - .get_request = kyber_get_request, 816 + .limit_depth = kyber_limit_depth, 817 + .prepare_request = kyber_prepare_request, 815 818 .finish_request = kyber_finish_request, 816 819 .completed_request = kyber_completed_request, 817 820 .dispatch_request = kyber_dispatch_request,
+2 -2
include/linux/elevator.h
··· 104 104 int (*request_merge)(struct request_queue *q, struct request **, struct bio *); 105 105 void (*request_merged)(struct request_queue *, struct request *, enum elv_merge); 106 106 void (*requests_merged)(struct request_queue *, struct request *, struct request *); 107 - struct request *(*get_request)(struct request_queue *, unsigned int, struct blk_mq_alloc_data *); 107 + void (*limit_depth)(unsigned int, struct blk_mq_alloc_data *); 108 + void (*prepare_request)(struct request *, struct bio *bio); 108 109 void (*finish_request)(struct request *); 109 110 void (*insert_requests)(struct blk_mq_hw_ctx *, struct list_head *, bool); 110 111 struct request *(*dispatch_request)(struct blk_mq_hw_ctx *); ··· 115 114 void (*requeue_request)(struct request *); 116 115 struct request *(*former_request)(struct request_queue *, struct request *); 117 116 struct request *(*next_request)(struct request_queue *, struct request *); 118 - int (*get_rq_priv)(struct request_queue *, struct request *, struct bio *); 119 117 void (*init_icq)(struct io_cq *); 120 118 void (*exit_icq)(struct io_cq *); 121 119 };