From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [119.145.14.65]) by dpdk.org (Postfix) with ESMTP id 113ED7F1D for ; Wed, 29 Oct 2014 03:45:54 +0100 (CET) Received: from 172.24.2.119 (EHLO SZXEML458-HUB.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CBM95756; Wed, 29 Oct 2014 10:54:42 +0800 (CST) Received: from localhost (10.177.19.115) by SZXEML458-HUB.china.huawei.com (10.82.67.201) with Microsoft SMTP Server id 14.3.158.1; Wed, 29 Oct 2014 10:54:34 +0800 From: linhaifeng To: Date: Wed, 29 Oct 2014 10:54:29 +0800 Message-ID: <1414551269-5820-1-git-send-email-haifeng.lin@huawei.com> X-Mailer: git-send-email 1.8.5.2.msysgit.0 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.177.19.115] X-CFilter-Loop: Reflected Subject: [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 02:45:56 -0000 maybe somebody want to free hugepages when application exit. so add this function for application to release hugepages when exit. Signed-off-by: linhaifeng --- .../lib/librte_eal/common/include/rte_memory.h | 11 +++++++++ .../lib/librte_eal/linuxapp/eal/eal_memory.c | 27 ++++++++++++++++++++++ 2 files changed, 38 insertions(+) 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 index 4cf8ea9..7251b6b 100644 --- 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 @@ -172,6 +172,17 @@ unsigned rte_memory_get_nchannel(void); */ unsigned rte_memory_get_nrank(void); +/** + * Free all the hugepages.For the application to call when exit. + * + * @param void + * + * @return + * 0: successfully + * negative: error + */ +int rte_eal_hugepage_free(void); + #ifdef RTE_LIBRTE_XEN_DOM0 /** * Return the physical address of elt, which is an element of the pool mp. 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 index f2454f4..1ae0e79 100644 --- 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 @@ -98,6 +98,13 @@ #include "eal_filesystem.h" #include "eal_hugepages.h" +struct hugepage_table { + struct hugepage_file *hugepg_tbl; + unsigned nr_hugefiles; +}; + +static struct hugepage_table g_hugepage_table; + /** * @file * Huge page mapping under linux @@ -1202,6 +1209,7 @@ rte_eal_hugepage_init(void) (unsigned) (used_hp[i].hugepage_sz / 0x100000), j); + g_hugepage_table.nr_hugefiles += used_hp[i].num_pages[j]; } } } @@ -1237,6 +1245,8 @@ rte_eal_hugepage_init(void) goto fail; } + g_hugepage_table.hugepg_tbl = hugepage; + /* free the temporary hugepage table */ free(tmp_hp); tmp_hp = NULL; @@ -1487,6 +1497,23 @@ error: return -1; } +int +rte_eal_hugepage_free(void) +{ + struct hugepage_file *hugepg_tbl = g_hugepage_table.hugepg_tbl; + unsigned i; + unsigned nr_hugefiles = g_hugepage_table.nr_hugefiles; + + RTE_LOG(INFO, EAL, "unlink %u hugepage files\n", nr_hugefiles); + + for (i = 0; i < nr_hugefiles; i++) { + unlink(hugepg_tbl[i].filepath); + hugepg_tbl[i].orig_va = NULL; + } + + return 0; +} + static int rte_eal_memdevice_init(void) { -- 1.8.3.1