DPDK patches and discussions
 help / color / mirror / Atom feed
From: Roy Shterman <roy.shterman@vastdata.com>
To: anatoly.burakov@intel.com
Cc: dev@dpdk.org, yuval@vastdata.com, aviv.bendavid@vastdata.com,
	Roy Shterman <roy.shterman@vastdata.com>
Subject: [dpdk-dev] [PATCH] mem: fix free segment when using huge-unlink option
Date: Mon, 22 Feb 2021 12:41:31 +0200
Message-ID: <20210222104131.11979-1-roy.shterman@vastdata.com> (raw)

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 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 falsly failing rte_malloc()
although we have hugepages available.

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

Signed-off-by: Roy Shterman <roy.shterman@vastdata.com>
---
 lib/librte_eal/linux/eal_memalloc.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/lib/librte_eal/linux/eal_memalloc.c b/lib/librte_eal/linux/eal_memalloc.c
index 6dc1b2bae..c590d6043 100644
--- a/lib/librte_eal/linux/eal_memalloc.c
+++ b/lib/librte_eal/linux/eal_memalloc.c
@@ -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();
 
@@ -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;
 	}
@@ -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 */
-- 
2.24.1


             reply	other threads:[~2021-02-23  8:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-22 10:41 Roy Shterman [this message]
2021-02-22 15:53 ` Burakov, Anatoly
2021-02-28 13:21   ` Roy Shterman
2021-03-01 10:44     ` Burakov, Anatoly
2021-03-25 13:34       ` [dpdk-dev] [dpdk-stable] " David Marchand
2021-04-01 11:07 ` [dpdk-dev] " Burakov, Anatoly
2021-04-07  9:09   ` David Marchand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210222104131.11979-1-roy.shterman@vastdata.com \
    --to=roy.shterman@vastdata.com \
    --cc=anatoly.burakov@intel.com \
    --cc=aviv.bendavid@vastdata.com \
    --cc=dev@dpdk.org \
    --cc=yuval@vastdata.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git