[dpdk-dev] [RFC 05/10] mem: add support for no-shared-files mode

Anatoly Burakov anatoly.burakov at intel.com
Thu May 31 16:32:28 CEST 2018


Unlink hugepages after creating them, to honor the no shared files mode.
We cannot resize non-existing files, so make single file segments
explicitly unsupported.

Signed-off-by: Anatoly Burakov <anatoly.burakov at intel.com>
---
 lib/librte_eal/linuxapp/eal/eal.c          |  9 +++++++++
 lib/librte_eal/linuxapp/eal/eal_memalloc.c | 23 +++++++++++++++++++---
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index 32ca25dc2..7904f813e 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -690,6 +690,15 @@ eal_parse_args(int argc, char **argv)
 		goto out;
 	}
 
+	if (internal_config.single_file_segments &&
+			internal_config.no_shared_files) {
+		RTE_LOG(ERR, EAL, "Option --"OPT_SINGLE_FILE_SEGMENTS" is "
+			"incompatible with --"OPT_NO_SHARED_FILES"\n");
+		eal_usage(prgname);
+		ret = -1;
+		goto out;
+	}
+
 	if (optind >= 0)
 		argv[optind-1] = prgname;
 	ret = optind-1;
diff --git a/lib/librte_eal/linuxapp/eal/eal_memalloc.c b/lib/librte_eal/linuxapp/eal/eal_memalloc.c
index 8c11f98c9..f57d307dd 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memalloc.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memalloc.c
@@ -512,6 +512,13 @@ alloc_seg(struct rte_memseg *ms, void *addr, int socket_id,
 				__func__, strerror(errno));
 			goto resized;
 		}
+		if (internal_config.no_shared_files) {
+			if (unlink(path)) {
+				RTE_LOG(DEBUG, EAL, "%s(): unlink() failed: %s\n",
+					__func__, strerror(errno));
+				goto resized;
+			}
+		}
 	}
 
 	/*
@@ -562,8 +569,11 @@ alloc_seg(struct rte_memseg *ms, void *addr, int socket_id,
 			(unsigned int)(alloc_sz >> 20));
 		goto mapped;
 	}
-	/* for non-single file segments, we can close fd here */
-	if (!internal_config.single_file_segments)
+	/* for non-single file segments or no shared files mode, we can close fd
+	 * here
+	 */
+	if (!internal_config.single_file_segments ||
+			internal_config.no_shared_files)
 		close(fd);
 
 	/* we need to trigger a write to the page to enforce page fault and
@@ -592,7 +602,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.no_shared_files == 0 &&
+				lock(fd, LOCK_EX) == 1)
 			unlink(path);
 		close(fd);
 	}
@@ -617,6 +628,12 @@ free_seg(struct rte_memseg *ms, struct hugepage_info *hi,
 		return -1;
 	}
 
+	/* if we're no in shared files mode, nothing needs to be done */
+	if (internal_config.no_shared_files) {
+		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.
-- 
2.17.0


More information about the dev mailing list