From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dispatch1-us1.ppe-hosted.com (dispatch1-us1.ppe-hosted.com [67.231.154.164]) by dpdk.org (Postfix) with ESMTP id B700E2B82 for ; Thu, 3 May 2018 11:35:11 +0200 (CEST) X-Virus-Scanned: Proofpoint Essentials engine Received: from webmail.solarflare.com (uk.solarflare.com [193.34.186.16]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1-us1.ppe-hosted.com (Proofpoint Essentials ESMTP Server) with ESMTPS id 67F8B40006A; Thu, 3 May 2018 09:35:07 +0000 (UTC) Received: from [192.168.38.17] (84.52.114.114) by ukex01.SolarFlarecom.com (10.17.10.4) with Microsoft SMTP Server (TLS) id 15.0.1044.25; Thu, 3 May 2018 10:35:02 +0100 To: Olivier Matz , CC: Anatoly Burakov References: <20180502201349.15568-1-olivier.matz@6wind.com> From: Andrew Rybchenko Message-ID: <366ffbd0-f5ab-c2d0-2cde-df1f904b2745@solarflare.com> Date: Thu, 3 May 2018 12:34:59 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180502201349.15568-1-olivier.matz@6wind.com> Content-Language: en-GB X-Originating-IP: [84.52.114.114] X-ClientProxiedBy: ocex03.SolarFlarecom.com (10.20.40.36) To ukex01.SolarFlarecom.com (10.17.10.4) X-TM-AS-Product-Ver: SMEX-11.0.0.1191-8.100.1062-23820.003 X-TM-AS-Result: No--22.192200-0.000000-31 X-TM-AS-User-Approved-Sender: Yes X-TM-AS-User-Blocked-Sender: No X-MDID: 1525340108-3iN+ztIfyYfV Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Subject: Re: [dpdk-dev] [PATCH] mempool: fix alignment of memzone length when populating 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: , X-List-Received-Date: Thu, 03 May 2018 09:35:12 -0000 Hi Olivier, On 05/02/2018 11:13 PM, Olivier Matz wrote: > When populating a mempool with the default function, if there is not > enough virtually contiguous memory for the whole mempool, it will be > populated with several chunks. A chunk of the maximum available length > is requested with: > > mz = rte_memzone_reserve_aligned(..., len=0, ..., align=x) > > If align is smaller than the page size, the length of the memzone may > not be a multiple of the page size. This makes > rte_mempool_populate_virt() to fail because it requires a page-aligned > length. This patch forces the memzone length to be a multiple of page > size. > > The problem can be reproduced easily by allocating more than available > memory: > ./build/app/testpmd -l 0,1 -- --total-num-mbufs=65536 > ... > Cause: Creation of mbuf pool for socket 0 failed: Invalid argument > > After the patch, the error code is correct: > ./build/app/testpmd -l 0,1 -- --total-num-mbufs=65536 > ... > Cause: Creation of mbuf pool for socket 0 failed: Cannot allocate memory > > Signed-off-by: Olivier Matz > Fixes: ba0009560c30 ("mempool: support new allocation methods") > --- > > Hi Anatoly, > > Another option to fix this issue could be to ensure that > rte_memzone_reserve_aligned(..., len=0, ..., align=x) returns a length > that is multiple of page size. Something like: > > mz = rte_memzone_reserve_aligned(mz_name, 0, > - mp->socket_id, flags, align); > + mp->socket_id, flags, RTE_MAX(pg_sz, align)); As far as I can see rte_mempool_populate_virt() checks that both address and length are page size aligned. So, I think both should be used. This one to be sure that address is page-aligned, below to ensure that length is page size aligned. May be one of them will be the property of the allocated region any way, but it is safer to guarantee both restrictions. > > Let me know if you prefer this way. > > Thanks, > Olivier > > > 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 cf5d124ec..78c3e95ec 100644 > --- a/lib/librte_mempool/rte_mempool.c > +++ b/lib/librte_mempool/rte_mempool.c > @@ -709,7 +709,7 @@ rte_mempool_populate_default(struct rte_mempool *mp) > (void *)(uintptr_t)mz); > else > ret = rte_mempool_populate_virt(mp, mz->addr, > - mz->len, pg_sz, > + RTE_ALIGN_FLOOR(mz->len, pg_sz), pg_sz, > rte_mempool_memchunk_mz_free, > (void *)(uintptr_t)mz); > if (ret < 0) {