[PATCH] nvmet: drop the extra RCU grace period in nvmet_ns_disable()
Qiliang Yuan
odys.yuan at gmail.com
Mon Nov 2 22:31:25 PST 2026
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 already 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 at gmail.com>
---
drivers/nvme/target/core.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index a8171b88035c5..8aca4b279bb9a 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -669,13 +669,13 @@ 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. 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 at gmail.com>
More information about the Linux-nvme
mailing list