diff options
| author | Ming Lei <ming.lei@redhat.com> | 2025-05-05 22:17:51 +0800 |
|---|---|---|
| committer | Jens Axboe <axboe@kernel.dk> | 2025-05-06 07:43:43 -0600 |
| commit | 596dce110b7d543db727e6957ae7adf35beb0633 (patch) | |
| tree | b5547489aa3c495bd1d613fdf351f2f4e0190013 /block/elevator.c | |
| parent | ac55b71a31a7287342e622c6f4de201e54b1c195 (diff) | |
block: simplify elevator reattachment for updating nr_hw_queues
In blk_mq_update_nr_hw_queues(), nr_hw_queues changes and elevator data
depends on it, and elevator has to be reattached, so call elevator_switch()
to force attachment.
Add elv_update_nr_hw_queues() simply for blk_mq_update_nr_hw_queues() to
reattach elevator, since elevator switch isn't likely when running
blk_mq_update_nr_hw_queues(). This way removes the current switch
none and switch back code.
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Nilay Shroff <nilay@linux.ibm.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20250505141805.2751237-14-ming.lei@redhat.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/elevator.c')
| -rw-r--r-- | block/elevator.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/block/elevator.c b/block/elevator.c index 4e58379c4d88..cabd7a8bb76c 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -621,7 +621,7 @@ void elevator_init_mq(struct request_queue *q) * If switching fails, we are most likely running out of memory and not able * to restore the old io scheduler, so leaving the io scheduler being none. */ -int elevator_switch(struct request_queue *q, const char *name) +static int elevator_switch(struct request_queue *q, const char *name) { struct elevator_type *new_e = NULL; int ret = 0; @@ -682,6 +682,24 @@ static int elevator_change(struct request_queue *q, const char *elevator_name) return elevator_switch(q, elevator_name); } +/* + * The I/O scheduler depends on the number of hardware queues, this forces a + * reattachment when nr_hw_queues changes. + */ +void elv_update_nr_hw_queues(struct request_queue *q) +{ + WARN_ON_ONCE(q->mq_freeze_depth == 0); + + mutex_lock(&q->elevator_lock); + if (q->elevator && !blk_queue_dying(q) && !blk_queue_registered(q)) { + const char *name = q->elevator->type->elevator_name; + + /* force to reattach elevator after nr_hw_queue is updated */ + elevator_switch(q, name); + } + mutex_unlock(&q->elevator_lock); +} + static void elv_iosched_load_module(char *elevator_name) { struct elevator_type *found; |
