[PATCH v4 1/2] nvme-multipath: apply delayed_removal_secs changes to a pending removal
Nilay Shroff
nilay at linux.ibm.com
Wed Nov 18 10:05:27 PST 2026
On 11/18/26 9:09 PM, Qiliang Yuan wrote:
> 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.
>
> Requeue a pending remove_work with the new delay when the attribute is
> written. Cancel it first so that the module reference taken for it
> carries over, as nvme_init_ns_head() does when a path comes back. If a
> path is already back and nvme_init_ns_head() hasn't cancelled the work
> yet, drop that reference instead of requeueing the work.
>
> 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 26877 (26327-27426) 9 (8-10) -99.97%
> 30 -> 5 27987 (27464-28509) 5248 (5193-5302) -81%
> 10 -> 30 8152 (8095-8209) 30106 (30080-30132) +269%
>
> A direct read queued before the 30 -> 0 write fails after:
>
> before (ms) after (ms) change
> 26801 (26243-27358) 6 (4-8) -99.98%
>
> Fixes: 62188639ec160 ("nvme-multipath: introduce delayed removal of the multipath head node")
> Suggested-by: Nilay Shroff <nilay at linux.ibm.com>
> Signed-off-by: Qiliang Yuan <qiliang.yuan at linux.dev>
> ---
> drivers/nvme/host/multipath.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
> index ae8059366b57d..881d8a0145255 100644
> --- a/drivers/nvme/host/multipath.c
> +++ b/drivers/nvme/host/multipath.c
> @@ -1242,6 +1242,17 @@ 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. If a path
> + * came back and nvme_init_ns_head() hasn't cancelled the removal yet,
> + * cancel it here and drop the module reference it held.
> + */
> + if (cancel_delayed_work(&head->remove_work)) {
> + if (list_empty(&head->list))
> + queue_delayed_work(nvme_wq, &head->remove_work, sec * HZ);
> + else
> + module_put(THIS_MODULE);
> + }
> mutex_unlock(&head->subsys->lock);
> /*
> * Ensure that update to NVME_NSHEAD_QUEUE_IF_NO_PATH is seen
>
The above change works and fixes the race which sashiko reported.
However, I think moving the cancel_delayed_work() check in
nvme_init_ns_head() under head->subsys->lock is more intuitive.
With that change, delayed_removal_secs_store() can always requeue
successfully cancelled work:
if (cancel_delayed_work(&head->remove_work))
queue_delayed_work(nvme_wq, &head->remove_work, sec * HZ);
And nvme_init_ns_head() would then become:
mutex_lock(&ctrl->subsys->lock);
...
...
list_add_tail_rcu(&ns->siblings, &head->list);
ns->head = head;
#ifdef CONFIG_NVME_MULTIPATH
if (cancel_delayed_work(&head->remove_work))
module_put(THIS_MODULE);
#endif
mutex_unlock(&ctrl->subsys->lock);
This way, path addition and delayed-work cancellation are serialized
with updates to delayed_removal_secs_store() through head->subsys->lock.
Consequently, we can eliminate the list_empty() check and the
module_put() from delayed_removal_secs_store().
Thanks,
--Nilay
More information about the Linux-nvme
mailing list