From patchwork Mon Jul 13 03:40:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?546L5b+X5YWL?= X-Patchwork-Id: 73859 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id B6F0FA0540; Mon, 13 Jul 2020 05:40:59 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 552A11C43F; Mon, 13 Jul 2020 05:40:58 +0200 (CEST) Received: from m12-13.163.com (m12-13.163.com [220.181.12.13]) by dpdk.org (Postfix) with ESMTP id EFF651C1D8 for ; Mon, 13 Jul 2020 05:40:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=si9DFp3OKt46n6A9Yf abEdREZ/dbjH6UcaSNoidSHdM=; b=RKeEeH0+rAm5eJxYQ9ArBWXJLBDduGIMKN XrVQWZqMahcs/SUDmWkkzyD76K+nydnG/1J5oyzustaLWWVn/CJb0qU5Ud2hnUff xC+2B6hlViV1C2zIYqVpjqQyElWXuesNZuQplhenBoBgrfW3Ppvxktl5aEbrwDl6 fx99+gcwM= Received: from localhost.localdomain (unknown [106.38.115.12]) by smtp9 (Coremail) with SMTP id DcCowADHpfK21wtfLyvpJA--.65523S2; Mon, 13 Jul 2020 11:40:48 +0800 (CST) From: Zhike Wang To: dev@dpdk.org Cc: olivier.matz@6wind.com, arybchenko@solarflare.com, Zhike Wang Date: Mon, 13 Jul 2020 11:40:34 +0800 Message-Id: <1594611634-7730-1-git-send-email-wangzhike@jd.com> X-Mailer: git-send-email 1.8.3.1 X-CM-TRANSID: DcCowADHpfK21wtfLyvpJA--.65523S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Zr1kJF48KF4kur43Xw1xAFb_yoW8GF43pr 43Gw1ktFnFqry7Crs7W3W8ua48K3Z29r12qry09r4vvr13Jw1UJanxtw1YqrWxZrWkJF45 t39rWF1fZw4Yga7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j5a9-UUUUU= X-Originating-IP: [106.38.115.12] X-CM-SenderInfo: pzdqw6bntsiqqrwthudrp/1tbiGABgulv2cZNPdgAAs0 Subject: [dpdk-dev] [PATCH] mempool: fix memory allocation in memzones during retry. X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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. Signed-off-by: Andrew Rybchenko Signed-off-by: Zhike Wang Reviewed-by: Andrew Rybchenko --- 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..b8f2629 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) || (mz == NULL && rte_errno != ENOMEM)) break; max_alloc_size = RTE_MIN(max_alloc_size,