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 C47F57F78 for ; Wed, 29 Oct 2014 08:58:02 +0100 (CET) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 29 Oct 2014 01:06:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.04,808,1406617200"; d="scan'208";a="613277820" Received: from pgsmsx103.gar.corp.intel.com ([10.221.44.82]) by fmsmga001.fm.intel.com with ESMTP; 29 Oct 2014 01:06:16 -0700 Received: from kmsmsx153.gar.corp.intel.com (172.21.73.88) by PGSMSX103.gar.corp.intel.com (10.221.44.82) with Microsoft SMTP Server (TLS) id 14.3.195.1; Wed, 29 Oct 2014 16:04:22 +0800 Received: from shsmsx103.ccr.corp.intel.com (10.239.110.14) by KMSMSX153.gar.corp.intel.com (172.21.73.88) with Microsoft SMTP Server (TLS) id 14.3.195.1; Wed, 29 Oct 2014 16:04:21 +0800 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.202]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.207]) with mapi id 14.03.0195.001; Wed, 29 Oct 2014 16:04:20 +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 08:04:20 +0000 Message-ID: <533710CFB86FA344BFBF2D6802E60286C7CC55@SHSMSX101.ccr.corp.intel.com> References: <1414561659-7408-1-git-send-email-haifeng.lin@huawei.com> <533710CFB86FA344BFBF2D6802E60286C7CBAE@SHSMSX101.ccr.corp.intel.com> <54508BD3.1080001@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 07:58:04 -0000 10/29/2014 2:41 PM, Linhaifeng :=0A= >=0A= > On 2014/10/29 14:14, Qiu, Michael wrote:=0A= >> =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 = you=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= mp.=0A= >>> diff --git a/dpdk/dpdk-1.7.0/lib/librte_eal/linuxapp/eal/eal_memory.c b= /dpdk/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= >> 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= > If first set hugepg_tbl[i].orig_va to NULL,then failed to unlink you have= to restore hugepg_tbl[i].orig_va.=0A= > So I first to unlink for less codes.=0A= =0A= But it may be a big issue(not safe) when you unlink the path before you=0A= set the pointer to NULL, another thing is , why you need to restore the=0A= orig_va since the app will exit? Even you need to restore it just one or=0A= two lines code, I think it is not a big deal.=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= >> .=0A= >>=0A= =0A=