[dpdk-dev] [PATCH] mempool: don't leak ring on failure

Stephen Hemminger stephen at networkplumber.org
Tue Jun 24 17:49:48 CEST 2014


If mempool can not be created because of insufficient memory
it returns an error but has already created a ring (and leaves it
behind). This prevents code from trying one mempool size and then
retrying with a smaller size if the bigger size fails.

Reordering to do ring creation after getting memory fixes
the problem.

Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>


--- a/lib/librte_mempool/rte_mempool.c	2014-06-24 08:20:28.513771717 -0700
+++ b/lib/librte_mempool/rte_mempool.c	2014-06-24 08:20:28.513771717 -0700
@@ -473,15 +473,6 @@ rte_mempool_xmem_create(const char *name
 
 	rte_rwlock_write_lock(RTE_EAL_MEMPOOL_RWLOCK);
 
-	/* allocate the ring that will be used to store objects */
-	/* Ring functions will return appropriate errors if we are
-	 * running as a secondary process etc., so no checks made
-	 * in this function for that condition */
-	rte_snprintf(rg_name, sizeof(rg_name), RTE_MEMPOOL_MZ_FORMAT, name);
-	r = rte_ring_create(rg_name, rte_align32pow2(n+1), socket_id, rg_flags);
-	if (r == NULL)
-		goto exit;
-
 	/*
 	 * reserve a memory zone for this mempool: private data is
 	 * cache-aligned
@@ -542,6 +533,15 @@ rte_mempool_xmem_create(const char *name
 		startaddr = (void*)addr;
 	}
 
+	/* allocate the ring that will be used to store objects */
+	/* Ring functions will return appropriate errors if we are
+	 * running as a secondary process etc., so no checks made
+	 * in this function for that condition */
+	rte_snprintf(rg_name, sizeof(rg_name), RTE_MEMPOOL_MZ_FORMAT, name);
+	r = rte_ring_create(rg_name, rte_align32pow2(n+1), socket_id, rg_flags);
+	if (r == NULL)
+		goto exit;
+
 	/* init the mempool structure */
 	mp = startaddr;
 	memset(mp, 0, sizeof(*mp));


More information about the dev mailing list