Skip to contentSkip to conversation

mem: command line option to delete hugepage backing files

PATCH Superseded shesha Sreenivasamurthy (shesha) 2 participants 2 messages Oct 21, 2015 – Oct 22, 2015 1 message not in the archive

v4 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v4 1/1 mem: command line option to delete hugepage backing files

When an application using huge-pages crash or exists, the hugetlbfs backing files are not cleaned up. This is a patch to clean those files. There are multi-process DPDK applications that may be benefited by those backing files. Therefore, I have made that configurable so that the application that does not need those backing files can remove them, thus not changing the current default behavior. The application itself can clean it up, however the rationale behind DPDK cleaning it up is, DPDK created it and therefore, it is better it unlinks it.

---
 lib/librte_eal/common/eal_common_options.c | 12 ++++++++++++
 lib/librte_eal/common/eal_internal_cfg.h   |  1 +
 lib/librte_eal/common/eal_options.h        |  2 ++
 lib/librte_eal/linuxapp/eal/eal_memory.c   | 12 ++++++++++++
 4 files changed, 27 insertions(+)
(quoted diff) +0 -0

b/lib/librte_eal/common/eal_common_options.c
index 1f459ac..5fe6374 100644

lib/librte_eal/common/eal_common_options.c +5 -0
@@ -79,6 +79,7 @@ eal_long_options[] = {
 	{OPT_MASTER_LCORE,      1, NULL, OPT_MASTER_LCORE_NUM     },
 	{OPT_NO_HPET,           0, NULL, OPT_NO_HPET_NUM          },
 	{OPT_NO_HUGE,           0, NULL, OPT_NO_HUGE_NUM          },
+	{OPT_HUGE_UNLINK,       0, NULL, OPT_HUGE_UNLINK_NUM      },
 	{OPT_NO_PCI,            0, NULL, OPT_NO_PCI_NUM           },
 	{OPT_NO_SHCONF,         0, NULL, OPT_NO_SHCONF_NUM        },
 	{OPT_PCI_BLACKLIST,     1, NULL, OPT_PCI_BLACKLIST_NUM    },
@@ -722,6 +723,10 @@ eal_parse_common_option(int opt, const char *optarg,
 		conf->no_hugetlbfs = 1;
 		break;
 
+	case OPT_HUGE_UNLINK_NUM:
+		conf->hugepage_unlink = 1;
+		break;
+
 	case OPT_NO_PCI_NUM:
 		conf->no_pci = 1;
 		break;
@@ -856,6 +861,12 @@ eal_check_common_options(struct internal_config

*internal_cfg)
return -1;
}

+ if (internal_cfg->no_hugetlbfs && internal_cfg->hugepage_unlink) {
+ RTE_LOG(ERR, EAL, "Option --"OPT_HUGE_UNLINK" cannot "
+ "be specified together with --"OPT_NO_HUGE"\n");
+ return -1;
+ }
+
if (rte_eal_devargs_type_count(RTE_DEVTYPE_WHITELISTED_PCI) != 0 &&
rte_eal_devargs_type_count(RTE_DEVTYPE_BLACKLISTED_PCI) != 0) { RTE_LOG(ERR, EAL, "Options blacklist (-b) and whitelist (-w) "
@@ -906,6 +917,7 @@ eal_common_usage(void)
" -h, --help This help\n"
"\nEAL options for DEBUG use only:\n"

 	       "  --"OPT_NO_HUGE"           Use malloc instead of hugetlbfs\n"
+	       "  --"OPT_HUGE_UNLINK"       Unlink hugepage backing file after
initalization\n"
 	       "  --"OPT_NO_PCI"            Disable PCI\n"
 	       "  --"OPT_NO_HPET"           Disable HPET\n"
 	       "  --"OPT_NO_SHCONF"         No shared config (mmap'd files)\n"
(quoted diff) +0 -0

b/lib/librte_eal/common/eal_internal_cfg.h
index e2ecb0d..84b075f 100644

lib/librte_eal/common/eal_internal_cfg.h +1 -0
@@ -64,6 +64,7 @@ struct internal_config {
 	volatile unsigned force_nchannel; /**< force number of channels */
 	volatile unsigned force_nrank;    /**< force number of ranks */
 	volatile unsigned no_hugetlbfs;   /**< true to disable hugetlbfs */
+	volatile unsigned hugepage_unlink; /** < true to unlink backing files */
 	volatile unsigned xen_dom0_support; /**< support app running on Xen

Dom0*/
volatile unsigned no_pci; /**< true to disable PCI */
volatile unsigned no_hpet; /**< true to disable HPET */

(quoted diff) +0 -0

b/lib/librte_eal/common/eal_options.h
index f6714d9..745f38c 100644

lib/librte_eal/common/eal_options.h +2 -0
@@ -63,6 +63,8 @@ enum {
 	OPT_PROC_TYPE_NUM,
 #define OPT_NO_HPET           "no-hpet"
 	OPT_NO_HPET_NUM,
+#define OPT_HUGE_UNLINK        "huge-unlink"
+	OPT_HUGE_UNLINK_NUM,
 #define OPT_NO_HUGE           "no-huge"
 	OPT_NO_HUGE_NUM,
 #define OPT_NO_PCI            "no-pci"
(quoted diff) +0 -0

b/lib/librte_eal/linuxapp/eal/eal_memory.c
index ac2745e..c6f383b 100644

lib/librte_eal/linuxapp/eal/eal_memory.c +12 -0
@@ -348,6 +348,12 @@ map_all_hugepages(struct hugepage_file *hugepg_tbl,
 			|| (hugepage_sz == RTE_PGSIZE_16G)) {
 			hugepg_tbl[i].final_va = hugepg_tbl[i].orig_va;
 			hugepg_tbl[i].orig_va = NULL;
+			if (internal_config.hugepage_unlink &&
+				unlink(hugepg_tbl[i].filepath)) {
+				RTE_LOG(ERR, EAL, "%s(): Removing %s failed: %s\n",
+					__func__, hugepg_tbl[i].filepath, strerror(errno));
+				return -1;
+			}
 			continue;
 		}
 #endif
@@ -407,6 +413,12 @@ map_all_hugepages(struct hugepage_file *hugepg_tbl,
 		}
 		else {
 			hugepg_tbl[i].final_va = virtaddr;
+			if (internal_config.hugepage_unlink &&
+				unlink(hugepg_tbl[i].filepath)) {
+				RTE_LOG(ERR, EAL, "%s(): Removing %s failed: %s\n",
+					__func__, hugepg_tbl[i].filepath, strerror(errno));
+				return -1;
+			}
 		}
 
 		/* set shared flock on the file. */
Signature · 1 line
1.9.1
#2 lore raw
Quoted 61 lines · shesha Sreenivasamurthy (shesha)

When an application using huge-pages crash or exists, the hugetlbfs backing files are not cleaned up. This is a patch to clean those files. There are multi-process DPDK applications that may be benefited by those backing files. Therefore, I have made that configurable so that the application that does not need those backing files can remove them, thus not changing the current default behavior. The application itself can clean it up, however the rationale behind DPDK cleaning it up is, DPDK created it and therefore, it is better it unlinks it.

---
  lib/librte_eal/common/eal_common_options.c | 12 ++++++++++++
  lib/librte_eal/common/eal_internal_cfg.h   |  1 +
  lib/librte_eal/common/eal_options.h        |  2 ++
  lib/librte_eal/linuxapp/eal/eal_memory.c   | 12 ++++++++++++
  4 files changed, 27 insertions(+)
lib/librte_eal/common/eal_common_options.c +11 -0
index 1f459ac..5fe6374 100644
@@ -79,6 +79,7 @@ eal_long_options[] = {
  	{OPT_MASTER_LCORE,      1, NULL, OPT_MASTER_LCORE_NUM     },
  	{OPT_NO_HPET,           0, NULL, OPT_NO_HPET_NUM          },
  	{OPT_NO_HUGE,           0, NULL, OPT_NO_HUGE_NUM          },
+	{OPT_HUGE_UNLINK,       0, NULL, OPT_HUGE_UNLINK_NUM      },
  	{OPT_NO_PCI,            0, NULL, OPT_NO_PCI_NUM           },
  	{OPT_NO_SHCONF,         0, NULL, OPT_NO_SHCONF_NUM        },
  	{OPT_PCI_BLACKLIST,     1, NULL, OPT_PCI_BLACKLIST_NUM    },
@@ -722,6 +723,10 @@ eal_parse_common_option(int opt, const char *optarg,
  		conf->no_hugetlbfs = 1;
  		break;
 
+	case OPT_HUGE_UNLINK_NUM:
+		conf->hugepage_unlink = 1;
+		break;
+
  	case OPT_NO_PCI_NUM:
  		conf->no_pci = 1;
  		break;
@@ -856,6 +861,12 @@ eal_check_common_options(struct internal_config
 *internal_cfg)
  		return -1;
  	}
 
+	if (internal_cfg->no_hugetlbfs && internal_cfg->hugepage_unlink) {
+		RTE_LOG(ERR, EAL, "Option --"OPT_HUGE_UNLINK" cannot "
+			"be specified together with --"OPT_NO_HUGE"\n");
+		return -1;
+	}
+
  	if (rte_eal_devargs_type_count(RTE_DEVTYPE_WHITELISTED_PCI) != 0 &&
  		rte_eal_devargs_type_count(RTE_DEVTYPE_BLACKLISTED_PCI) != 0) {

RTE_LOG(ERR, EAL, "Options blacklist (-b) and whitelist (-w) "

lib/librte_eal/common/eal_common_options.c +1 -0
@@ -906,6 +917,7 @@ eal_common_usage(void)
  	       "  -h, --help          This help\n"
  	       "\nEAL options for DEBUG use only:\n"
  	       "  --"OPT_NO_HUGE"           Use malloc instead of hugetlbfs\n"
+	       "  --"OPT_HUGE_UNLINK"       Unlink hugepage backing file after
Quoted 1 line

initalization\n"

The line above (and a couple more in the patch) is getting wrapped, causing checkpatch to report errors and git failing to apply the patch.

Quoted 52 lines
  	       "  --"OPT_NO_PCI"            Disable PCI\n"
  	       "  --"OPT_NO_HPET"           Disable HPET\n"
  	       "  --"OPT_NO_SHCONF"         No shared config (mmap'd files)\n"
lib/librte_eal/common/eal_internal_cfg.h +1 -0
index e2ecb0d..84b075f 100644
@@ -64,6 +64,7 @@ struct internal_config {
  	volatile unsigned force_nchannel; /**< force number of channels */
  	volatile unsigned force_nrank;    /**< force number of ranks */
  	volatile unsigned no_hugetlbfs;   /**< true to disable hugetlbfs */
+	volatile unsigned hugepage_unlink; /** < true to unlink backing files */
  	volatile unsigned xen_dom0_support; /**< support app running on Xen

Dom0*/
volatile unsigned no_pci; /**< true to disable PCI */
volatile unsigned no_hpet; /**< true to disable HPET */

lib/librte_eal/common/eal_options.h +2 -0
index f6714d9..745f38c 100644
@@ -63,6 +63,8 @@ enum {
  	OPT_PROC_TYPE_NUM,
  #define OPT_NO_HPET           "no-hpet"
  	OPT_NO_HPET_NUM,
+#define OPT_HUGE_UNLINK        "huge-unlink"
+	OPT_HUGE_UNLINK_NUM,
  #define OPT_NO_HUGE           "no-huge"
  	OPT_NO_HUGE_NUM,
  #define OPT_NO_PCI            "no-pci"
lib/librte_eal/linuxapp/eal/eal_memory.c +6 -0
index ac2745e..c6f383b 100644
@@ -348,6 +348,12 @@ map_all_hugepages(struct hugepage_file *hugepg_tbl,
  			|| (hugepage_sz == RTE_PGSIZE_16G)) {
  			hugepg_tbl[i].final_va = hugepg_tbl[i].orig_va;
  			hugepg_tbl[i].orig_va = NULL;
+			if (internal_config.hugepage_unlink &&
+				unlink(hugepg_tbl[i].filepath)) {
+				RTE_LOG(ERR, EAL, "%s(): Removing %s failed: %s\n",
+					__func__, hugepg_tbl[i].filepath, strerror(errno));
+				return -1;
+			}
  			continue;
  		}
  #endif
@@ -407,6 +413,12 @@ map_all_hugepages(struct hugepage_file *hugepg_tbl,
  		}
  		else {

lib/librte_eal/linuxapp/eal/eal_memory.c map_all_hugepages(struct hugepage_file *hugepg_tbl, · line 424

Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_memory.c +6 -0
  			hugepg_tbl[i].final_va = virtaddr;
+			if (internal_config.hugepage_unlink &&
+				unlink(hugepg_tbl[i].filepath)) {
+				RTE_LOG(ERR, EAL, "%s(): Removing %s failed: %s\n",
+					__func__, hugepg_tbl[i].filepath, strerror(errno));
+				return -1;
+			}
  		}
 
  		/* set shared flock on the file. */

Current patch does not work when using -m or --socket-mem. (detailed comments in http://dpdk.org/ml/archives/dev/2015-October/025746.html)

Sergio