* [PATCH v3 0/2] block: make changing to the current I/O scheduler cheap again
@ 2026-11-17 2:56 Qiliang Yuan
2026-11-17 2:56 ` [PATCH v3 1/2] block: don't request a module for the none elevator Qiliang Yuan
2026-11-17 2:56 ` [PATCH v3 2/2] block: return early when the elevator doesn't change Qiliang Yuan
0 siblings, 2 replies; 6+ messages in thread
From: Qiliang Yuan @ 2026-11-17 2:56 UTC (permalink / raw)
To: Jens Axboe, Damien Le Moal, Ming Lei, Nilay Shroff, Hannes Reinecke
Cc: linux-block, linux-kernel, Qiliang Yuan, Christoph Hellwig
Writing the scheduler a queue already uses to queue/scheduler takes
about 10 ms and freezes the queue, which stalls I/O on live disks every
time a udev rule or tuning tool sets the scheduler unconditionally.
Patch 1 stops requesting a "none-iosched" module on every write of
"none". Patch 2 returns before freezing the queue when the elevator
wouldn't change.
On a null_blk disk (median of 20 writes, all kernels measured in the
same run):
operation base (ms) patch 1 (ms) patch 1+2 (ms)
none -> none 13.10 9.11 0.08
mq-deadline -> mq-deadline 10.95 9.05 0.08
mq-deadline -> none 13.00 7.97 6.03
Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
---
V2 -> V3:
- Point Fixes in patch 2 at the commit that added the freeze, as
Christoph pointed out
- Add Christoph's Reviewed-by to patch 2
- Rebase onto v7.4-rc2-1025-g666539eecdf4
V1 -> V2:
- Keep the elevator check under the freeze and note the race in the
comment, as Christoph suggested
- Say "change" instead of "rewrite" in the cover letter subject
- Rebase onto v7.4-rc2-470-g7e1392a42ea2 and update the numbers from a
new run
v2: https://lore.kernel.org/r/20261114-bug-block-elevator-unchanged-v2-0-5a1fe7d72fa0@linux.dev
v1: https://lore.kernel.org/r/20261111-bug-block-elevator-unchanged-v1-0-583198bd4e21@linux.dev
---
Qiliang Yuan (2):
block: don't request a module for the none elevator
block: return early when the elevator doesn't change
block/elevator.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
---
base-commit: 666539eecdf4db623f5e3c3e55cf9f2dfad24aa4
change-id: 20261111-bug-block-elevator-unchanged-a6cd2d761d38
Best regards,
--
Qiliang Yuan <qiliang.yuan@linux.dev>
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH v3 1/2] block: don't request a module for the none elevator 2026-11-17 2:56 [PATCH v3 0/2] block: make changing to the current I/O scheduler cheap again Qiliang Yuan @ 2026-11-17 2:56 ` Qiliang Yuan 2026-11-17 15:19 ` Hannes Reinecke 2026-11-17 2:56 ` [PATCH v3 2/2] block: return early when the elevator doesn't change Qiliang Yuan 1 sibling, 1 reply; 6+ messages in thread From: Qiliang Yuan @ 2026-11-17 2:56 UTC (permalink / raw) To: Jens Axboe, Damien Le Moal, Ming Lei, Nilay Shroff, Hannes Reinecke Cc: linux-block, linux-kernel, Qiliang Yuan, Christoph Hellwig elv_iosched_store() calls elv_iosched_load_module() for the requested name before anything else, and loads "<name>-iosched" if no elevator type of that name is registered. "none" never is, so every write of "none" to queue/scheduler ends up in request_module("none-iosched"). That runs a modprobe helper which can never find the module, and adds several milliseconds to every switch to "none", including rewrites of it by udev rules or tuning tools that set the scheduler on each disk. Return early for "none", like elevator_change() did before the module loading moved into elv_iosched_load_module(). Writing queue/scheduler of a null_blk disk 20 times takes (median): operation before (ms) after (ms) change none -> none 13.10 9.11 -30% mq-deadline -> none 13.00 7.97 -39% Fixes: 734e1a8603128 ("block: Prevent deadlocks when switching elevators") Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Nilay Shroff <nilay@linux.ibm.com> --- block/elevator.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/block/elevator.c b/block/elevator.c index 66edf1a5768a8..9d9b2e84a1288 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -775,6 +775,9 @@ static void elv_iosched_load_module(const char *elevator_name) { struct elevator_type *found; + if (!strncmp(elevator_name, "none", 4)) + return; + spin_lock(&elv_list_lock); found = __elevator_find(elevator_name); spin_unlock(&elv_list_lock); -- 2.43.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3 1/2] block: don't request a module for the none elevator 2026-11-17 2:56 ` [PATCH v3 1/2] block: don't request a module for the none elevator Qiliang Yuan @ 2026-11-17 15:19 ` Hannes Reinecke 0 siblings, 0 replies; 6+ messages in thread From: Hannes Reinecke @ 2026-11-17 15:19 UTC (permalink / raw) To: Qiliang Yuan, Jens Axboe, Damien Le Moal, Ming Lei, Nilay Shroff Cc: linux-block, linux-kernel, Christoph Hellwig On 11/17/26 3:56 AM, Qiliang Yuan wrote: > elv_iosched_store() calls elv_iosched_load_module() for the requested > name before anything else, and loads "<name>-iosched" if no elevator > type of that name is registered. "none" never is, so every write of > "none" to queue/scheduler ends up in request_module("none-iosched"). > > That runs a modprobe helper which can never find the module, and adds > several milliseconds to every switch to "none", including rewrites of > it by udev rules or tuning tools that set the scheduler on each disk. > > Return early for "none", like elevator_change() did before the module > loading moved into elv_iosched_load_module(). > > Writing queue/scheduler of a null_blk disk 20 times takes (median): > > operation before (ms) after (ms) change > none -> none 13.10 9.11 -30% > mq-deadline -> none 13.00 7.97 -39% > > Fixes: 734e1a8603128 ("block: Prevent deadlocks when switching elevators") > Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev> > Reviewed-by: Christoph Hellwig <hch@lst.de> > Reviewed-by: Nilay Shroff <nilay@linux.ibm.com> > --- > block/elevator.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/block/elevator.c b/block/elevator.c > index 66edf1a5768a8..9d9b2e84a1288 100644 > --- a/block/elevator.c > +++ b/block/elevator.c > @@ -775,6 +775,9 @@ static void elv_iosched_load_module(const char *elevator_name) > { > struct elevator_type *found; > > + if (!strncmp(elevator_name, "none", 4)) > + return; > + > spin_lock(&elv_list_lock); > found = __elevator_find(elevator_name); > spin_unlock(&elv_list_lock); > Reviewed-by: Hannes Reinecke <hare@kernel.org> Cheers, Hannes -- Dr. Hannes Reinecke Kernel Storage Architect hare@suse.de +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v3 2/2] block: return early when the elevator doesn't change 2026-11-17 2:56 [PATCH v3 0/2] block: make changing to the current I/O scheduler cheap again Qiliang Yuan 2026-11-17 2:56 ` [PATCH v3 1/2] block: don't request a module for the none elevator Qiliang Yuan @ 2026-11-17 2:56 ` Qiliang Yuan 2026-11-17 14:54 ` Nilay Shroff 2026-11-17 15:20 ` Hannes Reinecke 1 sibling, 2 replies; 6+ messages in thread From: Qiliang Yuan @ 2026-11-17 2:56 UTC (permalink / raw) To: Jens Axboe, Damien Le Moal, Ming Lei, Nilay Shroff, Hannes Reinecke Cc: linux-block, linux-kernel, Qiliang Yuan, Christoph Hellwig Writing the scheduler a queue already uses to queue/scheduler used to be a no-op. elevator_change() now only checks for an unchanged elevator after freezing the queue, and doesn't treat "none" on a queue without an elevator as unchanged at all, so that case also quiesces the queue in elevator_switch() and resets nr_requests. Every such write therefore drains in-flight I/O and waits for an RCU grace period. udev rules and tuning tools that set the scheduler unconditionally stall I/O on live disks each time they run. Check under elevator_lock whether anything would change before allocating scheduler resources and freezing the queue. The check can race with another elevator change, which at worst leads to a redundant switch, so keep the one done under the freeze as well. Writing the current scheduler to queue/scheduler of a null_blk disk 20 times takes (median): operation before (ms) after (ms) change none -> none 9.11 0.08 -99% mq-deadline -> mq-deadline 9.05 0.08 -99% 4k random reads at queue depth 1 for 10 seconds, while "none" is written to queue/scheduler every 50 ms: metric before after change IOPS 340562 390392 +15% max latency (us) 16302 1224 -92% Fixes: af2814149883e ("block: freeze the queue in queue_attr_store") Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev> Reviewed-by: Christoph Hellwig <hch@lst.de> --- block/elevator.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/block/elevator.c b/block/elevator.c index 9d9b2e84a1288..549cf51543a8b 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -654,10 +654,24 @@ static int elevator_change(struct request_queue *q, struct elv_change_ctx *ctx) { unsigned int memflags; struct blk_mq_tag_set *set = q->tag_set; + bool unchanged; int ret = 0; lockdep_assert_held(&set->update_nr_hwq_lock); + /* + * Skip freezing the queue if nothing would change. This can race with + * another elevator change, which at worst leads to a redundant switch. + */ + mutex_lock(&q->elevator_lock); + if (q->elevator) + unchanged = elevator_match(q->elevator->type, ctx->name); + else + unchanged = !strncmp(ctx->name, "none", 4); + mutex_unlock(&q->elevator_lock); + if (unchanged) + return 0; + if (strncmp(ctx->name, "none", 4)) { ret = blk_mq_alloc_sched_res(q, ctx->type, &ctx->res, set->nr_hw_queues); -- 2.43.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3 2/2] block: return early when the elevator doesn't change 2026-11-17 2:56 ` [PATCH v3 2/2] block: return early when the elevator doesn't change Qiliang Yuan @ 2026-11-17 14:54 ` Nilay Shroff 2026-11-17 15:20 ` Hannes Reinecke 1 sibling, 0 replies; 6+ messages in thread From: Nilay Shroff @ 2026-11-17 14:54 UTC (permalink / raw) To: Qiliang Yuan, Jens Axboe, Damien Le Moal, Ming Lei, Hannes Reinecke Cc: linux-block, linux-kernel, Christoph Hellwig On 11/17/26 8:26 AM, Qiliang Yuan wrote: > Writing the scheduler a queue already uses to queue/scheduler used to > be a no-op. elevator_change() now only checks for an unchanged elevator > after freezing the queue, and doesn't treat "none" on a queue without > an elevator as unchanged at all, so that case also quiesces the queue > in elevator_switch() and resets nr_requests. > > Every such write therefore drains in-flight I/O and waits for an RCU > grace period. udev rules and tuning tools that set the scheduler > unconditionally stall I/O on live disks each time they run. > > Check under elevator_lock whether anything would change before > allocating scheduler resources and freezing the queue. The check can > race with another elevator change, which at worst leads to a redundant > switch, so keep the one done under the freeze as well. > > Writing the current scheduler to queue/scheduler of a null_blk disk 20 > times takes (median): > > operation before (ms) after (ms) change > none -> none 9.11 0.08 -99% > mq-deadline -> mq-deadline 9.05 0.08 -99% > > 4k random reads at queue depth 1 for 10 seconds, while "none" is > written to queue/scheduler every 50 ms: > > metric before after change > IOPS 340562 390392 +15% > max latency (us) 16302 1224 -92% > > Fixes: af2814149883e ("block: freeze the queue in queue_attr_store") > Signed-off-by: Qiliang Yuan<qiliang.yuan@linux.dev> > Reviewed-by: Christoph Hellwig<hch@lst.de> Looks good to me: Reviewed-by: Nilay Shroff <nilay@linux.ibm.com> ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3 2/2] block: return early when the elevator doesn't change 2026-11-17 2:56 ` [PATCH v3 2/2] block: return early when the elevator doesn't change Qiliang Yuan 2026-11-17 14:54 ` Nilay Shroff @ 2026-11-17 15:20 ` Hannes Reinecke 1 sibling, 0 replies; 6+ messages in thread From: Hannes Reinecke @ 2026-11-17 15:20 UTC (permalink / raw) To: Qiliang Yuan, Jens Axboe, Damien Le Moal, Ming Lei, Nilay Shroff Cc: linux-block, linux-kernel, Christoph Hellwig On 11/17/26 3:56 AM, Qiliang Yuan wrote: > Writing the scheduler a queue already uses to queue/scheduler used to > be a no-op. elevator_change() now only checks for an unchanged elevator > after freezing the queue, and doesn't treat "none" on a queue without > an elevator as unchanged at all, so that case also quiesces the queue > in elevator_switch() and resets nr_requests. > > Every such write therefore drains in-flight I/O and waits for an RCU > grace period. udev rules and tuning tools that set the scheduler > unconditionally stall I/O on live disks each time they run. > > Check under elevator_lock whether anything would change before > allocating scheduler resources and freezing the queue. The check can > race with another elevator change, which at worst leads to a redundant > switch, so keep the one done under the freeze as well. > > Writing the current scheduler to queue/scheduler of a null_blk disk 20 > times takes (median): > > operation before (ms) after (ms) change > none -> none 9.11 0.08 -99% > mq-deadline -> mq-deadline 9.05 0.08 -99% > > 4k random reads at queue depth 1 for 10 seconds, while "none" is > written to queue/scheduler every 50 ms: > > metric before after change > IOPS 340562 390392 +15% > max latency (us) 16302 1224 -92% > > Fixes: af2814149883e ("block: freeze the queue in queue_attr_store") > Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev> > Reviewed-by: Christoph Hellwig <hch@lst.de> > --- > block/elevator.c | 14 ++++++++++++++ > 1 file changed, 14 insertions(+) > > diff --git a/block/elevator.c b/block/elevator.c > index 9d9b2e84a1288..549cf51543a8b 100644 > --- a/block/elevator.c > +++ b/block/elevator.c > @@ -654,10 +654,24 @@ static int elevator_change(struct request_queue *q, struct elv_change_ctx *ctx) > { > unsigned int memflags; > struct blk_mq_tag_set *set = q->tag_set; > + bool unchanged; > int ret = 0; > > lockdep_assert_held(&set->update_nr_hwq_lock); > > + /* > + * Skip freezing the queue if nothing would change. This can race with > + * another elevator change, which at worst leads to a redundant switch. > + */ > + mutex_lock(&q->elevator_lock); > + if (q->elevator) > + unchanged = elevator_match(q->elevator->type, ctx->name); > + else > + unchanged = !strncmp(ctx->name, "none", 4); > + mutex_unlock(&q->elevator_lock); > + if (unchanged) > + return 0; > + > if (strncmp(ctx->name, "none", 4)) { > ret = blk_mq_alloc_sched_res(q, ctx->type, &ctx->res, > set->nr_hw_queues); > Reviewed-by: Hannes Reinecke <hare@kernel.org> Cheers, Hannes -- Dr. Hannes Reinecke Kernel Storage Architect hare@suse.de +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-17 15:20 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-11-17 2:56 [PATCH v3 0/2] block: make changing to the current I/O scheduler cheap again Qiliang Yuan 2026-11-17 2:56 ` [PATCH v3 1/2] block: don't request a module for the none elevator Qiliang Yuan 2026-11-17 15:19 ` Hannes Reinecke 2026-11-17 2:56 ` [PATCH v3 2/2] block: return early when the elevator doesn't change Qiliang Yuan 2026-11-17 14:54 ` Nilay Shroff 2026-11-17 15:20 ` Hannes Reinecke
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®