Skip to contentSkip to conversation

nvmet-rdma: Avoid o(n^2) loop in delete_ctrl

PATCH In review Sagi Grimberg 3 participants 3 messages May 7, 2024

Subsystems (2)
lore
Share & tools
lore

Sagi Grimberg

author maintainer
#0 lore raw

PATCH v2 1/1 nvmet-rdma: Avoid o(n^2) loop in delete_ctrl

From: Sagi Grimberg <[email protected]>

When deleting a nvmet-rdma ctrl, we essentially loop over all queues that belong to the controller and schedule a removal of each. Instead of restarting the loop every time a queue is found, do a simple safe list traversal.

This addresses an unneeded time spent scheduling queue removal in cases there a lot of queues.

---
Changes from v1:
- address exceed 80 characters

 drivers/nvme/target/rdma.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)
drivers/nvme/target/rdma.c +6 -10
index 5b8c63e74639..955296ac377f 100644
@@ -1814,18 +1814,14 @@ static int nvmet_rdma_cm_handler(struct rdma_cm_id *cm_id,
 
 static void nvmet_rdma_delete_ctrl(struct nvmet_ctrl *ctrl)
 {
-	struct nvmet_rdma_queue *queue;
+	struct nvmet_rdma_queue *queue, *n;
 
-restart:
 	mutex_lock(&nvmet_rdma_queue_mutex);
-	list_for_each_entry(queue, &nvmet_rdma_queue_list, queue_list) {
-		if (queue->nvme_sq.ctrl == ctrl) {
-			list_del_init(&queue->queue_list);
-			mutex_unlock(&nvmet_rdma_queue_mutex);
-
-			__nvmet_rdma_queue_disconnect(queue);
-			goto restart;
-		}
+	list_for_each_entry_safe(queue, n, &nvmet_rdma_queue_list, queue_list) {
+		if (queue->nvme_sq.ctrl != ctrl)
+			continue;
+		list_del_init(&queue->queue_list);
+		__nvmet_rdma_queue_disconnect(queue);
 	}
 	mutex_unlock(&nvmet_rdma_queue_mutex);
 }
Signature · 1 line
2.40.1
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 9 lines · Sagi Grimberg

From: Sagi Grimberg <[email protected]>

When deleting a nvmet-rdma ctrl, we essentially loop over all queues that belong to the controller and schedule a removal of each. Instead of restarting the loop every time a queue is found, do a simple safe list traversal.

This addresses an unneeded time spent scheduling queue removal in cases there a lot of queues.

Looks good:

(crossing fingers we're not going to run into a mess due to rdma_disconnect)

maintainer
#2 lore raw
Quoted 11 lines · Christoph Hellwig
Quoted 9 lines · Sagi Grimberg

From: Sagi Grimberg <[email protected]>

When deleting a nvmet-rdma ctrl, we essentially loop over all queues that belong to the controller and schedule a removal of each. Instead of restarting the loop every time a queue is found, do a simple safe list traversal.

This addresses an unneeded time spent scheduling queue removal in cases there a lot of queues.

Quoted 6 lines

Looks good:

(crossing fingers we're not going to run into a mess due to rdma_disconnect)

Sounds like nvme-6.10 material then. Applied to that tree.