From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 7C0B35926 for ; Mon, 28 Jul 2014 19:08:30 +0200 (CEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 28 Jul 2014 10:04:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.01,750,1400050800"; d="scan'208";a="580185586" Received: from irsmsx103.ger.corp.intel.com ([163.33.3.157]) by orsmga002.jf.intel.com with ESMTP; 28 Jul 2014 10:09:50 -0700 Received: from irsmsx152.ger.corp.intel.com (163.33.192.66) by IRSMSX103.ger.corp.intel.com (163.33.3.157) with Microsoft SMTP Server (TLS) id 14.3.123.3; Mon, 28 Jul 2014 18:09:48 +0100 Received: from irsmsx105.ger.corp.intel.com ([169.254.7.65]) by IRSMSX152.ger.corp.intel.com ([169.254.6.93]) with mapi id 14.03.0123.003; Mon, 28 Jul 2014 18:09:48 +0100 From: "Ananyev, Konstantin" To: Mahdi Dashtbozorgi , "dev@dpdk.org" Thread-Topic: [dpdk-dev] free a memzone Thread-Index: AQHPpaDxjio4UdMBWUOXAJwutZCpGJutTjyAgACgqgCAAMPKSYAENpcQgAKAcQCAAFakIA== Date: Mon, 28 Jul 2014 17:09:47 +0000 Message-ID: <2601191342CEEE43887BDE71AB9772582134416A@IRSMSX105.ger.corp.intel.com> References: <59AF69C657FD0841A61C55336867B5B0343B1714@IRSMSX103.ger.corp.intel.com> <2601191342CEEE43887BDE71AB977258213440D1@IRSMSX105.ger.corp.intel.com> In-Reply-To: Accept-Language: en-IE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.182] Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] free a memzone X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Jul 2014 17:08:31 -0000 Hi Mahdi, >Hi Konstantin, >Thank you very much. Your solution fixed my problem. >Is there a solution like this for resetting the memory zone, which is used= by rte_malloc function?=20 >Because if I use rte_malloc instead of malloc, in the case of application = crash, the memory zone, which was used by rte_malloc in the previous run wo= uld be >unusable for the next run of slave process.=20 Without significant modification inside librte_eal and/or librte_malloc - n= othing comes on top of my head. If that is such a big problem to you, might be it is possible to change you= r whole process model a bit: In the parent process: - allocate memory/init run-time strcutures L1: - fork(); - wait till child terminates - if it terminated abnormally, then free memory/re-init run-time structures= . Goto L1 Do actual packet processing inside child process. Would that help somehow? Konstantin > -----Original Message----- > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Mahdi Dashtbozorgi > Sent: Thursday, July 24, 2014 6:20 AM > To: dev@dpdk.org > Subject: Re: [dpdk-dev] free a memzone > > Hi Bruce, > > Thank you for the response. That's a great Idea! > But I do not understand the last four parameters of this function. (vaddr= , > paddr, pg_num, pg_shift) > I guess vaddr is the virtual address of the previously allocated mempool, yes > paddr is calculated using function call rte_mem_virt2phy(vaddr), am I > right? yes =A0>what about pg_num and pg_shift? how can I pass them correctly? >>From rte_mempool.h: "* @param pg_num =A0* =A0 Number of elements in the paddr array. =A0* @param pg_shift =A0* =A0 LOG2 of the physical pages size." If you are using memzone as externally allocated memory - it will be alread= y physically continuos. So in your case pg_num =3D MEMPOOL_PG_NUM_DEFAULT, =A0pg_shift =3D MEMPOOL_= PG_SHIFT_MAX. Though, I don't think rte_mempool_xmem_create() will help you in any way. Again from rte_mempool.h: "* Creates a new mempool named *name* in memory. =A0* =A0* This function uses ``memzone_reserve()`` to allocate memory. The =A0* pool contains n elements of elt_size. Its size is set to n. =A0* Depending on the input parameters, mempool elements can be either allo= cated =A0* together with the mempool header, or an externally provided memory buf= fer =A0* could be used to store mempool objects. In later case, that external =A0* memory buffer can consist of set of disjoint phyiscal pages." So xmem_create would still create a new ring, reserve a new memzone of memp= ool's metadata, etc. The only difference - it can use externally allocated memory to store mempo= ol elements. As I understand what you need is sort of mempool_reset(): a function that w= ould re-init mempool to just created state (all elements are free, lcores caches are empty, etc). Right now we don't have such function, =A0but I suppose something like that= should do (note that I didn't run or even build it): If ((mp =3D rte_mempool_lookup(name)) !=3D NULL { char ring_name[RTE_RING_NAMESIZE]; /* save mp ring name. */ memcpy(ring_name, mp->ring->name, sizeof ring_name); /* reset the ring. */ =A0 rte_ring_init(mp->ring, ring_name, =A0rte_align32pow2(mp->size+1), mp->= ring->flags); /*repopulate mempool and reinit all its elements. */ mempool_populate(mp, mp->size, 1, rte_pktmbuf_init, NULL); /* reset all lcore caches. */ =A0memset(mp->local_cache, 0, sizeof(local_cahce)); =A0 /* reset statistics if needed. */ } else { =A0 /* create new mempool. */ } Ideally such function should be in the librte_mempool of course, but if you= are in a hurry - you probably can give it a try. Note that I assume that no other process, except failed/restarting secondar= y are using this mempool. If primary or some other secondary do, then first you need to stop them usi= ng this mempool and wait till they finish all their packet processing activ= ity. Konstantin > Best Regards, > Mahdi. > > > On Thu, Jul 24, 2014 at 9:48 AM, Mahdi Dashtbozorgi > wrote: > > > Hi Bruce, > > > > Thank you for the response. That's a great Idea! > > But I do not understand the last four parameters of this function. (vad= dr, > > paddr, pg_num, pg_shift) > > I guess vaddr is the virtual address of the previously allocated mempoo= l, > > paddr is calculated using function call rte_mem_virt2phy(vaddr), am I > > right? what about pg_num and pg_shift? how can I pass them correctly? > > > > Best Regards, > > Mahdi. > > > > > > On Wed, Jul 23, 2014 at 11:09 PM, Richardson, Bruce < > > bruce.richardson@intel.com> wrote: > > > >> Rather than freeing the previously allocated memzone, could you not ju= st > >> re-initialize the mempool using something like rte_mempool_xmem_create= ? > >> > >> > -----Original Message----- > >> > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Mahdi Dashtbozo= rgi > >> > Sent: Wednesday, July 23, 2014 2:05 AM > >> > To: dev@dpdk.org > >> > Subject: Re: [dpdk-dev] free a memzone > >> > > >> > Hi guys, > >> > > >> > Is there any suggestion to free the previously allocated memzone? > >> > I really need help in this issue. > >> > Any help is appreciated. > >> > > >> > Best Regards, > >> > Mahdi. > >> > > >> > > >> > > >> > On Tue, Jul 22, 2014 at 4:03 PM, Mahdi Dashtbozorgi > >> > wrote: > >> > > >> > > Hi, > >> > > > >> > > I have two processes, which uses DPDK multi-process feature to > >> communicate. > >> > > Master process captures packets from NIC and put them to a ring > >> buffer, > >> > > which is shared between master and slave process. > >> > > The slave process looks up the shared ring buffer using > >> rte_ring_lookup > >> > > function and reads the packets. > >> > > The slave process needs a memory pool, too. Therefore, it creates = a > >> > > mempool using rte_mempool_create. But If the slave process crashes > >> during > >> > > its processing and runs again, rte_mempool_create function fails a= nd > >> tells > >> > > that there is a memory zone with that name. > >> > > If I use rte_mempool_lookup in this case, the memory pool is not a > >> clean > >> > > memory pool. Because the previous run of slave process did not > >> terminate > >> > > gracefully and did not return all the objects to the pool. > >> > > Is there any function to free an existing memory zone, which I cal= l > >> before > >> > > rte_mempool_create to ensure that previous memory pool does not ex= ists > >> > > anymore? > >> > > > >> > > Best Regards, > >> > > Mahdi. > >> > > > >> > > > >