From: Christoph Hellwig <hch@lst.de>
To: Ming Lei <ming.lei@redhat.com>
Cc: "Jens Axboe" <axboe@kernel.dk>,
linux-block@vger.kernel.org, "Nilay Shroff" <nilay@linux.ibm.com>,
"Shinichiro Kawasaki" <shinichiro.kawasaki@wdc.com>,
"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
"Christoph Hellwig" <hch@lst.de>
Subject: Re: [PATCH V3 09/20] block: simplify elevator reattachment for updating nr_hw_queues
Date: Fri, 25 Apr 2025 20:12:27 +0200 [thread overview]
Message-ID: <20250425181227.GA25925@lst.de> (raw)
In-Reply-To: <20250424152148.1066220-10-ming.lei@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 448 bytes --]
On Thu, Apr 24, 2025 at 11:21:32PM +0800, Ming Lei wrote:
> +static int __elevator_change(struct request_queue *q,
> + const char *elevator_name)
There's still not good reason for this helper.
I'd suggest you add the two first attached patches before this one
(it'll need a bi of reabsing as all of them are after your entire
sweries right now) and then fold the third one into this, which will
give us less code and a cleaner interface.
[-- Attachment #2: 0001-block-look-up-the-elevator-type-in-elevator_switch.patch --]
[-- Type: text/x-patch, Size: 2036 bytes --]
From 44da16a97ef758d1d9fe7c54c8360388f585d0c5 Mon Sep 17 00:00:00 2001
From: Christoph Hellwig <hch@lst.de>
Date: Fri, 25 Apr 2025 07:01:39 -0700
Subject: block: look up the elevator type in elevator_switch
That makes the function nicely self-contained and can be used
to avoid code duplication.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/elevator.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/block/elevator.c b/block/elevator.c
index a637426da56d..773b8931d874 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -591,14 +591,18 @@ static bool use_default_elevator(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.
*/
-static int elevator_switch(struct request_queue *q, struct elevator_type *new_e,
- struct elv_change_ctx *ctx)
+static int elevator_switch(struct request_queue *q, struct elv_change_ctx *ctx)
{
+ struct elevator_type *new_e;
int ret;
WARN_ON_ONCE(q->mq_freeze_depth == 0);
lockdep_assert_held(&q->elevator_lock);
+ new_e = elevator_find_get(ctx->name);
+ if (!new_e)
+ return -EINVAL;
+
blk_mq_quiesce_queue(q);
if (q->elevator) {
@@ -621,6 +625,7 @@ static int elevator_switch(struct request_queue *q, struct elevator_type *new_e,
new_e->elevator_name);
}
+ elevator_put(new_e);
return ret;
}
@@ -686,8 +691,6 @@ static int __elevator_change(struct request_queue *q,
struct elv_change_ctx *ctx)
{
const char *elevator_name = ctx->name;
- struct elevator_type *e;
- int ret;
lockdep_assert_held(&q->tag_set->update_nr_hwq_sema);
@@ -701,12 +704,7 @@ static int __elevator_change(struct request_queue *q,
return 0;
}
- e = elevator_find_get(elevator_name);
- if (!e)
- return -EINVAL;
- ret = elevator_switch(q, e, ctx);
- elevator_put(e);
- return ret;
+ return elevator_switch(q, ctx);
}
static int elevator_change(struct request_queue *q,
--
2.47.2
[-- Attachment #3: 0002-block-fold-elevator_disable-into-elevator_switch.patch --]
[-- Type: text/x-patch, Size: 3109 bytes --]
From 1bfce1a308b9e46734ed56196b4e9fe31b5a0036 Mon Sep 17 00:00:00 2001
From: Christoph Hellwig <hch@lst.de>
Date: Fri, 25 Apr 2025 07:10:35 -0700
Subject: block: fold elevator_disable into elevator_switch
This removes duplicate code, and keeps the callers tidy.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/elevator.c | 59 ++++++++++++++++--------------------------------
1 file changed, 20 insertions(+), 39 deletions(-)
diff --git a/block/elevator.c b/block/elevator.c
index 773b8931d874..59ff0abde920 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -593,15 +593,17 @@ static bool use_default_elevator(struct request_queue *q)
*/
static int elevator_switch(struct request_queue *q, struct elv_change_ctx *ctx)
{
- struct elevator_type *new_e;
- int ret;
+ struct elevator_type *new_e = NULL;
+ int ret = 0;
WARN_ON_ONCE(q->mq_freeze_depth == 0);
lockdep_assert_held(&q->elevator_lock);
- new_e = elevator_find_get(ctx->name);
- if (!new_e)
- return -EINVAL;
+ if (strncmp(ctx->name, "none", 4)) {
+ new_e = elevator_find_get(ctx->name);
+ if (!new_e)
+ return -EINVAL;
+ }
blk_mq_quiesce_queue(q);
@@ -610,12 +612,17 @@ static int elevator_switch(struct request_queue *q, struct elv_change_ctx *ctx)
__elevator_exit(q);
}
- ret = blk_mq_init_sched(q, new_e);
- if (ret)
- goto out_unfreeze;
-
- ctx->new = q->elevator;
- blk_add_trace_msg(q, "elv switch: %s", new_e->elevator_name);
+ if (new_e) {
+ ret = blk_mq_init_sched(q, new_e);
+ if (ret)
+ goto out_unfreeze;
+ ctx->new = q->elevator;
+ } else {
+ blk_queue_flag_clear(QUEUE_FLAG_SQ_SCHED, q);
+ q->elevator = NULL;
+ q->nr_requests = q->tag_set->queue_depth;
+ }
+ blk_add_trace_msg(q, "elv switch: %s", ctx->name);
out_unfreeze:
blk_mq_unquiesce_queue(q);
@@ -625,28 +632,11 @@ static int elevator_switch(struct request_queue *q, struct elv_change_ctx *ctx)
new_e->elevator_name);
}
- elevator_put(new_e);
+ if (new_e)
+ elevator_put(new_e);
return ret;
}
-static void elevator_disable(struct request_queue *q,
- struct elv_change_ctx *ctx)
-{
- WARN_ON_ONCE(q->mq_freeze_depth == 0);
- lockdep_assert_held(&q->elevator_lock);
-
- blk_mq_quiesce_queue(q);
-
- ctx->old = q->elevator;
- __elevator_exit(q);
- blk_queue_flag_clear(QUEUE_FLAG_SQ_SCHED, q);
- q->elevator = NULL;
- q->nr_requests = q->tag_set->queue_depth;
- blk_add_trace_msg(q, "elv switch: none");
-
- blk_mq_unquiesce_queue(q);
-}
-
static void elv_exit_and_release(struct request_queue *q)
{
struct elevator_queue *e;
@@ -690,20 +680,11 @@ static int elevator_change_done(struct request_queue *q,
static int __elevator_change(struct request_queue *q,
struct elv_change_ctx *ctx)
{
- const char *elevator_name = ctx->name;
-
lockdep_assert_held(&q->tag_set->update_nr_hwq_sema);
/* Make sure queue is not in the middle of being removed */
if (!ctx->init && !blk_queue_registered(q))
return -ENOENT;
-
- if (!strncmp(elevator_name, "none", 4)) {
- if (q->elevator)
- elevator_disable(q, ctx);
- return 0;
- }
-
return elevator_switch(q, ctx);
}
--
2.47.2
[-- Attachment #4: 0003-block-remove-__elevator_change.patch --]
[-- Type: text/x-patch, Size: 2756 bytes --]
From dcda3f508e5f938cb27d4b743226ca4d8af75e28 Mon Sep 17 00:00:00 2001
From: Christoph Hellwig <hch@lst.de>
Date: Fri, 25 Apr 2025 07:18:42 -0700
Subject: block: remove __elevator_change
Not much of a point in sharing code between callers with very different
expectations.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/elevator.c | 45 ++++++++++++++++++++-------------------------
1 file changed, 20 insertions(+), 25 deletions(-)
diff --git a/block/elevator.c b/block/elevator.c
index 59ff0abde920..b358858387a0 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -674,25 +674,13 @@ static int elevator_change_done(struct request_queue *q,
return ret;
}
-/*
- * Switch this queue to the given IO scheduler.
- */
-static int __elevator_change(struct request_queue *q,
- struct elv_change_ctx *ctx)
-{
- lockdep_assert_held(&q->tag_set->update_nr_hwq_sema);
-
- /* Make sure queue is not in the middle of being removed */
- if (!ctx->init && !blk_queue_registered(q))
- return -ENOENT;
- return elevator_switch(q, ctx);
-}
-
static int elevator_change(struct request_queue *q,
struct elv_change_ctx *ctx)
{
unsigned int memflags;
- int ret = 0;
+ int ret;
+
+ lockdep_assert_held(&q->tag_set->update_nr_hwq_sema);
memflags = blk_mq_freeze_queue(q);
/*
@@ -706,14 +694,20 @@ static int elevator_change(struct request_queue *q,
*/
blk_mq_cancel_work_sync(q);
mutex_lock(&q->elevator_lock);
- if (!q->elevator || !elevator_match(q->elevator->type, ctx->name))
- ret = __elevator_change(q, ctx);
+ /* Make sure queue is not in the middle of being removed */
+ ret = -ENOENT;
+ if (!ctx->init && !blk_queue_registered(q))
+ goto out_unlock;
+ ret = 0;
+ if (q->elevator && elevator_match(q->elevator->type, ctx->name))
+ goto out_unlock;
+ ret = elevator_switch(q, ctx);
+out_unlock:
mutex_unlock(&q->elevator_lock);
blk_mq_unfreeze_queue(q, memflags);
- if (!ret)
- ret = elevator_change_done(q, ctx);
-
- return ret;
+ if (ret)
+ return ret;
+ return elevator_change_done(q, ctx);
}
/*
@@ -768,17 +762,18 @@ void elevator_set_none(struct request_queue *q)
void elv_update_nr_hw_queues(struct request_queue *q)
{
struct elv_change_ctx ctx = {
- .name = "none",
.uevent = true,
};
- int ret = -ENODEV;
+ int ret = -ENOENT;
+ lockdep_assert_held(&q->tag_set->update_nr_hwq_sema);
WARN_ON_ONCE(q->mq_freeze_depth == 0);
mutex_lock(&q->elevator_lock);
- if (q->elevator && !blk_queue_dying(q))
+ if (blk_queue_registered(q) && !blk_queue_dying(q) && q->elevator) {
ctx.name = q->elevator->type->elevator_name;
- ret = __elevator_change(q, &ctx);
+ ret = elevator_switch(q, &ctx);
+ }
mutex_unlock(&q->elevator_lock);
blk_mq_unfreeze_queue_nomemrestore(q);
--
2.47.2
next prev parent reply other threads:[~2025-04-25 18:12 UTC|newest]
Thread overview: 71+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-24 15:21 [PATCH V3 00/20] block: unify elevator changing and fix lockdep warning Ming Lei
2025-04-24 15:21 ` [PATCH V3 01/20] block: move blk_mq_add_queue_tag_set() after blk_mq_map_swqueue() Ming Lei
2025-04-24 15:21 ` [PATCH V3 02/20] block: move ELEVATOR_FLAG_DISABLE_WBT a request queue flag Ming Lei
2025-04-25 14:29 ` Christoph Hellwig
2025-04-24 15:21 ` [PATCH V3 03/20] block: don't call freeze queue in elevator_switch() and elevator_disable() Ming Lei
2025-04-25 14:29 ` Christoph Hellwig
2025-04-24 15:21 ` [PATCH V3 04/20] block: use q->elevator with ->elevator_lock held in elv_iosched_show() Ming Lei
2025-04-25 6:08 ` Hannes Reinecke
2025-04-25 10:53 ` Nilay Shroff
2025-04-25 14:29 ` Christoph Hellwig
2025-04-24 15:21 ` [PATCH V3 05/20] block: add two helpers for registering/un-registering sched debugfs Ming Lei
2025-04-24 15:21 ` [PATCH V3 06/20] block: move sched debugfs register into elvevator_register_queue Ming Lei
2025-04-24 15:21 ` [PATCH V3 07/20] block: prevent adding/deleting disk during updating nr_hw_queues Ming Lei
2025-04-25 6:33 ` Hannes Reinecke
2025-04-25 11:37 ` Nilay Shroff
2025-04-25 14:33 ` Christoph Hellwig
2025-04-25 16:46 ` kernel test robot
2025-04-24 15:21 ` [PATCH V3 08/20] block: don't allow to switch elevator if updating nr_hw_queues is in-progress Ming Lei
2025-04-25 6:33 ` Hannes Reinecke
2025-04-25 12:48 ` Nilay Shroff
2025-04-27 2:27 ` Ming Lei
2025-04-28 16:17 ` Nilay Shroff
2025-04-29 2:43 ` Ming Lei
2025-04-29 10:22 ` Nilay Shroff
2025-04-30 0:54 ` Ming Lei
2025-04-24 15:21 ` [PATCH V3 09/20] block: simplify elevator reattachment for updating nr_hw_queues Ming Lei
2025-04-25 6:34 ` Hannes Reinecke
2025-04-25 18:12 ` Christoph Hellwig [this message]
2025-04-29 9:51 ` Ming Lei
2025-04-24 15:21 ` [PATCH V3 10/20] block: move blk_unregister_queue() & device_del() after freeze wait Ming Lei
2025-04-25 6:35 ` Hannes Reinecke
2025-04-25 12:50 ` Nilay Shroff
2025-04-25 14:34 ` Christoph Hellwig
2025-04-28 11:51 ` Ming Lei
2025-04-24 15:21 ` [PATCH V3 11/20] block: move queue freezing & elevator_lock into elevator_change() Ming Lei
2025-04-25 6:36 ` Hannes Reinecke
2025-04-25 12:54 ` Nilay Shroff
2025-04-25 14:35 ` Christoph Hellwig
2025-04-24 15:21 ` [PATCH V3 12/20] block: add `struct elv_change_ctx` for unifying elevator change Ming Lei
2025-04-25 6:38 ` Hannes Reinecke
2025-04-25 18:23 ` Christoph Hellwig
2025-04-29 15:45 ` Ming Lei
2025-04-24 15:21 ` [PATCH V3 13/20] block: " Ming Lei
2025-04-25 6:39 ` Hannes Reinecke
2025-04-25 13:03 ` Nilay Shroff
2025-04-30 0:46 ` Ming Lei
2025-04-25 18:30 ` Christoph Hellwig
2025-04-24 15:21 ` [PATCH V3 14/20] block: pass elevator_queue to elv_register_queue & unregister_queue Ming Lei
2025-04-25 6:40 ` Hannes Reinecke
2025-04-24 15:21 ` [PATCH V3 15/20] block: fail to show/store elevator sysfs attribute if elevator is dying Ming Lei
2025-04-25 6:45 ` Hannes Reinecke
2025-04-25 18:36 ` Christoph Hellwig
2025-04-30 1:07 ` Ming Lei
2025-04-24 15:21 ` [PATCH V3 16/20] block: move elv_register[unregister]_queue out of elevator_lock Ming Lei
2025-04-25 6:46 ` Hannes Reinecke
2025-04-25 13:05 ` Nilay Shroff
2025-04-25 18:37 ` Christoph Hellwig
2025-04-24 15:21 ` [PATCH V3 17/20] block: move debugfs/sysfs register out of freezing queue Ming Lei
2025-04-25 6:47 ` Hannes Reinecke
2025-04-25 18:38 ` Christoph Hellwig
2025-04-28 11:28 ` Ming Lei
2025-04-24 15:21 ` [PATCH V3 18/20] block: remove several ->elevator_lock Ming Lei
2025-04-25 6:48 ` Hannes Reinecke
2025-04-25 18:38 ` Christoph Hellwig
2025-04-24 15:21 ` [PATCH V3 19/20] block: move hctx cpuhp add/del out of queue freezing Ming Lei
2025-04-25 6:49 ` Hannes Reinecke
2025-04-24 15:21 ` [PATCH V3 20/20] block: move wbt_enable_default() out of queue freezing from sched ->exit() Ming Lei
2025-04-25 13:10 ` Nilay Shroff
2025-04-29 10:59 ` Nilay Shroff
2025-04-29 12:00 ` [PATCH V3 00/20] block: unify elevator changing and fix lockdep warning Stefan Haberland
2025-04-29 12:11 ` Ming Lei
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250425181227.GA25925@lst.de \
--to=hch@lst.de \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=ming.lei@redhat.com \
--cc=nilay@linux.ibm.com \
--cc=shinichiro.kawasaki@wdc.com \
--cc=thomas.hellstrom@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.