eal: refactor --huge-unlink storage
authorDmitry Kozlyuk <dkozlyuk@nvidia.com>
Thu, 3 Feb 2022 18:13:34 +0000 (20:13 +0200)
committerDavid Marchand <david.marchand@redhat.com>
Tue, 8 Feb 2022 20:32:53 +0000 (21:32 +0100)
In preparation to extend --huge-unlink option semantics
refactor how it is stored in the internal configuration.
It makes future changes more isolated.

Signed-off-by: Dmitry Kozlyuk <dkozlyuk@nvidia.com>
Acked-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
lib/eal/common/eal_common_options.c
lib/eal/common/eal_internal_cfg.h
lib/eal/linux/eal_memalloc.c
lib/eal/linux/eal_memory.c

index 1cfdd75..7520ebd 100644 (file)
@@ -1737,7 +1737,7 @@ eal_parse_common_option(int opt, const char *optarg,
 
        /* long options */
        case OPT_HUGE_UNLINK_NUM:
-               conf->hugepage_unlink = 1;
+               conf->hugepage_file.unlink_before_mapping = true;
                break;
 
        case OPT_NO_HUGE_NUM:
@@ -1766,7 +1766,7 @@ eal_parse_common_option(int opt, const char *optarg,
                conf->in_memory = 1;
                /* in-memory is a superset of noshconf and huge-unlink */
                conf->no_shconf = 1;
-               conf->hugepage_unlink = 1;
+               conf->hugepage_file.unlink_before_mapping = true;
                break;
 
        case OPT_PROC_TYPE_NUM:
@@ -2050,7 +2050,8 @@ eal_check_common_options(struct internal_config *internal_cfg)
                        "be specified together with --"OPT_NO_HUGE"\n");
                return -1;
        }
-       if (internal_cfg->no_hugetlbfs && internal_cfg->hugepage_unlink &&
+       if (internal_cfg->no_hugetlbfs &&
+                       internal_cfg->hugepage_file.unlink_before_mapping &&
                        !internal_cfg->in_memory) {
                RTE_LOG(ERR, EAL, "Option --"OPT_HUGE_UNLINK" cannot "
                        "be specified together with --"OPT_NO_HUGE"\n");
@@ -2061,7 +2062,7 @@ eal_check_common_options(struct internal_config *internal_cfg)
                        " is only supported in non-legacy memory mode\n");
        }
        if (internal_cfg->single_file_segments &&
-                       internal_cfg->hugepage_unlink &&
+                       internal_cfg->hugepage_file.unlink_before_mapping &&
                        !internal_cfg->in_memory) {
                RTE_LOG(ERR, EAL, "Option --"OPT_SINGLE_FILE_SEGMENTS" is "
                        "not compatible with --"OPT_HUGE_UNLINK"\n");
index d6c0470..b5e6942 100644 (file)
@@ -40,6 +40,12 @@ struct simd_bitwidth {
        uint16_t bitwidth; /**< bitwidth value */
 };
 
+/** Hugepage backing files discipline. */
+struct hugepage_file_discipline {
+       /** Unlink files before mapping them to leave no trace in hugetlbfs. */
+       bool unlink_before_mapping;
+};
+
 /**
  * internal configuration
  */
@@ -48,7 +54,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 */
-       unsigned hugepage_unlink;         /**< true to unlink backing files */
+       struct hugepage_file_discipline hugepage_file;
        volatile unsigned no_pci;         /**< true to disable PCI */
        volatile unsigned no_hpet;        /**< true to disable HPET */
        volatile unsigned vmware_tsc_map; /**< true to use VMware TSC mapping
index 16b58d8..5f55318 100644 (file)
@@ -564,7 +564,7 @@ alloc_seg(struct rte_memseg *ms, void *addr, int socket_id,
                                        __func__, strerror(errno));
                                goto resized;
                        }
-                       if (internal_conf->hugepage_unlink &&
+                       if (internal_conf->hugepage_file.unlink_before_mapping &&
                                        !internal_conf->in_memory) {
                                if (unlink(path)) {
                                        RTE_LOG(DEBUG, EAL, "%s(): unlink() failed: %s\n",
@@ -697,7 +697,7 @@ resized:
                        close_hugefile(fd, path, list_idx);
        } else {
                /* only remove file if we can take out a write lock */
-               if (internal_conf->hugepage_unlink == 0 &&
+               if (!internal_conf->hugepage_file.unlink_before_mapping &&
                                internal_conf->in_memory == 0 &&
                                lock(fd, LOCK_EX) == 1)
                        unlink(path);
@@ -756,7 +756,8 @@ free_seg(struct rte_memseg *ms, struct hugepage_info *hi,
                /* if we're able to take out a write lock, we're the last one
                 * holding onto this page.
                 */
-               if (!internal_conf->in_memory && !internal_conf->hugepage_unlink) {
+               if (!internal_conf->in_memory &&
+                               !internal_conf->hugepage_file.unlink_before_mapping) {
                        ret = lock(fd, LOCK_EX);
                        if (ret >= 0) {
                                /* no one else is using this page */
index 03a4f2d..83eec07 100644 (file)
@@ -1428,7 +1428,7 @@ eal_legacy_hugepage_init(void)
        }
 
        /* free the hugepage backing files */
-       if (internal_conf->hugepage_unlink &&
+       if (internal_conf->hugepage_file.unlink_before_mapping &&
                unlink_hugepage_files(tmp_hp, internal_conf->num_hugepage_sizes) < 0) {
                RTE_LOG(ERR, EAL, "Unlinking hugepage files failed!\n");
                goto fail;