mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] nvmet: drop the extra RCU grace period in nvmet_ns_disable()
@ 2026-11-04  6:31 Qiliang Yuan
  2026-11-04  7:14 ` Christoph Hellwig
  2026-11-04 16:35 ` Keith Busch
  0 siblings, 2 replies; 3+ messages in thread
From: Qiliang Yuan @ 2026-11-04  6:31 UTC (permalink / raw)
  To: Christoph Hellwig, Sagi Grimberg, Chaitanya Kulkarni
  Cc: linux-nvme, linux-kernel, Qiliang Yuan

nvmet_ns_disable() kills the namespace's percpu ref, waits in
synchronize_rcu() for anyone looking the namespace up under
rcu_read_lock(), and then waits for the ref to drop to zero.

Killing a percpu ref that is still in percpu mode, as the namespace
ref always is until then, switches it to atomic mode from an RCU
callback, so the ref can't drop to zero before a grace period has
passed since the kill. synchronize_rcu() thus adds a second grace
period in a row, about 4 ms here, and disabling the namespaces of a
subsystem one by one takes about 9 ms each.

Drop synchronize_rcu() and rely on the wait for the ref to cover the
RCU readers as well.

Disabling 64 namespaces through configfs, median of 3 runs on each of
two boots per kernel:

  host connected  before          after
  none            588 / 590 ms    409 / 409 ms
  nvme-tcp        617 / 619 ms    542 / 511 ms

Signed-off-by: Qiliang Yuan <odys.yuan@gmail.com>
---
V1 -> V2:
- Note in the comment that this relies on the ref staying in percpu
  mode until the kill

v1: https://lore.kernel.org/r/20261103-bug-nvmet-ns-disable-rcu-v1-1-ff7ac5623923@gmail.com
---
 drivers/nvme/target/core.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index a8171b88035c5..50486fc3cde8b 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -669,13 +669,15 @@ void nvmet_ns_disable(struct nvmet_ns *ns)
 	/*
 	 * Now that we removed the namespaces from the lookup list, we
 	 * can kill the per_cpu ref and wait for any remaining references
-	 * to be dropped, as well as a RCU grace period for anyone only
-	 * using the namespace under rcu_read_lock().  Note that we can't
-	 * use call_rcu here as we need to ensure the namespaces have
-	 * been fully destroyed before unloading the module.
+	 * to be dropped.  Rely on that wait for anyone only using the
+	 * namespace under rcu_read_lock() too: the ref can't drop to zero
+	 * before an RCU grace period has passed since the kill.  This only
+	 * holds as long as nothing switches the ref to atomic mode before
+	 * the kill; bring back synchronize_rcu() here if that changes.
+	 * Note that we can't use call_rcu here as we need to ensure the
+	 * namespaces have been fully destroyed before unloading the module.
 	 */
 	percpu_ref_kill(&ns->ref);
-	synchronize_rcu();
 	wait_for_completion(&ns->disable_done);
 	percpu_ref_exit(&ns->ref);
 

---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261102-bug-nvmet-ns-disable-rcu-30ebdfe414ff

Best regards,
-- 
Qiliang Yuan <odys.yuan@gmail.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] nvmet: drop the extra RCU grace period in nvmet_ns_disable()
  2026-11-04  6:31 [PATCH v2] nvmet: drop the extra RCU grace period in nvmet_ns_disable() Qiliang Yuan
@ 2026-11-04  7:14 ` Christoph Hellwig
  2026-11-04 16:35 ` Keith Busch
  1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2026-11-04  7:14 UTC (permalink / raw)
  To: Qiliang Yuan
  Cc: Christoph Hellwig, Sagi Grimberg, Chaitanya Kulkarni, linux-nvme,
	linux-kernel

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] nvmet: drop the extra RCU grace period in nvmet_ns_disable()
  2026-11-04  6:31 [PATCH v2] nvmet: drop the extra RCU grace period in nvmet_ns_disable() Qiliang Yuan
  2026-11-04  7:14 ` Christoph Hellwig
@ 2026-11-04 16:35 ` Keith Busch
  1 sibling, 0 replies; 3+ messages in thread
From: Keith Busch @ 2026-11-04 16:35 UTC (permalink / raw)
  To: Qiliang Yuan
  Cc: Christoph Hellwig, Sagi Grimberg, Chaitanya Kulkarni, linux-nvme,
	linux-kernel

On Wed, Nov 04, 2026 at 01:31:28AM -0500, Qiliang Yuan wrote:
> nvmet_ns_disable() kills the namespace's percpu ref, waits in
> synchronize_rcu() for anyone looking the namespace up under
> rcu_read_lock(), and then waits for the ref to drop to zero.
> 
> Killing a percpu ref that is still in percpu mode, as the namespace
> ref always is until then, switches it to atomic mode from an RCU
> callback, so the ref can't drop to zero before a grace period has
> passed since the kill. synchronize_rcu() thus adds a second grace
> period in a row, about 4 ms here, and disabling the namespaces of a
> subsystem one by one takes about 9 ms each.
> 
> Drop synchronize_rcu() and rely on the wait for the ref to cover the
> RCU readers as well.

Thanks, applied to nvme-7.4.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-04 16:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-04  6:31 [PATCH v2] nvmet: drop the extra RCU grace period in nvmet_ns_disable() Qiliang Yuan
2026-11-04  7:14 ` Christoph Hellwig
2026-11-04 16:35 ` Keith Busch

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®