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

Configure Feed

Select the types of activity you want to include in your feed.

block: move elevator tags into struct elevator_resources

This patch introduces a new structure, struct elevator_resources, to
group together all elevator-related resources that share the same
lifetime. As a first step, this change moves the elevator tag pointer
from struct elv_change_ctx into the new struct elevator_resources.

Additionally, rename blk_mq_alloc_sched_tags_batch() and
blk_mq_free_sched_tags_batch() to blk_mq_alloc_sched_res_batch() and
blk_mq_free_sched_res_batch(), respectively. Introduce two new wrapper
helpers, blk_mq_alloc_sched_res() and blk_mq_free_sched_res(), around
blk_mq_alloc_sched_tags() and blk_mq_free_sched_tags().

These changes pave the way for consolidating the allocation and freeing
of elevator-specific resources into common helper functions. This
refactoring improves encapsulation and prepares the code for future
extensions, allowing additional elevator-specific data to be added to
struct elevator_resources without cluttering struct elv_change_ctx.

Subsequent patches will extend struct elevator_resources to include
other elevator-related data.

Reviewed-by: Ming Lei <ming.lei@redhat.com>
Reviewed-by: Yu Kuai <yukuai@fnnas.com>
Signed-off-by: Nilay Shroff <nilay@linux.ibm.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Nilay Shroff and committed by
Jens Axboe
04728ce9 232143b6

+64 -36
+33 -15
block/blk-mq-sched.c
··· 427 427 kfree(et); 428 428 } 429 429 430 - void blk_mq_free_sched_tags_batch(struct xarray *elv_tbl, 430 + void blk_mq_free_sched_res(struct elevator_resources *res, 431 + struct blk_mq_tag_set *set) 432 + { 433 + if (res->et) { 434 + blk_mq_free_sched_tags(res->et, set); 435 + res->et = NULL; 436 + } 437 + } 438 + 439 + void blk_mq_free_sched_res_batch(struct xarray *elv_tbl, 431 440 struct blk_mq_tag_set *set) 432 441 { 433 442 struct request_queue *q; ··· 454 445 */ 455 446 if (q->elevator) { 456 447 ctx = xa_load(elv_tbl, q->id); 457 - if (!ctx || !ctx->et) { 448 + if (!ctx) { 458 449 WARN_ON_ONCE(1); 459 450 continue; 460 451 } 461 - blk_mq_free_sched_tags(ctx->et, set); 462 - ctx->et = NULL; 452 + blk_mq_free_sched_res(&ctx->res, set); 463 453 } 464 454 } 465 455 } ··· 539 531 return NULL; 540 532 } 541 533 542 - int blk_mq_alloc_sched_tags_batch(struct xarray *elv_tbl, 534 + int blk_mq_alloc_sched_res(struct request_queue *q, 535 + struct elevator_resources *res, unsigned int nr_hw_queues) 536 + { 537 + struct blk_mq_tag_set *set = q->tag_set; 538 + 539 + res->et = blk_mq_alloc_sched_tags(set, nr_hw_queues, 540 + blk_mq_default_nr_requests(set)); 541 + if (!res->et) 542 + return -ENOMEM; 543 + 544 + return 0; 545 + } 546 + 547 + int blk_mq_alloc_sched_res_batch(struct xarray *elv_tbl, 543 548 struct blk_mq_tag_set *set, unsigned int nr_hw_queues) 544 549 { 545 550 struct elv_change_ctx *ctx; 546 551 struct request_queue *q; 547 - struct elevator_tags *et; 548 552 int ret = -ENOMEM; 549 553 550 554 lockdep_assert_held_write(&set->update_nr_hwq_lock); ··· 576 556 goto out_unwind; 577 557 } 578 558 579 - ctx->et = blk_mq_alloc_sched_tags(set, nr_hw_queues, 580 - blk_mq_default_nr_requests(set)); 581 - if (!ctx->et) 559 + ret = blk_mq_alloc_sched_res(q, &ctx->res, 560 + nr_hw_queues); 561 + if (ret) 582 562 goto out_unwind; 583 - 584 563 } 585 564 } 586 565 return 0; ··· 587 568 list_for_each_entry_continue_reverse(q, &set->tag_list, tag_set_list) { 588 569 if (q->elevator) { 589 570 ctx = xa_load(elv_tbl, q->id); 590 - if (ctx && ctx->et) { 591 - blk_mq_free_sched_tags(ctx->et, set); 592 - ctx->et = NULL; 593 - } 571 + if (ctx) 572 + blk_mq_free_sched_res(&ctx->res, set); 594 573 } 595 574 } 596 575 return ret; ··· 596 579 597 580 /* caller must have a reference to @e, will grab another one if successful */ 598 581 int blk_mq_init_sched(struct request_queue *q, struct elevator_type *e, 599 - struct elevator_tags *et) 582 + struct elevator_resources *res) 600 583 { 601 584 unsigned int flags = q->tag_set->flags; 585 + struct elevator_tags *et = res->et; 602 586 struct blk_mq_hw_ctx *hctx; 603 587 struct elevator_queue *eq; 604 588 unsigned long i;
+7 -3
block/blk-mq-sched.h
··· 19 19 void blk_mq_sched_dispatch_requests(struct blk_mq_hw_ctx *hctx); 20 20 21 21 int blk_mq_init_sched(struct request_queue *q, struct elevator_type *e, 22 - struct elevator_tags *et); 22 + struct elevator_resources *res); 23 23 void blk_mq_exit_sched(struct request_queue *q, struct elevator_queue *e); 24 24 void blk_mq_sched_free_rqs(struct request_queue *q); 25 25 26 26 struct elevator_tags *blk_mq_alloc_sched_tags(struct blk_mq_tag_set *set, 27 27 unsigned int nr_hw_queues, unsigned int nr_requests); 28 - int blk_mq_alloc_sched_tags_batch(struct xarray *et_table, 28 + int blk_mq_alloc_sched_res(struct request_queue *q, 29 + struct elevator_resources *res, unsigned int nr_hw_queues); 30 + int blk_mq_alloc_sched_res_batch(struct xarray *elv_tbl, 29 31 struct blk_mq_tag_set *set, unsigned int nr_hw_queues); 30 32 int blk_mq_alloc_sched_ctx_batch(struct xarray *elv_tbl, 31 33 struct blk_mq_tag_set *set); 32 34 void blk_mq_free_sched_ctx_batch(struct xarray *elv_tbl); 33 35 void blk_mq_free_sched_tags(struct elevator_tags *et, 34 36 struct blk_mq_tag_set *set); 35 - void blk_mq_free_sched_tags_batch(struct xarray *et_table, 37 + void blk_mq_free_sched_res(struct elevator_resources *res, 38 + struct blk_mq_tag_set *set); 39 + void blk_mq_free_sched_res_batch(struct xarray *et_table, 36 40 struct blk_mq_tag_set *set); 37 41 38 42 static inline void blk_mq_sched_restart(struct blk_mq_hw_ctx *hctx)
+1 -1
block/blk-mq.c
··· 5072 5072 if (blk_mq_alloc_sched_ctx_batch(&elv_tbl, set) < 0) 5073 5073 goto out_free_ctx; 5074 5074 5075 - if (blk_mq_alloc_sched_tags_batch(&elv_tbl, set, nr_hw_queues) < 0) 5075 + if (blk_mq_alloc_sched_res_batch(&elv_tbl, set, nr_hw_queues) < 0) 5076 5076 goto out_free_ctx; 5077 5077 5078 5078 list_for_each_entry(q, &set->tag_list, tag_set_list) {
+16 -15
block/elevator.c
··· 580 580 } 581 581 582 582 if (new_e) { 583 - ret = blk_mq_init_sched(q, new_e, ctx->et); 583 + ret = blk_mq_init_sched(q, new_e, &ctx->res); 584 584 if (ret) 585 585 goto out_unfreeze; 586 586 ctx->new = q->elevator; ··· 604 604 return ret; 605 605 } 606 606 607 - static void elv_exit_and_release(struct request_queue *q) 607 + static void elv_exit_and_release(struct elv_change_ctx *ctx, 608 + struct request_queue *q) 608 609 { 609 610 struct elevator_queue *e; 610 611 unsigned memflags; ··· 617 616 mutex_unlock(&q->elevator_lock); 618 617 blk_mq_unfreeze_queue(q, memflags); 619 618 if (e) { 620 - blk_mq_free_sched_tags(e->et, q->tag_set); 619 + blk_mq_free_sched_res(&ctx->res, q->tag_set); 621 620 kobject_put(&e->kobj); 622 621 } 623 622 } ··· 628 627 int ret = 0; 629 628 630 629 if (ctx->old) { 630 + struct elevator_resources res = {.et = ctx->old->et}; 631 631 bool enable_wbt = test_bit(ELEVATOR_FLAG_ENABLE_WBT_ON_EXIT, 632 632 &ctx->old->flags); 633 633 634 634 elv_unregister_queue(q, ctx->old); 635 - blk_mq_free_sched_tags(ctx->old->et, q->tag_set); 635 + blk_mq_free_sched_res(&res, q->tag_set); 636 636 kobject_put(&ctx->old->kobj); 637 637 if (enable_wbt) 638 638 wbt_enable_default(q->disk); ··· 641 639 if (ctx->new) { 642 640 ret = elv_register_queue(q, ctx->new, !ctx->no_uevent); 643 641 if (ret) 644 - elv_exit_and_release(q); 642 + elv_exit_and_release(ctx, q); 645 643 } 646 644 return ret; 647 645 } ··· 658 656 lockdep_assert_held(&set->update_nr_hwq_lock); 659 657 660 658 if (strncmp(ctx->name, "none", 4)) { 661 - ctx->et = blk_mq_alloc_sched_tags(set, set->nr_hw_queues, 662 - blk_mq_default_nr_requests(set)); 663 - if (!ctx->et) 664 - return -ENOMEM; 659 + ret = blk_mq_alloc_sched_res(q, &ctx->res, set->nr_hw_queues); 660 + if (ret) 661 + return ret; 665 662 } 666 663 667 664 memflags = blk_mq_freeze_queue(q); ··· 682 681 if (!ret) 683 682 ret = elevator_change_done(q, ctx); 684 683 /* 685 - * Free sched tags if it's allocated but we couldn't switch elevator. 684 + * Free sched resource if it's allocated but we couldn't switch elevator. 686 685 */ 687 - if (ctx->et && !ctx->new) 688 - blk_mq_free_sched_tags(ctx->et, set); 686 + if (!ctx->new) 687 + blk_mq_free_sched_res(&ctx->res, set); 689 688 690 689 return ret; 691 690 } ··· 712 711 if (!ret) 713 712 WARN_ON_ONCE(elevator_change_done(q, ctx)); 714 713 /* 715 - * Free sched tags if it's allocated but we couldn't switch elevator. 714 + * Free sched resource if it's allocated but we couldn't switch elevator. 716 715 */ 717 - if (ctx->et && !ctx->new) 718 - blk_mq_free_sched_tags(ctx->et, set); 716 + if (!ctx->new) 717 + blk_mq_free_sched_res(&ctx->res, set); 719 718 } 720 719 721 720 /*
+7 -2
block/elevator.h
··· 32 32 struct blk_mq_tags *tags[]; 33 33 }; 34 34 35 + struct elevator_resources { 36 + /* holds elevator tags */ 37 + struct elevator_tags *et; 38 + }; 39 + 35 40 /* Holding context data for changing elevator */ 36 41 struct elv_change_ctx { 37 42 const char *name; ··· 48 43 struct elevator_queue *new; 49 44 /* store elevator type */ 50 45 struct elevator_type *type; 51 - /* holds sched tags data */ 52 - struct elevator_tags *et; 46 + /* store elevator resources */ 47 + struct elevator_resources res; 53 48 }; 54 49 55 50 struct elevator_mq_ops {