From: "Qiu, Michael" <michael.qiu@intel.com>
To: linhaifeng <haifeng.lin@huawei.com>, "dev@dpdk.org" <dev@dpdk.org>
Subject: Re: [dpdk-dev] [PATCH] add free hugepage function
Date: Wed, 29 Oct 2014 03:27:58 +0000 [thread overview]
Message-ID: <533710CFB86FA344BFBF2D6802E60286C7CAAB@SHSMSX101.ccr.corp.intel.com> (raw)
In-Reply-To: <1414551269-5820-1-git-send-email-haifeng.lin@huawei.com>
10/29/2014 10:55 AM, linhaifeng :
> 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@huawei.com>
> ---
> .../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
> + */
here should be a non-return function, see comments below :)
> +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;
I just saw one return path with value '0', and no any other place
return a negative value, so it is better to be designed as one
non-return function,
+void
+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;
+ }
+}
+
Thanks,
Michael
> +}
> +
> static int
> rte_eal_memdevice_init(void)
> {
next prev parent reply other threads:[~2014-10-29 3:20 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-29 2:54 linhaifeng
2014-10-29 3:27 ` Qiu, Michael [this message]
2014-10-29 3:44 ` Matthew Hall
2014-10-29 5:14 ` Linhaifeng
2014-10-29 5:26 ` Qiu, Michael
2014-10-29 6:49 ` Linhaifeng
2014-10-29 10:26 ` Bruce Richardson
2014-10-29 14:27 ` Neil Horman
2014-10-29 15:22 ` Ramia, Kannan Babu
2014-10-29 15:32 ` Neil Horman
2014-10-29 16:47 ` Bruce Richardson
2014-10-30 3:23 ` Matthew Hall
2014-10-30 10:18 ` Neil Horman
2014-10-30 14:56 ` Matthew Hall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=533710CFB86FA344BFBF2D6802E60286C7CAAB@SHSMSX101.ccr.corp.intel.com \
--to=michael.qiu@intel.com \
--cc=dev@dpdk.org \
--cc=haifeng.lin@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).