From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 921587F5C for ; Wed, 29 Oct 2014 07:07:40 +0100 (CET) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 28 Oct 2014 23:16:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.04,808,1406617200"; d="scan'208";a="613229581" Received: from pgsmsx103.gar.corp.intel.com ([10.221.44.82]) by fmsmga001.fm.intel.com with ESMTP; 28 Oct 2014 23:16:28 -0700 Received: from pgsmsx108.gar.corp.intel.com (10.221.44.103) by PGSMSX103.gar.corp.intel.com (10.221.44.82) with Microsoft SMTP Server (TLS) id 14.3.195.1; Wed, 29 Oct 2014 14:14:34 +0800 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by PGSMSX108.gar.corp.intel.com (10.221.44.103) with Microsoft SMTP Server (TLS) id 14.3.195.1; Wed, 29 Oct 2014 14:14:34 +0800 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.202]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.44]) with mapi id 14.03.0195.001; Wed, 29 Oct 2014 14:14:33 +0800 From: "Qiu, Michael" To: linhaifeng , "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH v2] support free hugepages Thread-Index: AQHP8zwM/Pmizg8u4UyAPDK47ITsuQ== Date: Wed, 29 Oct 2014 06:14:33 +0000 Message-ID: <533710CFB86FA344BFBF2D6802E60286C7CBAE@SHSMSX101.ccr.corp.intel.com> References: <1414561659-7408-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="iso-2022-jp" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v2] support free hugepages 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 06:07:41 -0000 =1B$B:_=1B(B 10/29/2014 1:49 PM, linhaifeng =1B$B rte_eal_hugepage_free() is used for unlink all hugepages.If you want to= =0A= > free all hugepages you must make sure that you have stop to use it,and yo= u=0A= > must call this function before exit process.=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 | 31 ++++++++++++++++= ++++++=0A= > 2 files changed, 42 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..f6ad95f 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= > + * Unlink all hugepages which created by dpdk.=0A= > + *=0A= > + * @param void=0A= > + *=0A= > + * @return=0A= > + * 0: successfully=0A= > + * negative: error=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..109207c 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,27 @@ 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= > + int ret =3D 0;=0A= > +=0A= > + for (i =3D 0; i < nr_hugefiles; i++) {=0A= > + ret =3D unlink(hugepg_tbl[i].filepath);=0A= > + if (ret !=3D 0) {=0A= > + RTE_LOG(ERR, EAL, "Failed to unlink %s", hugepg_tbl[i].filepath);=0A= > + return ret;=0A= > + }=0A= > + hugepg_tbl[i].orig_va =3D NULL;=0A= =0A= BTW, is it better to first set hugepg_tbl[i].orig_vato NULL, then unlink=0A= filepath?=0A= It may be not a good idea to first remove then set to NULL.=0A= =0A= Thanks,=0A= Michael=0A= =0A= > + }=0A= > +=0A= > + RTE_LOG(INFO, EAL, "unlink %u hugepage files\n", nr_hugefiles);=0A= > + return ret;=0A= > +}=0A= > +=0A= > static int=0A= > rte_eal_memdevice_init(void)=0A= > {=0A= =0A=