* [PATCH v6 1/3] nvme-multipath: keep a large delayed_removal_secs from wrapping around
2026-11-20 1:25 [PATCH v6 0/3] nvme-multipath: requeue work fixes Qiliang Yuan
@ 2026-11-20 1:25 ` Qiliang Yuan
2026-11-20 17:35 ` Nilay Shroff
2026-11-20 1:25 ` [PATCH v6 2/3] nvme-multipath: apply delayed_removal_secs changes to a pending removal Qiliang Yuan
` (2 subsequent siblings)
3 siblings, 1 reply; 6+ messages in thread
From: Qiliang Yuan @ 2026-11-20 1:25 UTC (permalink / raw)
To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
Nilay Shroff, Hannes Reinecke
Cc: linux-nvme, linux-kernel, Qiliang Yuan
nvme_mpath_remove_disk() delays the removal of a namespace head that
lost its last path by delayed_removal_secs, which it converts to
jiffies as delayed_removal_secs * HZ.
delayed_removal_secs is an unsigned int, so the product is computed in
32 bits and wraps around for values above UINT_MAX / HZ. With HZ=1000,
4294968 seconds turns into a delay of 704 jiffies, and the head goes
away in under a second instead of after about 50 days.
Compute the delay in 64 bits and cap it at MAX_JIFFY_OFFSET.
With delayed_removal_secs set to 4294968 at HZ=1000, removing the last
path deletes the head after (mean of two runs, min-max in parentheses;
"> 10000" means it was still there 10 s later):
before (ms) after (ms)
858 (856-860) > 10000
Fixes: 62188639ec160 ("nvme-multipath: introduce delayed removal of the multipath head node")
Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
---
drivers/nvme/host/multipath.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index ae8059366b57d..9958d08cd3829 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -724,6 +724,15 @@ static void nvme_requeue_work(struct work_struct *work)
}
}
+/*
+ * Convert delayed_removal_secs to jiffies, capped at MAX_JIFFY_OFFSET so
+ * that a large value doesn't wrap around into a short delay.
+ */
+static unsigned long nvme_delayed_removal_jiffies(unsigned int secs)
+{
+ return min_t(u64, (u64)secs * HZ, MAX_JIFFY_OFFSET);
+}
+
static void nvme_remove_head(struct nvme_ns_head *head)
{
if (test_and_clear_bit(NVME_NSHEAD_DISK_LIVE, &head->flags)) {
@@ -1523,7 +1532,7 @@ void nvme_mpath_remove_disk(struct nvme_ns_head *head)
*/
if (head->delayed_removal_secs && try_module_get(THIS_MODULE)) {
mod_delayed_work(nvme_wq, &head->remove_work,
- head->delayed_removal_secs * HZ);
+ nvme_delayed_removal_jiffies(head->delayed_removal_secs));
} else {
list_del_init(&head->entry);
remove = true;
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v6 1/3] nvme-multipath: keep a large delayed_removal_secs from wrapping around
2026-11-20 1:25 ` [PATCH v6 1/3] nvme-multipath: keep a large delayed_removal_secs from wrapping around Qiliang Yuan
@ 2026-11-20 17:35 ` Nilay Shroff
0 siblings, 0 replies; 6+ messages in thread
From: Nilay Shroff @ 2026-11-20 17:35 UTC (permalink / raw)
To: Qiliang Yuan, Keith Busch, Jens Axboe, Christoph Hellwig,
Sagi Grimberg, Hannes Reinecke
Cc: linux-nvme, linux-kernel
On 11/20/26 6:55 AM, Qiliang Yuan wrote:
> nvme_mpath_remove_disk() delays the removal of a namespace head that
> lost its last path by delayed_removal_secs, which it converts to
> jiffies as delayed_removal_secs * HZ.
>
> delayed_removal_secs is an unsigned int, so the product is computed in
> 32 bits and wraps around for values above UINT_MAX / HZ. With HZ=1000,
> 4294968 seconds turns into a delay of 704 jiffies, and the head goes
> away in under a second instead of after about 50 days.
>
> Compute the delay in 64 bits and cap it at MAX_JIFFY_OFFSET.
>
> With delayed_removal_secs set to 4294968 at HZ=1000, removing the last
> path deletes the head after (mean of two runs, min-max in parentheses;
> "> 10000" means it was still there 10 s later):
>
> before (ms) after (ms)
> 858 (856-860) > 10000
>
> Fixes: 62188639ec160 ("nvme-multipath: introduce delayed removal of the multipath head node")
> Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
Looks good to me:
Reviewed-by: Nilay Shroff <nilay@linux.ibm.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v6 2/3] nvme-multipath: apply delayed_removal_secs changes to a pending removal
2026-11-20 1:25 [PATCH v6 0/3] nvme-multipath: requeue work fixes Qiliang Yuan
2026-11-20 1:25 ` [PATCH v6 1/3] nvme-multipath: keep a large delayed_removal_secs from wrapping around Qiliang Yuan
@ 2026-11-20 1:25 ` Qiliang Yuan
2026-11-20 1:25 ` [PATCH v6 3/3] nvme-multipath: don't wait for a grace period in nvme_mpath_set_live() Qiliang Yuan
2026-11-20 19:54 ` [PATCH v6 0/3] nvme-multipath: requeue work fixes Keith Busch
3 siblings, 0 replies; 6+ messages in thread
From: Qiliang Yuan @ 2026-11-20 1:25 UTC (permalink / raw)
To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
Nilay Shroff, Hannes Reinecke
Cc: linux-nvme, linux-kernel, Qiliang Yuan
With delayed_removal_secs set, removing the last path of a namespace
head doesn't delete the head right away. nvme_mpath_remove_disk()
queues remove_work with the configured delay, and bios submitted in the
meantime wait on head->requeue_list in case a path comes back.
A write to delayed_removal_secs only takes effect for removals that
start later. A removal that is already pending keeps the old delay, so
clearing the attribute leaves the queued bios waiting until that delay
expires instead of failing them, and lowering or raising it doesn't
move the pending removal either. When paths remain but none of them is
usable, for example because they are ANA inaccessible, nothing
resubmits the queued bios after the attribute is cleared at all.
Requeue a pending remove_work with the new delay when the attribute is
written, cancelling it first so that the module reference taken for it
carries over. Have nvme_init_ns_head() cancel the pending removal
before it drops subsys->lock rather than after, so that a write to the
attribute cannot requeue the removal once a path is back. When the
attribute is cleared, kick requeue_work, so that the queued bios fail
right away if there is still no usable path.
With delayed_removal_secs set and no path left, the attribute is
changed two seconds later and the head is removed after (mean of two
runs, min-max in parentheses):
delay (s) before (ms) after (ms) change
30 -> 0 26311 (26103-26518) 8.5 (8-9) -99.97%
30 -> 5 28281 (28037-28525) 5293 (5198-5388) -81%
10 -> 30 8110 (8097-8122) 30094 (30057-30130) +271%
A direct read queued before the 30 -> 0 write fails this long after
the write, with no path left and with the only path ANA inaccessible
("> 15000" means it was still queued 15 s later):
paths before (ms) after (ms) change
none 26261 (26071-26451) 4.5 (4-5) -99.98%
inaccessible > 15000 4.5 (4-5) < -99.97%
Fixes: 62188639ec160 ("nvme-multipath: introduce delayed removal of the multipath head node")
Suggested-by: Nilay Shroff <nilay@linux.ibm.com>
Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
Reviewed-by: Nilay Shroff <nilay@linux.ibm.com>
---
drivers/nvme/host/core.c | 7 +++++--
drivers/nvme/host/multipath.c | 11 +++++++++++
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index f4aa02869b790..48d432c5d7aeb 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -4231,12 +4231,15 @@ static int nvme_init_ns_head(struct nvme_ns *ns, struct nvme_ns_info *info)
list_add_tail_rcu(&ns->siblings, &head->list);
ns->head = head;
- mutex_unlock(&ctrl->subsys->lock);
-
#ifdef CONFIG_NVME_MULTIPATH
+ /*
+ * Cancel a pending head removal under subsys->lock, so that
+ * delayed_removal_secs_store() never requeues it once a path is back.
+ */
if (cancel_delayed_work(&head->remove_work))
module_put(THIS_MODULE);
#endif
+ mutex_unlock(&ctrl->subsys->lock);
return 0;
out_put_ns_head:
diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index 9958d08cd3829..df96933f49459 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -1251,6 +1251,13 @@ static ssize_t delayed_removal_secs_store(struct device *dev,
mutex_lock(&head->subsys->lock);
head->delayed_removal_secs = sec;
assign_bit(NVME_NSHEAD_QUEUE_IF_NO_PATH, &head->flags, sec);
+ /*
+ * Apply the new delay to a removal that is still pending. The module
+ * reference taken for it carries over to the requeued work.
+ */
+ if (cancel_delayed_work(&head->remove_work))
+ queue_delayed_work(nvme_wq, &head->remove_work,
+ nvme_delayed_removal_jiffies(sec));
mutex_unlock(&head->subsys->lock);
/*
* Ensure that update to NVME_NSHEAD_QUEUE_IF_NO_PATH is seen
@@ -1258,6 +1265,10 @@ static ssize_t delayed_removal_secs_store(struct device *dev,
*/
synchronize_srcu(&head->srcu);
+ /* Resubmit queued bios, so that they fail without a usable path */
+ if (!sec)
+ kblockd_schedule_work(&head->requeue_work);
+
return count;
}
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH v6 3/3] nvme-multipath: don't wait for a grace period in nvme_mpath_set_live()
2026-11-20 1:25 [PATCH v6 0/3] nvme-multipath: requeue work fixes Qiliang Yuan
2026-11-20 1:25 ` [PATCH v6 1/3] nvme-multipath: keep a large delayed_removal_secs from wrapping around Qiliang Yuan
2026-11-20 1:25 ` [PATCH v6 2/3] nvme-multipath: apply delayed_removal_secs changes to a pending removal Qiliang Yuan
@ 2026-11-20 1:25 ` Qiliang Yuan
2026-11-20 19:54 ` [PATCH v6 0/3] nvme-multipath: requeue work fixes Keith Busch
3 siblings, 0 replies; 6+ messages in thread
From: Qiliang Yuan @ 2026-11-20 1:25 UTC (permalink / raw)
To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
Nilay Shroff, Hannes Reinecke
Cc: linux-nvme, linux-kernel, Qiliang Yuan, Hannes Reinecke
When a path goes live, nvme_mpath_set_live() waits for an SRCU grace
period of the namespace head before kicking the requeue work, so that
bios which found no usable path are on the requeue list by the time it
runs.
The ANA work calls nvme_mpath_set_live() for every namespace that
becomes optimized or non-optimized, one after another, so an ANA change
waits for one grace period per namespace.
Start the grace period with start_poll_synchronize_srcu() instead and
have nvme_requeue_work() wait for it only if it has not completed yet.
Take the cookie under head->lock, so that concurrent callers store
their cookies in order and the requeue work never sees an older one.
The grace periods of all namespaces then run in parallel, and requeue
work kicked for other reasons finds the cookie completed and does not
wait.
Flipping an ANA group from inaccessible to optimized ten times on each
of two boots over nvme-tcp loopback, nvme_read_ana_log() takes (median,
min-max in parentheses):
namespaces before (ms) after (ms) change
256 52.0 (35.4-74.7) 8.7 (2.5-19.6) -83%
1024 154.3 (123.9-193.8) 43.1 (18.2-58.3) -72%
Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
Reviewed-by: Hannes Reinecke <hare@kernel.org>
Reviewed-by: Nilay Shroff <nilay@linux.ibm.com>
---
drivers/nvme/host/multipath.c | 15 ++++++++++++++-
drivers/nvme/host/nvme.h | 1 +
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index df96933f49459..ad9b3746ddba1 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -712,6 +712,11 @@ static void nvme_requeue_work(struct work_struct *work)
container_of(work, struct nvme_ns_head, requeue_work);
struct bio *bio, *next;
+ /* Let bios that found no usable path reach the requeue list first. */
+ if (!poll_state_synchronize_srcu(&head->srcu,
+ READ_ONCE(head->requeue_srcu_cookie)))
+ synchronize_srcu(&head->srcu);
+
spin_lock_irq(&head->requeue_lock);
next = bio_list_get(&head->requeue_list);
spin_unlock_irq(&head->requeue_lock);
@@ -776,6 +781,7 @@ int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl, struct nvme_ns_head *head)
mutex_init(&head->lock);
spin_lock_init(&head->requeue_lock);
INIT_WORK(&head->requeue_work, nvme_requeue_work);
+ head->requeue_srcu_cookie = get_completed_synchronize_srcu();
INIT_WORK(&head->partition_scan_work, nvme_partition_scan_work);
INIT_DELAYED_WORK(&head->remove_work, nvme_remove_head_work);
@@ -858,9 +864,16 @@ static void nvme_mpath_set_live(struct nvme_ns *ns)
__nvme_find_path(head, node);
srcu_read_unlock(&head->srcu, srcu_idx);
}
+ /*
+ * Have nvme_requeue_work() wait for the grace period instead of
+ * blocking here, so that namespaces going live together, e.g. on
+ * an ANA change, do not wait for one grace period each. Start it
+ * under head->lock so that the newest cookie is stored last.
+ */
+ WRITE_ONCE(head->requeue_srcu_cookie,
+ start_poll_synchronize_srcu(&head->srcu));
mutex_unlock(&head->lock);
- synchronize_srcu(&head->srcu);
nvme_mpath_revalidate_zones(head);
kblockd_schedule_work(&head->requeue_work);
}
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 8833a463f1c84..3fff9b394b1cd 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -587,6 +587,7 @@ struct nvme_ns_head {
__guarded_by(&requeue_lock);
spinlock_t requeue_lock;
struct work_struct requeue_work;
+ unsigned long requeue_srcu_cookie;
struct work_struct partition_scan_work;
struct mutex lock;
unsigned long flags;
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v6 0/3] nvme-multipath: requeue work fixes
2026-11-20 1:25 [PATCH v6 0/3] nvme-multipath: requeue work fixes Qiliang Yuan
` (2 preceding siblings ...)
2026-11-20 1:25 ` [PATCH v6 3/3] nvme-multipath: don't wait for a grace period in nvme_mpath_set_live() Qiliang Yuan
@ 2026-11-20 19:54 ` Keith Busch
3 siblings, 0 replies; 6+ messages in thread
From: Keith Busch @ 2026-11-20 19:54 UTC (permalink / raw)
To: Jens Axboe, Christoph Hellwig, Sagi Grimberg, Nilay Shroff,
Hannes Reinecke, Qiliang Yuan
Cc: linux-nvme, linux-kernel, Hannes Reinecke
On Thu, 19 Nov 2026 20:25:00 -0500, Qiliang Yuan wrote:
> Patch 1 keeps a large delayed_removal_secs from wrapping around into a
> short delay when it is converted to jiffies.
>
> Patch 2 applies a new delayed_removal_secs to a head removal that is
> already pending, so that clearing it fails the I/O queued without a
> usable path right away instead of when the old delay expires.
>
> [...]
Thanks, applied to nvme-7.4.
[1/3] nvme-multipath: keep a large delayed_removal_secs from wrapping around
commit: a280772ee0a8a1f2ac769be4d88a5c52ef5ed743
[2/3] nvme-multipath: apply delayed_removal_secs changes to a pending removal
commit: 536a72ea54f81ebdf56a2a0b31d7dc0fb2837c1d
[3/3] nvme-multipath: don't wait for a grace period in nvme_mpath_set_live()
commit: 3ca1ccf527aae210ecee2905062dd6da0934416a
--
Keith Busch <kbusch@kernel.org>
^ permalink raw reply [flat|nested] 6+ messages in thread