nvmet: drop the extra RCU grace period in nvmet_ns_disable()
Subsystems (2)
PATCH v2 1/1 nvmet: drop the extra RCU grace period in nvmet_ns_disable()
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
---
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/[email protected]
--- drivers/nvme/target/core.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/nvme/target/core.c +7 -5
@@ -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,
Signature · 1 line
Qiliang Yuan <[email protected]>
Looks good:
Quoted 11 lines · Qiliang Yuan
nvmet_ns_disable()kills the namespace's percpu ref, waits insynchronize_rcu()for anyone looking the namespace up underrcu_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.
Quoted 2 lines
Drop
synchronize_rcu()and rely on the wait for the ref to cover the RCU readers as well.
Thanks, applied to nvme-7.4.