Skip to content

Commit

Permalink
mem: fix freeing segments in --huge-unlink mode
Browse files Browse the repository at this point in the history
[ upstream commit edf20bd ]

When using huge_unlink we unlink the segment right
after allocation. Although we unlink the file we keep
the fd in fd_list so file still exist just the path deleted.
When freeing the hugepage we need to close the fd and assign
it with (-1) in fd_list for the page to be released.

The current flow fails rte_malloc in the following flow when working
with --huge-unlink option:
1. alloc_seg() for segment A -
    We allocate a segment, unlink the path to the segment
    and keep the file descriptor in fd_list.
2. free_seg() for segment A -
    We clear the segment metadata and return - without closing fd
    or assigning (-1) in fd list.
3. alloc_seg() for segment A again -
    We find segment A as available, try to allocate it,
    find the old fd in fd_list try to unlink it
    as part of alloc_seg() but failed because path doesn't exist.

The impact of such error is falsely failing rte_malloc()
although we have hugepages available.

Fixes: d435aad ("mem: support --huge-unlink mode")

Signed-off-by: Roy Shterman <roy.shterman@vastdata.com>
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
  • Loading branch information
Roy Shterman authored and steevenlee committed May 8, 2021
1 parent 8ee0fde commit e0a41b8
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions lib/librte_eal/linux/eal_memalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,6 @@ free_seg(struct rte_memseg *ms, struct hugepage_info *hi,
uint64_t map_offset;
char path[PATH_MAX];
int fd, ret = 0;
bool exit_early;
const struct internal_config *internal_conf =
eal_get_internal_configuration();

Expand All @@ -725,17 +724,8 @@ free_seg(struct rte_memseg *ms, struct hugepage_info *hi,

eal_mem_set_dump(ms->addr, ms->len, false);

exit_early = false;

/* if we're using anonymous hugepages, nothing to be done */
if (internal_conf->in_memory && !memfd_create_supported)
exit_early = true;

/* if we've already unlinked the page, nothing needs to be done */
if (!internal_conf->in_memory && internal_conf->hugepage_unlink)
exit_early = true;

if (exit_early) {
if (internal_conf->in_memory && !memfd_create_supported) {
memset(ms, 0, sizeof(*ms));
return 0;
}
Expand All @@ -761,7 +751,7 @@ 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) {
if (!internal_conf->in_memory && !internal_conf->hugepage_unlink) {
ret = lock(fd, LOCK_EX);
if (ret >= 0) {
/* no one else is using this page */
Expand Down

0 comments on commit e0a41b8

Please sign in to comment.