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 at 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)
>  {

Reply via email to