From: Anatoly Burakov <anatoly.burakov@intel.com>
To: dev@dpdk.org
Cc: tiwei.bie@intel.com, ray.kinsella@intel.com,
zhihong.wang@intel.com, maxime.coquelin@redhat.com,
kuralamudhan.ramakrishnan@intel.com
Subject: [dpdk-dev] [PATCH v2 5/9] memalloc: track page fd's in non-single file mode
Date: Tue, 4 Sep 2018 16:01:58 +0100 [thread overview]
Message-ID: <c5ee2a29a7dc920c2e59d4efdd120147aad4e5cb.1536072550.git.anatoly.burakov@intel.com> (raw)
In-Reply-To: <cover.1536072550.git.anatoly.burakov@intel.com>
In-Reply-To: <cover.1536072550.git.anatoly.burakov@intel.com>
Previously, we were only tracking lock file fd's in single-file
segments mode, but did not track fd's in non-single file mode
because we didn't need to (mmap() call still kept the lock). Now
that we are going to expose these fd's to the world, we need to
have access to them, so track them even in non-single file
segments mode.
We don't need to close fd's after mmap() because we're still
tracking them in an fd list. Also, for anonymous hugepages mode,
fd will always be -1 so exit early on error.
Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
lib/librte_eal/linuxapp/eal/eal_memalloc.c | 44 ++++++++++++----------
1 file changed, 25 insertions(+), 19 deletions(-)
diff --git a/lib/librte_eal/linuxapp/eal/eal_memalloc.c b/lib/librte_eal/linuxapp/eal/eal_memalloc.c
index 14bc5dce9..7d536350e 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memalloc.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memalloc.c
@@ -318,18 +318,24 @@ get_seg_fd(char *path, int buflen, struct hugepage_info *hi,
/* create a hugepage file path */
eal_get_hugefile_path(path, buflen, hi->hugedir,
list_idx * RTE_MAX_MEMSEG_PER_LIST + seg_idx);
- fd = open(path, O_CREAT | O_RDWR, 0600);
+
+ fd = fd_list[list_idx].fds[seg_idx];
+
if (fd < 0) {
- RTE_LOG(DEBUG, EAL, "%s(): open failed: %s\n", __func__,
- strerror(errno));
- return -1;
- }
- /* take out a read lock */
- if (lock(fd, LOCK_SH) < 0) {
- RTE_LOG(ERR, EAL, "%s(): lock failed: %s\n",
- __func__, strerror(errno));
- close(fd);
- return -1;
+ fd = open(path, O_CREAT | O_RDWR, 0600);
+ if (fd < 0) {
+ RTE_LOG(DEBUG, EAL, "%s(): open failed: %s\n",
+ __func__, strerror(errno));
+ return -1;
+ }
+ /* take out a read lock */
+ if (lock(fd, LOCK_SH) < 0) {
+ RTE_LOG(ERR, EAL, "%s(): lock failed: %s\n",
+ __func__, strerror(errno));
+ close(fd);
+ return -1;
+ }
+ fd_list[list_idx].fds[seg_idx] = fd;
}
}
return fd;
@@ -601,10 +607,6 @@ alloc_seg(struct rte_memseg *ms, void *addr, int socket_id,
goto mapped;
}
#endif
- /* for non-single file segments that aren't in-memory, we can close fd
- * here */
- if (!internal_config.single_file_segments && !internal_config.in_memory)
- close(fd);
ms->addr = addr;
ms->hugepage_sz = alloc_sz;
@@ -634,7 +636,10 @@ alloc_seg(struct rte_memseg *ms, void *addr, int socket_id,
RTE_LOG(CRIT, EAL, "Can't mmap holes in our virtual address space\n");
}
resized:
- /* in-memory mode will never be single-file-segments mode */
+ /* some codepaths will return negative fd, so exit early */
+ if (fd < 0)
+ return -1;
+
if (internal_config.single_file_segments) {
resize_hugefile(fd, path, list_idx, seg_idx, map_offset,
alloc_sz, false);
@@ -646,6 +651,7 @@ alloc_seg(struct rte_memseg *ms, void *addr, int socket_id,
lock(fd, LOCK_EX) == 1)
unlink(path);
close(fd);
+ fd_list[list_idx].fds[seg_idx] = -1;
}
return -1;
}
@@ -700,6 +706,7 @@ free_seg(struct rte_memseg *ms, struct hugepage_info *hi,
}
/* closing fd will drop the lock */
close(fd);
+ fd_list[list_idx].fds[seg_idx] = -1;
}
memset(ms, 0, sizeof(*ms));
@@ -1364,8 +1371,7 @@ eal_memalloc_init(void)
return -1;
/* initialize all of the fd lists */
- if (internal_config.single_file_segments)
- if (rte_memseg_list_walk(fd_list_create_walk, NULL))
- return -1;
+ if (rte_memseg_list_walk(fd_list_create_walk, NULL))
+ return -1;
return 0;
}
--
2.17.1
next prev parent reply other threads:[~2018-09-04 15:02 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-23 16:59 [dpdk-dev] [PATCH 0/8] Improve running DPDK without hugetlbfs mounpoint Anatoly Burakov
2018-08-23 16:59 ` [dpdk-dev] [PATCH 1/8] fbarray: fix detach in noshconf mode Anatoly Burakov
2018-08-23 16:59 ` [dpdk-dev] [PATCH 2/8] eal: don't allow legacy mode with in-memory mode Anatoly Burakov
2018-08-23 16:59 ` [dpdk-dev] [PATCH 3/8] mem: raise maximum fd limit unconditionally Anatoly Burakov
2018-08-23 16:59 ` [dpdk-dev] [PATCH 4/8] memalloc: rename lock list to fd list Anatoly Burakov
2018-08-23 16:59 ` [dpdk-dev] [PATCH 5/8] memalloc: track page fd's in non-single file mode Anatoly Burakov
2018-08-23 16:59 ` [dpdk-dev] [PATCH 6/8] memalloc: add EAL-internal API to get and set segment fd's Anatoly Burakov
2018-08-23 16:59 ` [dpdk-dev] [PATCH 7/8] mem: add external API to retrieve page fd from EAL Anatoly Burakov
2018-08-23 16:59 ` [dpdk-dev] [PATCH 8/8] mem: support using memfd segments for in-memory mode Anatoly Burakov
2018-08-24 4:39 ` Jerin Jacob
2018-08-24 8:56 ` Burakov, Anatoly
2018-09-04 15:01 ` [dpdk-dev] [PATCH v2 0/9] Improve running DPDK without hugetlbfs mounpoint Anatoly Burakov
2018-09-04 15:15 ` [dpdk-dev] [PATCH v3 " Anatoly Burakov
2018-09-19 13:04 ` Thomas Monjalon
2018-09-19 13:55 ` Burakov, Anatoly
2018-09-19 14:15 ` Thomas Monjalon
2018-09-04 15:15 ` [dpdk-dev] [PATCH v3 1/9] fbarray: fix detach in noshconf mode Anatoly Burakov
2018-09-13 13:00 ` Maxime Coquelin
2018-09-04 15:15 ` [dpdk-dev] [PATCH v3 2/9] eal: don't allow legacy mode with in-memory mode Anatoly Burakov
2018-09-13 13:06 ` Maxime Coquelin
2018-09-17 9:49 ` Burakov, Anatoly
2018-09-04 15:15 ` [dpdk-dev] [PATCH v3 3/9] mem: raise maximum fd limit unconditionally Anatoly Burakov
2018-09-13 13:12 ` Maxime Coquelin
2018-09-04 15:15 ` [dpdk-dev] [PATCH v3 4/9] memalloc: rename lock list to fd list Anatoly Burakov
2018-09-13 15:19 ` Maxime Coquelin
2018-09-04 15:15 ` [dpdk-dev] [PATCH v3 5/9] memalloc: track page fd's in non-single file mode Anatoly Burakov
2018-09-13 15:56 ` Maxime Coquelin
2018-09-04 15:15 ` [dpdk-dev] [PATCH v3 6/9] memalloc: add EAL-internal API to get and set segment fd's Anatoly Burakov
2018-09-14 7:54 ` Maxime Coquelin
2018-09-17 9:53 ` Burakov, Anatoly
2018-09-04 15:15 ` [dpdk-dev] [PATCH v3 7/9] mem: add external API to retrieve page fd from EAL Anatoly Burakov
2018-09-14 8:00 ` Maxime Coquelin
2018-09-04 15:15 ` [dpdk-dev] [PATCH v3 8/9] mem: allow querying offset into segment fd Anatoly Burakov
2018-09-14 7:57 ` Maxime Coquelin
2018-09-04 15:15 ` [dpdk-dev] [PATCH v3 9/9] mem: support using memfd segments for in-memory mode Anatoly Burakov
2018-09-14 8:06 ` Maxime Coquelin
2018-09-04 15:01 ` [dpdk-dev] [PATCH v2 1/9] fbarray: fix detach in noshconf mode Anatoly Burakov
2018-09-04 15:01 ` [dpdk-dev] [PATCH v2 2/9] eal: don't allow legacy mode with in-memory mode Anatoly Burakov
2018-09-04 15:01 ` [dpdk-dev] [PATCH v2 3/9] mem: raise maximum fd limit unconditionally Anatoly Burakov
2018-09-04 15:01 ` [dpdk-dev] [PATCH v2 4/9] memalloc: rename lock list to fd list Anatoly Burakov
2018-09-04 15:01 ` Anatoly Burakov [this message]
2018-09-04 15:01 ` [dpdk-dev] [PATCH v2 6/9] memalloc: add EAL-internal API to get and set segment fd's Anatoly Burakov
2018-09-04 15:02 ` [dpdk-dev] [PATCH v2 7/9] mem: add external API to retrieve page fd from EAL Anatoly Burakov
2018-09-04 15:02 ` [dpdk-dev] [PATCH v2 8/9] mem: allow querying offset into segment fd Anatoly Burakov
2018-09-04 15:02 ` [dpdk-dev] [PATCH v2 9/9] mem: support using memfd segments for in-memory mode Anatoly Burakov
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=c5ee2a29a7dc920c2e59d4efdd120147aad4e5cb.1536072550.git.anatoly.burakov@intel.com \
--to=anatoly.burakov@intel.com \
--cc=dev@dpdk.org \
--cc=kuralamudhan.ramakrishnan@intel.com \
--cc=maxime.coquelin@redhat.com \
--cc=ray.kinsella@intel.com \
--cc=tiwei.bie@intel.com \
--cc=zhihong.wang@intel.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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).