DPDK patches and discussions
 help / color / mirror / Atom feed
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 4/8] memalloc: rename lock list to fd list
Date: Thu, 23 Aug 2018 17:59:51 +0100	[thread overview]
Message-ID: <30b0acc36d64ff3994dd1741a444a50e58613ff6.1535041359.git.anatoly.burakov@intel.com> (raw)
In-Reply-To: <cover.1535041359.git.anatoly.burakov@intel.com>
In-Reply-To: <cover.1535041359.git.anatoly.burakov@intel.com>

Previously, we were only using lock lists to store per-page lock fd's
because we cannot use modern fcntl() file description locks to lock
parts of the page in single file segments mode.

Now, we will be using this list to store either lock fd's (along with
memseg list fd) in single file segments mode, or per-page fd's (and set
memseg list fd to -1), so rename the list accordingly.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 lib/librte_eal/linuxapp/eal/eal_memalloc.c | 66 ++++++++++++----------
 1 file changed, 37 insertions(+), 29 deletions(-)

diff --git a/lib/librte_eal/linuxapp/eal/eal_memalloc.c b/lib/librte_eal/linuxapp/eal/eal_memalloc.c
index aa95551a8..14bc5dce9 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memalloc.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memalloc.c
@@ -57,25 +57,33 @@ const int anonymous_hugepages_supported =
  */
 static int fallocate_supported = -1; /* unknown */
 
-/* for single-file segments, we need some kind of mechanism to keep track of
+/*
+ * we have two modes - single file segments, and file-per-page mode.
+ *
+ * for single-file segments, we need some kind of mechanism to keep track of
  * which hugepages can be freed back to the system, and which cannot. we cannot
  * use flock() because they don't allow locking parts of a file, and we cannot
  * use fcntl() due to issues with their semantics, so we will have to rely on a
- * bunch of lockfiles for each page.
+ * bunch of lockfiles for each page. so, we will use 'fds' array to keep track
+ * of per-page lockfiles. we will store the actual segment list fd in the
+ * 'memseg_list_fd' field.
+ *
+ * for file-per-page mode, each page will have its own fd, so 'memseg_list_fd'
+ * will be invalid (set to -1), and we'll use 'fds' to keep track of page fd's.
  *
  * we cannot know how many pages a system will have in advance, but we do know
  * that they come in lists, and we know lengths of these lists. so, simply store
  * a malloc'd array of fd's indexed by list and segment index.
  *
  * they will be initialized at startup, and filled as we allocate/deallocate
- * segments. also, use this to track memseg list proper fd.
+ * segments.
  */
 static struct {
 	int *fds; /**< dynamically allocated array of segment lock fd's */
 	int memseg_list_fd; /**< memseg list fd */
 	int len; /**< total length of the array */
 	int count; /**< entries used in an array */
-} lock_fds[RTE_MAX_MEMSEG_LISTS];
+} fd_list[RTE_MAX_MEMSEG_LISTS];
 
 /** local copy of a memory map, used to synchronize memory hotplug in MP */
 static struct rte_memseg_list local_memsegs[RTE_MAX_MEMSEG_LISTS];
@@ -209,12 +217,12 @@ static int get_segment_lock_fd(int list_idx, int seg_idx)
 	char path[PATH_MAX] = {0};
 	int fd;
 
-	if (list_idx < 0 || list_idx >= (int)RTE_DIM(lock_fds))
+	if (list_idx < 0 || list_idx >= (int)RTE_DIM(fd_list))
 		return -1;
-	if (seg_idx < 0 || seg_idx >= lock_fds[list_idx].len)
+	if (seg_idx < 0 || seg_idx >= fd_list[list_idx].len)
 		return -1;
 
-	fd = lock_fds[list_idx].fds[seg_idx];
+	fd = fd_list[list_idx].fds[seg_idx];
 	/* does this lock already exist? */
 	if (fd >= 0)
 		return fd;
@@ -236,8 +244,8 @@ static int get_segment_lock_fd(int list_idx, int seg_idx)
 		return -1;
 	}
 	/* store it for future reference */
-	lock_fds[list_idx].fds[seg_idx] = fd;
-	lock_fds[list_idx].count++;
+	fd_list[list_idx].fds[seg_idx] = fd;
+	fd_list[list_idx].count++;
 	return fd;
 }
 
@@ -245,12 +253,12 @@ static int unlock_segment(int list_idx, int seg_idx)
 {
 	int fd, ret;
 
-	if (list_idx < 0 || list_idx >= (int)RTE_DIM(lock_fds))
+	if (list_idx < 0 || list_idx >= (int)RTE_DIM(fd_list))
 		return -1;
-	if (seg_idx < 0 || seg_idx >= lock_fds[list_idx].len)
+	if (seg_idx < 0 || seg_idx >= fd_list[list_idx].len)
 		return -1;
 
-	fd = lock_fds[list_idx].fds[seg_idx];
+	fd = fd_list[list_idx].fds[seg_idx];
 
 	/* upgrade lock to exclusive to see if we can remove the lockfile */
 	ret = lock(fd, LOCK_EX);
@@ -270,8 +278,8 @@ static int unlock_segment(int list_idx, int seg_idx)
 	 * and remove it from list anyway.
 	 */
 	close(fd);
-	lock_fds[list_idx].fds[seg_idx] = -1;
-	lock_fds[list_idx].count--;
+	fd_list[list_idx].fds[seg_idx] = -1;
+	fd_list[list_idx].count--;
 
 	if (ret < 0)
 		return -1;
@@ -288,7 +296,7 @@ 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);
 
-		fd = lock_fds[list_idx].memseg_list_fd;
+		fd = fd_list[list_idx].memseg_list_fd;
 
 		if (fd < 0) {
 			fd = open(path, O_CREAT | O_RDWR, 0600);
@@ -304,7 +312,7 @@ get_seg_fd(char *path, int buflen, struct hugepage_info *hi,
 				close(fd);
 				return -1;
 			}
-			lock_fds[list_idx].memseg_list_fd = fd;
+			fd_list[list_idx].memseg_list_fd = fd;
 		}
 	} else {
 		/* create a hugepage file path */
@@ -410,9 +418,9 @@ resize_hugefile(int fd, char *path, int list_idx, int seg_idx,
 				 * page file fd, so that one of the processes
 				 * could then delete the file after shrinking.
 				 */
-				if (ret < 1 && lock_fds[list_idx].count == 0) {
+				if (ret < 1 && fd_list[list_idx].count == 0) {
 					close(fd);
-					lock_fds[list_idx].memseg_list_fd = -1;
+					fd_list[list_idx].memseg_list_fd = -1;
 				}
 
 				if (ret < 0) {
@@ -448,13 +456,13 @@ resize_hugefile(int fd, char *path, int list_idx, int seg_idx,
 				 * more segments active in this segment list,
 				 * and remove the file if there aren't.
 				 */
-				if (lock_fds[list_idx].count == 0) {
+				if (fd_list[list_idx].count == 0) {
 					if (unlink(path))
 						RTE_LOG(ERR, EAL, "%s(): unlinking '%s' failed: %s\n",
 							__func__, path,
 							strerror(errno));
 					close(fd);
-					lock_fds[list_idx].memseg_list_fd = -1;
+					fd_list[list_idx].memseg_list_fd = -1;
 				}
 			}
 		}
@@ -1319,7 +1327,7 @@ secondary_msl_create_walk(const struct rte_memseg_list *msl,
 }
 
 static int
-secondary_lock_list_create_walk(const struct rte_memseg_list *msl,
+fd_list_create_walk(const struct rte_memseg_list *msl,
 		void *arg __rte_unused)
 {
 	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
@@ -1330,20 +1338,20 @@ secondary_lock_list_create_walk(const struct rte_memseg_list *msl,
 	msl_idx = msl - mcfg->memsegs;
 	len = msl->memseg_arr.len;
 
-	/* ensure we have space to store lock fd per each possible segment */
+	/* ensure we have space to store fd per each possible segment */
 	data = malloc(sizeof(int) * len);
 	if (data == NULL) {
-		RTE_LOG(ERR, EAL, "Unable to allocate space for lock descriptors\n");
+		RTE_LOG(ERR, EAL, "Unable to allocate space for file descriptors\n");
 		return -1;
 	}
 	/* set all fd's as invalid */
 	for (i = 0; i < len; i++)
 		data[i] = -1;
 
-	lock_fds[msl_idx].fds = data;
-	lock_fds[msl_idx].len = len;
-	lock_fds[msl_idx].count = 0;
-	lock_fds[msl_idx].memseg_list_fd = -1;
+	fd_list[msl_idx].fds = data;
+	fd_list[msl_idx].len = len;
+	fd_list[msl_idx].count = 0;
+	fd_list[msl_idx].memseg_list_fd = -1;
 
 	return 0;
 }
@@ -1355,9 +1363,9 @@ eal_memalloc_init(void)
 		if (rte_memseg_list_walk(secondary_msl_create_walk, NULL) < 0)
 			return -1;
 
-	/* initialize all of the lock fd lists */
+	/* initialize all of the fd lists */
 	if (internal_config.single_file_segments)
-		if (rte_memseg_list_walk(secondary_lock_list_create_walk, NULL))
+		if (rte_memseg_list_walk(fd_list_create_walk, NULL))
 			return -1;
 	return 0;
 }
-- 
2.17.1

  parent reply	other threads:[~2018-08-23 16:59 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 ` Anatoly Burakov [this message]
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 ` [dpdk-dev] [PATCH v2 5/9] memalloc: track page fd's in non-single file mode Anatoly Burakov
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=30b0acc36d64ff3994dd1741a444a50e58613ff6.1535041359.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).