mem: support --huge-unlink mode
authorAnatoly Burakov <anatoly.burakov@intel.com>
Fri, 13 Jul 2018 12:48:02 +0000 (13:48 +0100)
committerThomas Monjalon <thomas@monjalon.net>
Fri, 13 Jul 2018 13:34:17 +0000 (15:34 +0200)
Unlink hugepages after creating them, to honor the hugepage-unlink mode.
We cannot resize non-existing files, so make single file segments
explicitly unsupported.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
lib/librte_eal/common/eal_common_options.c
lib/librte_eal/linuxapp/eal/eal_memalloc.c

index 45ea01a..df5d536 100644 (file)
@@ -1332,6 +1332,12 @@ eal_check_common_options(struct internal_config *internal_cfg)
                        " is only supported in non-legacy memory mode\n");
                return -1;
        }
+       if (internal_cfg->single_file_segments &&
+                       internal_cfg->hugepage_unlink) {
+               RTE_LOG(ERR, EAL, "Option --"OPT_SINGLE_FILE_SEGMENTS" is "
+                       "not compatible with --"OPT_HUGE_UNLINK"\n");
+               return -1;
+       }
 
        return 0;
 }
index 69604f8..d610923 100644 (file)
@@ -489,6 +489,13 @@ alloc_seg(struct rte_memseg *ms, void *addr, int socket_id,
                                __func__, strerror(errno));
                        goto resized;
                }
+               if (internal_config.hugepage_unlink) {
+                       if (unlink(path)) {
+                               RTE_LOG(DEBUG, EAL, "%s(): unlink() failed: %s\n",
+                                       __func__, strerror(errno));
+                               goto resized;
+                       }
+               }
        }
 
        /*
@@ -587,7 +594,8 @@ resized:
                /* ignore failure, can't make it any worse */
        } else {
                /* only remove file if we can take out a write lock */
-               if (lock(fd, LOCK_EX) == 1)
+               if (internal_config.hugepage_unlink == 0 &&
+                               lock(fd, LOCK_EX) == 1)
                        unlink(path);
                close(fd);
        }
@@ -612,6 +620,12 @@ free_seg(struct rte_memseg *ms, struct hugepage_info *hi,
                return -1;
        }
 
+       /* if we've already unlinked the page, nothing needs to be done */
+       if (internal_config.hugepage_unlink) {
+               memset(ms, 0, sizeof(*ms));
+               return 0;
+       }
+
        /* if we are not in single file segments mode, we're going to unmap the
         * segment and thus drop the lock on original fd, but hugepage dir is
         * now locked so we can take out another one without races.