From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3536FA0542 for ; Tue, 14 Jul 2020 09:26:47 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 01B8D1D574; Tue, 14 Jul 2020 09:26:47 +0200 (CEST) Received: from m12-14.163.com (m12-14.163.com [220.181.12.14]) by dpdk.org (Postfix) with ESMTP id 521831D40F; Tue, 14 Jul 2020 09:26:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=T/5SE0xi8XdZPbuiSa 8n9cCOVXJr0508FKRuhaP5UIE=; b=VYmAOYzKRhoptIdtqwVeMV6Fo1cnzP7s18 ssheLztD2drVgPDqEQKSdY+UNmmkUudt/VNAAfTw0+xks+61z5sXENMqx38vaC2w y8j8ngq7tVLovsZ2yQfzST6lRPVZKIC0dzBeIlDICGIzjz7LjhhrpzsCcPrV4nlt BTpMJk3A4= Received: from localhost.localdomain (unknown [106.38.115.12]) by smtp10 (Coremail) with SMTP id DsCowABHn9sPXg1fUZSzAw--.40266S2; Tue, 14 Jul 2020 15:26:11 +0800 (CST) From: Zhike Wang To: dev@dpdk.org Cc: olivier.matz@6wind.com, arybchenko@solarflare.com, stable@dpdk.org, Zhike Wang Date: Tue, 14 Jul 2020 15:26:05 +0800 Message-Id: <1594711565-28309-1-git-send-email-wangzhike@jd.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1594611634-7730-1-git-send-email-wangzhike@jd.com> References: <1594611634-7730-1-git-send-email-wangzhike@jd.com> X-CM-TRANSID: DsCowABHn9sPXg1fUZSzAw--.40266S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Zr1kJF48KF4kur43Xw1xAFb_yoW8Xr18pr 43Gwn5tFnFqrWxArs7W3WrWa48G3Z29r17try0vr4vvrnxJ3W5Janrt34YqrWxZrs5JF45 t3yDWF1fA3yjga7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j7Oz3UUUUU= X-Originating-IP: [106.38.115.12] X-CM-SenderInfo: pzdqw6bntsiqqrwthudrp/1tbiVghgulqzl3uNcgABs- Subject: [dpdk-stable] [PATCH v2] mempool: fix memory allocation in memzones during retry. X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" If allocation is successful on the first attempt, typically there is no problem since we allocated everything required and we'll terminate the loop (if memory chunk is really sufficient to populate required number of mempool elements). If the first attempt fails, we try to allocate half of mem_size and it succeed, we'll have one more iteration of the for-loop to allocate memory for remaining elements and should not try the next time with quarter of the mem_size. It is wrong that max_alloc_size is divided by 2 in the case of successful allocation as well, or invalid memory can be allocated, and leads to population failure, then errno other than ENOMEM may be returned. Fixes: 3a3d0c75b43e ("mempool: fix slow allocation of large pools") Signed-off-by: Andrew Rybchenko Signed-off-by: Zhike Wang --- lib/librte_mempool/rte_mempool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c index a2bd249..7774f0c 100644 --- a/lib/librte_mempool/rte_mempool.c +++ b/lib/librte_mempool/rte_mempool.c @@ -635,7 +635,7 @@ struct pagesz_walk_arg { RTE_MIN((size_t)mem_size, max_alloc_size), mp->socket_id, mz_flags, align); - if (mz == NULL && rte_errno != ENOMEM) + if (mz != NULL || rte_errno != ENOMEM) break; max_alloc_size = RTE_MIN(max_alloc_size, -- 1.8.3.1