From patchwork Wed Oct 29 05:47:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linhaifeng X-Patchwork-Id: 996 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 0C4957F55; Wed, 29 Oct 2014 06:39:03 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [119.145.14.65]) by dpdk.org (Postfix) with ESMTP id E19937F51 for ; Wed, 29 Oct 2014 06:38:58 +0100 (CET) Received: from 172.24.2.119 (EHLO szxeml420-hub.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CBN13015; Wed, 29 Oct 2014 13:47:47 +0800 (CST) Received: from localhost (10.177.19.115) by szxeml420-hub.china.huawei.com (10.82.67.159) with Microsoft SMTP Server id 14.3.158.1; Wed, 29 Oct 2014 13:47:40 +0800 From: linhaifeng To: Date: Wed, 29 Oct 2014 13:47:39 +0800 Message-ID: <1414561659-7408-1-git-send-email-haifeng.lin@huawei.com> X-Mailer: git-send-email 1.8.5.2.msysgit.0 MIME-Version: 1.0 X-Originating-IP: [10.177.19.115] X-CFilter-Loop: Reflected Subject: [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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" rte_eal_hugepage_free() is used for unlink all hugepages.If you want to free all hugepages you must make sure that you have stop to use it,and you must call this function before exit process. Signed-off-by: linhaifeng --- .../lib/librte_eal/common/include/rte_memory.h | 11 ++++++++ .../lib/librte_eal/linuxapp/eal/eal_memory.c | 31 ++++++++++++++++++++++ 2 files changed, 42 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..f6ad95f 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); +/** + * Unlink all hugepages which created by dpdk. + * + * @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..109207c 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,27 @@ 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; + int ret = 0; + + for (i = 0; i < nr_hugefiles; i++) { + ret = unlink(hugepg_tbl[i].filepath); + if (ret != 0) { + RTE_LOG(ERR, EAL, "Failed to unlink %s", hugepg_tbl[i].filepath); + return ret; + } + hugepg_tbl[i].orig_va = NULL; + } + + RTE_LOG(INFO, EAL, "unlink %u hugepage files\n", nr_hugefiles); + return ret; +} + static int rte_eal_memdevice_init(void) {