From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 9175D7E0B for ; Wed, 29 Oct 2014 04:20:57 +0100 (CET) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP; 28 Oct 2014 20:23:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.04,807,1406617200"; d="scan'208";a="613179609" Received: from pgsmsx101.gar.corp.intel.com ([10.221.44.78]) by fmsmga001.fm.intel.com with ESMTP; 28 Oct 2014 20:29:45 -0700 Received: from kmsmsx151.gar.corp.intel.com (172.21.73.86) by PGSMSX101.gar.corp.intel.com (10.221.44.78) with Microsoft SMTP Server (TLS) id 14.3.195.1; Wed, 29 Oct 2014 11:28:07 +0800 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by KMSMSX151.gar.corp.intel.com (172.21.73.86) with Microsoft SMTP Server (TLS) id 14.3.195.1; Wed, 29 Oct 2014 11:28:07 +0800 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.202]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.174]) with mapi id 14.03.0195.001; Wed, 29 Oct 2014 11:27:59 +0800 From: "Qiu, Michael" To: linhaifeng , "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH] add free hugepage function Thread-Index: AQHP8yPWQcc+h2Wonkit2TyrlWBr4w== Date: Wed, 29 Oct 2014 03:27:58 +0000 Message-ID: <533710CFB86FA344BFBF2D6802E60286C7CAAB@SHSMSX101.ccr.corp.intel.com> References: <1414551269-5820-1-git-send-email-haifeng.lin@huawei.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH] add free hugepage function 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: Wed, 29 Oct 2014 03:20:59 -0000 10/29/2014 10:55 AM, linhaifeng :=0A= > maybe somebody want to free hugepages when application exit.=0A= > so add this function for application to release hugepages when exit.=0A= >=0A= > Signed-off-by: linhaifeng =0A= > ---=0A= > .../lib/librte_eal/common/include/rte_memory.h | 11 +++++++++=0A= > .../lib/librte_eal/linuxapp/eal/eal_memory.c | 27 ++++++++++++++++= ++++++=0A= > 2 files changed, 38 insertions(+)=0A= >=0A= > diff --git a/dpdk/dpdk-1.7.0/lib/librte_eal/common/include/rte_memory.h b= /dpdk/dpdk-1.7.0/lib/librte_eal/common/include/rte_memory.h=0A= > index 4cf8ea9..7251b6b 100644=0A= > --- a/dpdk/dpdk-1.7.0/lib/librte_eal/common/include/rte_memory.h=0A= > +++ b/dpdk/dpdk-1.7.0/lib/librte_eal/common/include/rte_memory.h=0A= > @@ -172,6 +172,17 @@ unsigned rte_memory_get_nchannel(void);=0A= > */=0A= > unsigned rte_memory_get_nrank(void);=0A= > =0A= > +/**=0A= > + * Free all the hugepages.For the application to call when exit.=0A= > + *=0A= > + * @param void=0A= > + *=0A= > + * @return=0A= > + * 0: successfully=0A= > + * negative: error=0A= > + */=0A= =0A= here should be a non-return function, see comments below :)=0A= =0A= > +int rte_eal_hugepage_free(void);=0A= > +=0A= > #ifdef RTE_LIBRTE_XEN_DOM0=0A= > /**=0A= > * Return the physical address of elt, which is an element of the pool m= p.=0A= > diff --git a/dpdk/dpdk-1.7.0/lib/librte_eal/linuxapp/eal/eal_memory.c b/d= pdk/dpdk-1.7.0/lib/librte_eal/linuxapp/eal/eal_memory.c=0A= > index f2454f4..1ae0e79 100644=0A= > --- a/dpdk/dpdk-1.7.0/lib/librte_eal/linuxapp/eal/eal_memory.c=0A= > +++ b/dpdk/dpdk-1.7.0/lib/librte_eal/linuxapp/eal/eal_memory.c=0A= > @@ -98,6 +98,13 @@=0A= > #include "eal_filesystem.h"=0A= > #include "eal_hugepages.h"=0A= > =0A= > +struct hugepage_table {=0A= > + struct hugepage_file *hugepg_tbl;=0A= > + unsigned nr_hugefiles;=0A= > +};=0A= > +=0A= > +static struct hugepage_table g_hugepage_table;=0A= > +=0A= > /**=0A= > * @file=0A= > * Huge page mapping under linux=0A= > @@ -1202,6 +1209,7 @@ rte_eal_hugepage_init(void)=0A= > (unsigned)=0A= > (used_hp[i].hugepage_sz / 0x100000),=0A= > j);=0A= > + g_hugepage_table.nr_hugefiles +=3D used_hp[i].num_pages[j];=0A= > }=0A= > }=0A= > }=0A= > @@ -1237,6 +1245,8 @@ rte_eal_hugepage_init(void)=0A= > goto fail;=0A= > }=0A= > =0A= > + g_hugepage_table.hugepg_tbl =3D hugepage;=0A= > +=0A= > /* free the temporary hugepage table */=0A= > free(tmp_hp);=0A= > tmp_hp =3D NULL;=0A= > @@ -1487,6 +1497,23 @@ error:=0A= > return -1;=0A= > }=0A= > =0A= > +int=0A= > +rte_eal_hugepage_free(void)=0A= > +{=0A= > + struct hugepage_file *hugepg_tbl =3D g_hugepage_table.hugepg_tbl;=0A= > + unsigned i;=0A= > + unsigned nr_hugefiles =3D g_hugepage_table.nr_hugefiles;=0A= > +=0A= > + RTE_LOG(INFO, EAL, "unlink %u hugepage files\n", nr_hugefiles);=0A= > +=0A= > + for (i =3D 0; i < nr_hugefiles; i++) {=0A= > + unlink(hugepg_tbl[i].filepath);=0A= > + hugepg_tbl[i].orig_va =3D NULL;=0A= > + }=0A= > +=0A= > + return 0;=0A= =0A= I just saw one return path with value '0', and no any other place =0A= return a negative value, so it is better to be designed as one=0A= non-return function,=0A= =0A= +void=0A= +rte_eal_hugepage_free(void)=0A= +{=0A= + struct hugepage_file *hugepg_tbl =3D g_hugepage_table.hugepg_tbl;=0A= + unsigned i;=0A= + unsigned nr_hugefiles =3D g_hugepage_table.nr_hugefiles;=0A= +=0A= + RTE_LOG(INFO, EAL, "unlink %u hugepage files\n", nr_hugefiles);=0A= +=0A= + for (i =3D 0; i < nr_hugefiles; i++) {=0A= + unlink(hugepg_tbl[i].filepath);=0A= + hugepg_tbl[i].orig_va =3D NULL;=0A= + }=0A= +}=0A= +=0A= =0A= Thanks,=0A= Michael=0A= > +}=0A= > +=0A= > static int=0A= > rte_eal_memdevice_init(void)=0A= > {=0A= =0A=