[ofa-general] [PATCH for-2.6.22] IB/cm: improve local id allocation

Michael S. Tsirkin mst at dev.mellanox.co.il
Mon May 21 05:06:33 PDT 2007


IB/cm uses idr for local id allocations, with a running counter
as start_id. This fails to generate distinct ids in the scenario where
1. An id is constantly created and destroyed
2. A chunk of ids just beyond the current next_id value is occupied

This in turn leads to an increased chance of connection request being mis-detected
as a duplicate, sometimes for several retries, until next_id gets past
the block of allocated ids. This has been observed in practice.

As a fix, remember the last id allocated and start immediately above it.

Signed-off-by: Michael S. Tsirkin <mst at dev.mellanox.co.il>

---

BTW, cast to unsigned here is to prevent integer overflow and make language
lawyers happy.

Sean, can you ack this pls?

diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
index d446998..9032cd3 100644
--- a/drivers/infiniband/core/cm.c
+++ b/drivers/infiniband/core/cm.c
@@ -308,7 +308,9 @@ static int cm_alloc_id(struct cm_id_private *cm_id_priv)
 	do {
 		spin_lock_irqsave(&cm.lock, flags);
 		ret = idr_get_new_above(&cm.local_id_table, cm_id_priv,
-					next_id++, &id);
+					next_id, &id);
+		if (!ret)
+			next_id = (unsigned)id + 1;
 		spin_unlock_irqrestore(&cm.lock, flags);
 	} while( (ret == -EAGAIN) && idr_pre_get(&cm.local_id_table, GFP_KERNEL) );
 


-- 
MST



More information about the general mailing list