dev.dpdk.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] add free hugepage function
@ 2014-10-29  2:54 linhaifeng
  2014-10-29  3:27 ` Qiu, Michael
  0 siblings, 1 reply; 14+ messages in thread
From: linhaifeng @ 2014-10-29  2:54 UTC (permalink / raw)
  To: dev-VfR2kkLFssw

maybe somebody want to free hugepages when application exit.
so add this function for application to release hugepages when exit.

Signed-off-by: linhaifeng <haifeng.lin-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
---
 .../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

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2014-10-30 14:56 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-29  2:54 [PATCH] add free hugepage function linhaifeng
2014-10-29  3:27 ` Qiu, Michael
     [not found]   ` <533710CFB86FA344BFBF2D6802E60286C7CAAB-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2014-10-29  3:44     ` Matthew Hall
     [not found]       ` <20141029034437.GA29486-Hv3ogNYU3JfZZajBQzqCxQ@public.gmane.org>
2014-10-29  5:14         ` Linhaifeng
2014-10-29  5:26       ` Qiu, Michael
     [not found]         ` <533710CFB86FA344BFBF2D6802E60286C7CB42-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2014-10-29  6:49           ` Linhaifeng
     [not found]             ` <54508DE1.9090908-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2014-10-29 10:26               ` Bruce Richardson
2014-10-29 14:27                 ` Neil Horman
     [not found]                   ` <20141029142745.GA14253-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2014-10-29 15:22                     ` Ramia, Kannan Babu
     [not found]                       ` <682698A055A0F44AA47192B20141149711B6074C-yHIBzpp8AekFyVwBAnZdSLfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2014-10-29 15:32                         ` Neil Horman
     [not found]                           ` <20141029153212.GB14253-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2014-10-29 16:47                             ` Bruce Richardson
2014-10-30  3:23                             ` Matthew Hall
     [not found]                               ` <20141030032324.GC3286-Hv3ogNYU3JfZZajBQzqCxQ@public.gmane.org>
2014-10-30 10:18                                 ` Neil Horman
     [not found]                                   ` <20141030101856.GA24783-B26myB8xz7F8NnZeBjwnZQMhkBWG/bsMQH7oEaQurus@public.gmane.org>
2014-10-30 14:56                                     ` Matthew Hall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).