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 A9298A0540; Mon, 13 Jul 2020 16:52:47 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8435A1D8DE; Mon, 13 Jul 2020 16:52:46 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id 708DE1D8DB for ; Mon, 13 Jul 2020 16:52:44 +0200 (CEST) IronPort-SDR: MR4WwlOrH3UNhWM9pYJ8Syzj60Yteq9MfvFd4ZhUFX2DjAFykX8fi3EBZ1K79+gXBs/TpZxYkn MaKzGnVyw03g== X-IronPort-AV: E=McAfee;i="6000,8403,9681"; a="233483170" X-IronPort-AV: E=Sophos;i="5.75,347,1589266800"; d="scan'208";a="233483170" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2020 07:52:43 -0700 IronPort-SDR: 5g0lo5aLDl9aF+T1dqxKdaqHqeLnItEJtsRdMi9F+pCv4IMzxN9/BMzlulvPMpk96AbDdJFCS5 ndLsidj9Y+NA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,347,1589266800"; d="scan'208";a="459321459" Received: from aburakov-mobl.ger.corp.intel.com (HELO [10.213.225.87]) ([10.213.225.87]) by orsmga005.jf.intel.com with ESMTP; 13 Jul 2020 07:52:41 -0700 To: Andrew Rybchenko , Zhike Wang , dev@dpdk.org Cc: olivier.matz@6wind.com References: <1594611634-7730-1-git-send-email-wangzhike@jd.com> <29052ed4-8edd-3667-f44d-314522a44292@solarflare.com> From: "Burakov, Anatoly" Message-ID: <731680e8-9ae8-b378-4dc7-3ffb0a710d7c@intel.com> Date: Mon, 13 Jul 2020 15:52:40 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <29052ed4-8edd-3667-f44d-314522a44292@solarflare.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit 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 12:29 PM, Andrew Rybchenko wrote: > On 7/13/20 2:17 PM, Burakov, Anatoly wrote: >> 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. > > Yes, of course. (Also parenthesis will be not required.) > >> >> That said, i'm struggling to think of circumstances where this would >> matter. Could you please provide an example? > > If the question about break in the case of mz != NULL, > it is important to avoid decreasing max_alloc_size to > try the same size once again if one more iteration is > needed to allocate remaining elements. Right, no further questions :) > >> >>>                   break; >>>                 max_alloc_size = RTE_MIN(max_alloc_size, >>> >> >> This should have a Fixes: tag. >> > > Yes, missed it. > > Many thanks for the review. > -- Thanks, Anatoly