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 7EEAAA0540; Mon, 13 Jul 2020 13:17:40 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id DB4821D5F1; Mon, 13 Jul 2020 13:17:39 +0200 (CEST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id 042311D5B6 for ; Mon, 13 Jul 2020 13:17:37 +0200 (CEST) IronPort-SDR: 8GJgma7zE92wscgD9II7AE+cSirx5hYqTACRmSDWjpcNxifwpMv7qgQ2RuY3g3jutWSKuz9V9G lPmLRS67XH9A== X-IronPort-AV: E=McAfee;i="6000,8403,9680"; a="210129494" X-IronPort-AV: E=Sophos;i="5.75,347,1589266800"; d="scan'208";a="210129494" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2020 04:17:36 -0700 IronPort-SDR: aYPcgUq2qH5qjYUilpHZ57u/W9rPiauhbTRo0MTlkujTqCx8a+EqfO0AosmsHxCi0GQXBPV6pW aVNpdDqMkzJg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,347,1589266800"; d="scan'208";a="485447760" Received: from aburakov-mobl.ger.corp.intel.com (HELO [10.213.225.87]) ([10.213.225.87]) by fmsmga005.fm.intel.com with ESMTP; 13 Jul 2020 04:17:35 -0700 To: Zhike Wang , dev@dpdk.org Cc: olivier.matz@6wind.com, arybchenko@solarflare.com References: <1594611634-7730-1-git-send-email-wangzhike@jd.com> From: "Burakov, Anatoly" Message-ID: Date: Mon, 13 Jul 2020 12:17:35 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <1594611634-7730-1-git-send-email-wangzhike@jd.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [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" On 13-Jul-20 4:40 AM, Zhike Wang wrote: > 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 > --- > 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)) I think checking mz == NULL for the second time is redundant, as if we're hitting the second branch, we've already failed the "mz != NULL" test and can therefore assume that mz == NULL. That said, i'm struggling to think of circumstances where this would matter. Could you please provide an example? > break; > > max_alloc_size = RTE_MIN(max_alloc_size, > This should have a Fixes: tag. -- Thanks, Anatoly