Skip to content

Commit

Permalink
mem: support --huge-unlink mode
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
anatolyburakov authored and tmonjalo committed Jul 13, 2018
1 parent 5cb4270 commit d435aad
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/librte_eal/common/eal_common_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
16 changes: 15 additions & 1 deletion lib/librte_eal/linuxapp/eal/eal_memalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

/*
Expand Down Expand Up @@ -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);
}
Expand All @@ -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.
Expand Down

0 comments on commit d435aad

Please sign in to comment.