* Re: [PATCH v2] nvme: remove namespaces in parallel
2026-11-03 6:28 [PATCH v2] nvme: remove namespaces in parallel Qiliang Yuan
@ 2026-11-03 7:41 ` Nilay Shroff
2026-11-03 8:11 ` Christoph Hellwig
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Nilay Shroff @ 2026-11-03 7:41 UTC (permalink / raw)
To: Qiliang Yuan, Keith Busch, Jens Axboe, Christoph Hellwig,
Sagi Grimberg
Cc: linux-nvme, linux-kernel, linux-block, Hannes Reinecke, Ming Lei,
Shin'ichiro Kawasaki, Stuart Hayes
On 11/3/26 11:58 AM, Qiliang Yuan wrote:
> nvme_remove_namespaces() removes the namespaces of a controller one
> after another. Each removal waits for RCU grace periods in
> del_gendisk() for the namespace and for its multipath head, about
> 20 ms in all.
>
> Deleting a controller, such as disconnecting from a fabrics target,
> thus takes time proportional to its namespace count, over a second for
> 64 namespaces. Scanning had the same problem until commit 4e893ca81170
> ("nvme_core: scan namespaces asynchronously") made it add namespaces
> in parallel.
>
> Remove the namespaces through an async domain the same way, and wait
> for all of them before returning. Each removal still waits about
> 20 ms, but the waits now overlap: a grace period is system-wide, so
> removals that wait at the same time are released by the same grace
> periods instead of each needing its own.
>
> Disconnect time from a target on the same host, over tcp to 127.0.0.1
> and over nvme-loop, with 4 I/O queues, median of 3 runs on each of two
> boots per kernel:
>
> namespaces transport before after
> 8 tcp 170 / 171 ms 85 / 91 ms
> 32 tcp 628 / 628 ms 294 / 293 ms
> 64 tcp 1201 / 1308 ms 533 / 550 ms
> 64 loop 1988 / 1913 ms 1283 / 1200 ms
>
> Signed-off-by: Qiliang Yuan<odys.yuan@gmail.com>
Looks good to me:
Reviewed-by: Nilay Shroff <nilay@linux.ibm.com>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v2] nvme: remove namespaces in parallel
2026-11-03 6:28 [PATCH v2] nvme: remove namespaces in parallel Qiliang Yuan
2026-11-03 7:41 ` Nilay Shroff
@ 2026-11-03 8:11 ` Christoph Hellwig
2026-11-03 13:14 ` Hannes Reinecke
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Christoph Hellwig @ 2026-11-03 8:11 UTC (permalink / raw)
To: Qiliang Yuan
Cc: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
linux-nvme, linux-kernel, linux-block, Hannes Reinecke, Ming Lei,
Nilay Shroff, Shin'ichiro Kawasaki, Stuart Hayes
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v2] nvme: remove namespaces in parallel
2026-11-03 6:28 [PATCH v2] nvme: remove namespaces in parallel Qiliang Yuan
2026-11-03 7:41 ` Nilay Shroff
2026-11-03 8:11 ` Christoph Hellwig
@ 2026-11-03 13:14 ` Hannes Reinecke
2026-11-03 16:19 ` Daniel Wagner
2026-11-06 16:41 ` Keith Busch
4 siblings, 0 replies; 6+ messages in thread
From: Hannes Reinecke @ 2026-11-03 13:14 UTC (permalink / raw)
To: Qiliang Yuan, Keith Busch, Jens Axboe, Christoph Hellwig,
Sagi Grimberg
Cc: linux-nvme, linux-kernel, linux-block, Hannes Reinecke, Ming Lei,
Nilay Shroff, Shin'ichiro Kawasaki, Stuart Hayes
On 11/3/26 7:28 AM, Qiliang Yuan wrote:
> nvme_remove_namespaces() removes the namespaces of a controller one
> after another. Each removal waits for RCU grace periods in
> del_gendisk() for the namespace and for its multipath head, about
> 20 ms in all.
>
> Deleting a controller, such as disconnecting from a fabrics target,
> thus takes time proportional to its namespace count, over a second for
> 64 namespaces. Scanning had the same problem until commit 4e893ca81170
> ("nvme_core: scan namespaces asynchronously") made it add namespaces
> in parallel.
>
> Remove the namespaces through an async domain the same way, and wait
> for all of them before returning. Each removal still waits about
> 20 ms, but the waits now overlap: a grace period is system-wide, so
> removals that wait at the same time are released by the same grace
> periods instead of each needing its own.
>
> Disconnect time from a target on the same host, over tcp to 127.0.0.1
> and over nvme-loop, with 4 I/O queues, median of 3 runs on each of two
> boots per kernel:
>
> namespaces transport before after
> 8 tcp 170 / 171 ms 85 / 91 ms
> 32 tcp 628 / 628 ms 294 / 293 ms
> 64 tcp 1201 / 1308 ms 533 / 550 ms
> 64 loop 1988 / 1913 ms 1283 / 1200 ms
>
> Signed-off-by: Qiliang Yuan <odys.yuan@gmail.com>
> ---
> V1 -> V2:
> - Explain why removing the namespaces in parallel saves time
> - Drop patch 2 until the elevator switch locking change settles:
> https://lore.kernel.org/r/20261031044141.5569-1-laveeshb@laveeshbansal.com
>
> v1: https://lore.kernel.org/r/20261102-bug-nvme-remove-ns-async-v1-0-61780fee111c@gmail.com
> ---
> drivers/nvme/host/core.c | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
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* Re: [PATCH v2] nvme: remove namespaces in parallel
2026-11-03 6:28 [PATCH v2] nvme: remove namespaces in parallel Qiliang Yuan
` (2 preceding siblings ...)
2026-11-03 13:14 ` Hannes Reinecke
@ 2026-11-03 16:19 ` Daniel Wagner
2026-11-06 16:41 ` Keith Busch
4 siblings, 0 replies; 6+ messages in thread
From: Daniel Wagner @ 2026-11-03 16:19 UTC (permalink / raw)
To: Qiliang Yuan
Cc: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
linux-nvme, linux-kernel, linux-block, Hannes Reinecke, Ming Lei,
Nilay Shroff, Shin'ichiro Kawasaki, Stuart Hayes
On Tue, Nov 03, 2026 at 01:28:02AM -0500, Qiliang Yuan wrote:
> +static void nvme_ns_remove_async(void *data, async_cookie_t cookie)
> +{
> + nvme_ns_remove(data);
> +}
> +
> /*
> * This function iterates the namespace list unlocked to allow recovery from
> * controller failure. It is up to the caller to ensure the namespace list is
> @@ -4725,6 +4730,7 @@ void nvme_remove_namespaces(struct nvme_ctrl *ctrl)
> {
> struct nvme_ns *ns, *next;
> LIST_HEAD(ns_list);
> + ASYNC_DOMAIN(domain);
>
> /*
> * make sure to requeue I/O to all namespaces as these
> @@ -4759,8 +4765,13 @@ void nvme_remove_namespaces(struct nvme_ctrl *ctrl)
> mutex_unlock(&ctrl->namespaces_lock);
> synchronize_srcu(&ctrl->srcu);
>
> + /*
> + * Remove the namespaces in parallel, as each removal waits for several
> + * RCU grace periods.
> + */
> list_for_each_entry_safe(ns, next, &ns_list, list)
> - nvme_ns_remove(ns);
> + async_schedule_domain(nvme_ns_remove_async, ns, &domain);
> + async_synchronize_full_domain(&domain);
Nice!
Reviewed-by: Daniel Wagner <dwagner@suse.de>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v2] nvme: remove namespaces in parallel
2026-11-03 6:28 [PATCH v2] nvme: remove namespaces in parallel Qiliang Yuan
` (3 preceding siblings ...)
2026-11-03 16:19 ` Daniel Wagner
@ 2026-11-06 16:41 ` Keith Busch
4 siblings, 0 replies; 6+ messages in thread
From: Keith Busch @ 2026-11-06 16:41 UTC (permalink / raw)
To: axboe, hch, sagi, Qiliang Yuan
Cc: linux-nvme, linux-kernel, linux-block, hare, tom.leiming, nilay,
shinichiro.kawasaki, stuart.w.hayes
On Tue, 03 Nov 2026 01:28:02 -0500, Qiliang Yuan wrote:
> nvme_remove_namespaces() removes the namespaces of a controller one
> after another. Each removal waits for RCU grace periods in
> del_gendisk() for the namespace and for its multipath head, about
> 20 ms in all.
>
> Deleting a controller, such as disconnecting from a fabrics target,
> thus takes time proportional to its namespace count, over a second for
> 64 namespaces. Scanning had the same problem until commit 4e893ca81170
> ("nvme_core: scan namespaces asynchronously") made it add namespaces
> in parallel.
>
> [...]
Thanks, applied to nvme-7.4.
[1/1] nvme: remove namespaces in parallel
commit: fc991838ef25f1cab9ff34b55b39f16d95ed39b3
--
Keith Busch <kbusch@kernel.org>
^ permalink raw reply [flat|nested] 6+ messages in thread