[v3,6/8] mem: add support for hugepage-unlink mode
Checks
Commit Message
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>
---
Notes:
v1->v2:
- Move check for hugepage unlink into this patch, to be
consistent with commit message
RFC->v1:
- Use --huge-unlink only
RFC->v1:
- Use --huge-unlink only
lib/librte_eal/common/eal_common_options.c | 6 ++++++
lib/librte_eal/linuxapp/eal/eal_memalloc.c | 16 +++++++++++++++-
2 files changed, 21 insertions(+), 1 deletion(-)
@@ -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;
}
@@ -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 @@ alloc_seg(struct rte_memseg *ms, void *addr, int socket_id,
/* 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.