From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pd0-f175.google.com (mail-pd0-f175.google.com [209.85.192.175]) by dpdk.org (Postfix) with ESMTP id 2B0DBB0B9 for ; Tue, 24 Jun 2014 17:49:33 +0200 (CEST) Received: by mail-pd0-f175.google.com with SMTP id v10so399841pde.34 for ; Tue, 24 Jun 2014 08:49:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:subject:message-id:importance :mime-version:content-type:content-transfer-encoding; bh=K7IEG6McTgSLKoPeMjaVfdAuaiXyEJvWhHz7RYGZnJw=; b=hLiuORJ3CStfyA/OxzLWEabx3FeYjDOhJRbKUQ4eLnTGgrlcVpi800bmoCNvePlBIb pd36WJk6a0RdDoCv54Xjsnkr+L2ERN6kT3jxt6t78Ye7pKBBaENLypRUsVsY+CEHjU/i sUEmUPoy4FrL/EBeAoYH+zidaRUh9siI6MBOs4SdeL7a5Uw+AFkNGqDWy48LgswGRZMw gth+mKOfN63MlSgYvq/dLTt/2i5E8V1yoC5y8U1V53rGFV5iNXwlCoTWhJd94ej0yWgZ bYb6clrvTWeYaGFdByGGnzB3bv6GYo1w1jbTfS98V98Zup03+eyctmCK5kiPgEQ6NLym cvzA== X-Gm-Message-State: ALoCoQnYxFYVXF/HCFciUObgfbgYrVErohL6fpjGUwpJSsjBbxbOCha9BXYMyMSL6Py3IKWrx2Eq X-Received: by 10.68.189.137 with SMTP id gi9mr2625926pbc.79.1403624990967; Tue, 24 Jun 2014 08:49:50 -0700 (PDT) Received: from nehalam.linuxnetplumber.net (static-50-53-83-51.bvtn.or.frontiernet.net. [50.53.83.51]) by mx.google.com with ESMTPSA id g6sm3212884pat.2.2014.06.24.08.49.50 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 24 Jun 2014 08:49:50 -0700 (PDT) Date: Tue, 24 Jun 2014 08:49:48 -0700 From: Stephen Hemminger To: "dev@dpdk.org" Message-ID: <20140624084948.6d4ab3cd@nehalam.linuxnetplumber.net> X-Mailer: Claws Mail 3.9.3 (GTK+ 2.24.23; x86_64-pc-linux-gnu) Importance: high X-Priority: 1 (Highest) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: [dpdk-dev] [PATCH] mempool: don't leak ring on failure X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Jun 2014 15:49:33 -0000 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 --- 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));