[dpdk-dev] [PATCH v3 3/5] memalloc: allow setting up segment list fd's

Anatoly Burakov anatoly.burakov at intel.com
Thu Dec 13 12:43:17 CET 2018


Currently, only segment fd's for multi-file segments are supported,
while for memfd-backed no-huge memory we need single-file segments
mode. Add support for single-file segments in the internal API.

Signed-off-by: Anatoly Burakov <anatoly.burakov at intel.com>
Acked-by: Tiwei Bie <tiwei.bie at intel.com>
---

Notes:
    v2:
    - Add missing fd list allocation on setting segment
      list fd

 lib/librte_eal/bsdapp/eal/eal_memalloc.c   |  6 +++++
 lib/librte_eal/common/eal_memalloc.h       |  4 ++++
 lib/librte_eal/linuxapp/eal/eal_memalloc.c | 26 ++++++++++++++++++++++
 3 files changed, 36 insertions(+)

diff --git a/lib/librte_eal/bsdapp/eal/eal_memalloc.c b/lib/librte_eal/bsdapp/eal/eal_memalloc.c
index a5847f0bd..6893448db 100644
--- a/lib/librte_eal/bsdapp/eal/eal_memalloc.c
+++ b/lib/librte_eal/bsdapp/eal/eal_memalloc.c
@@ -61,6 +61,12 @@ eal_memalloc_set_seg_fd(int list_idx __rte_unused, int seg_idx __rte_unused,
 	return -ENOTSUP;
 }
 
+int
+eal_memalloc_set_seg_list_fd(int list_idx __rte_unused, int fd __rte_unused)
+{
+	return -ENOTSUP;
+}
+
 int
 eal_memalloc_get_seg_fd_offset(int list_idx __rte_unused,
 		int seg_idx __rte_unused, size_t *offset __rte_unused)
diff --git a/lib/librte_eal/common/eal_memalloc.h b/lib/librte_eal/common/eal_memalloc.h
index af917c2f9..b96c9c512 100644
--- a/lib/librte_eal/common/eal_memalloc.h
+++ b/lib/librte_eal/common/eal_memalloc.h
@@ -84,6 +84,10 @@ eal_memalloc_get_seg_fd(int list_idx, int seg_idx);
 int
 eal_memalloc_set_seg_fd(int list_idx, int seg_idx, int fd);
 
+/* returns 0 or -errno */
+int
+eal_memalloc_set_seg_list_fd(int list_idx, int fd);
+
 int
 eal_memalloc_get_seg_fd_offset(int list_idx, int seg_idx, size_t *offset);
 
diff --git a/lib/librte_eal/linuxapp/eal/eal_memalloc.c b/lib/librte_eal/linuxapp/eal/eal_memalloc.c
index a93548b8c..eef140b33 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memalloc.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memalloc.c
@@ -1529,6 +1529,10 @@ eal_memalloc_set_seg_fd(int list_idx, int seg_idx, int fd)
 {
 	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
 
+	/* single file segments mode doesn't support individual segment fd's */
+	if (internal_config.single_file_segments)
+		return -ENOTSUP;
+
 	/* if list is not allocated, allocate it */
 	if (fd_list[list_idx].len == 0) {
 		int len = mcfg->memsegs[list_idx].memseg_arr.len;
@@ -1541,6 +1545,28 @@ eal_memalloc_set_seg_fd(int list_idx, int seg_idx, int fd)
 	return 0;
 }
 
+int
+eal_memalloc_set_seg_list_fd(int list_idx, int fd)
+{
+	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+
+	/* non-single file segment mode doesn't support segment list fd's */
+	if (!internal_config.single_file_segments)
+		return -ENOTSUP;
+
+	/* if list is not allocated, allocate it */
+	if (fd_list[list_idx].len == 0) {
+		int len = mcfg->memsegs[list_idx].memseg_arr.len;
+
+		if (alloc_list(list_idx, len) < 0)
+			return -ENOMEM;
+	}
+
+	fd_list[list_idx].memseg_list_fd = fd;
+
+	return 0;
+}
+
 int
 eal_memalloc_get_seg_fd(int list_idx, int seg_idx)
 {
-- 
2.17.1


More information about the dev mailing list