From: Anatoly Burakov <anatoly.burakov@intel.com>
To: dev@dpdk.org
Cc: david.marchand@redhat.com, thomas@monjalon.net,
maxime.coquelin@redhat.com
Subject: [dpdk-dev] [PATCH v2 1/2] memalloc: refactor segment resizing code
Date: Fri, 29 Mar 2019 17:55:28 +0000 [thread overview]
Message-ID: <728c19fa1ed26cdd319fe65e23c4058363dbf2dd.1553882085.git.anatoly.burakov@intel.com> (raw)
In-Reply-To: <07f664c33ddedaa5dcfe82ecb97d931e68b7e33a.1550855529.git.anatoly.burakov@intel.com>
Currently, segment resizing code sits in one giant function which
handles both in-memory and regular modes. Split them up into
individual functions.
Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
lib/librte_eal/linux/eal/eal_memalloc.c | 72 +++++++++++++++----------
1 file changed, 45 insertions(+), 27 deletions(-)
diff --git a/lib/librte_eal/linux/eal/eal_memalloc.c b/lib/librte_eal/linux/eal/eal_memalloc.c
index b6fb183db..e90fe6c95 100644
--- a/lib/librte_eal/linux/eal/eal_memalloc.c
+++ b/lib/librte_eal/linux/eal/eal_memalloc.c
@@ -425,37 +425,37 @@ get_seg_fd(char *path, int buflen, struct hugepage_info *hi,
}
static int
-resize_hugefile(int fd, char *path, int list_idx, int seg_idx,
+resize_hugefile_in_memory(int fd, int list_idx, uint64_t fa_offset,
+ uint64_t page_sz, bool grow)
+{
+ int flags = grow ? 0 : FALLOC_FL_PUNCH_HOLE |
+ FALLOC_FL_KEEP_SIZE;
+ int ret;
+
+ /* grow or shrink the file */
+ ret = fallocate(fd, flags, fa_offset, page_sz);
+
+ if (ret < 0) {
+ RTE_LOG(DEBUG, EAL, "%s(): fallocate() failed: %s\n",
+ __func__,
+ strerror(errno));
+ return -1;
+ }
+ /* increase/decrease total segment count */
+ fd_list[list_idx].count += (grow ? 1 : -1);
+ if (!grow && fd_list[list_idx].count == 0) {
+ close(fd_list[list_idx].memseg_list_fd);
+ fd_list[list_idx].memseg_list_fd = -1;
+ }
+ return 0;
+}
+
+static int
+resize_hugefile_in_filesystem(int fd, char *path, int list_idx, int seg_idx,
uint64_t fa_offset, uint64_t page_sz, bool grow)
{
bool again = false;
- /* in-memory mode is a special case, because we don't need to perform
- * any locking, and we can be sure that fallocate() is supported.
- */
- if (internal_config.in_memory) {
- int flags = grow ? 0 : FALLOC_FL_PUNCH_HOLE |
- FALLOC_FL_KEEP_SIZE;
- int ret;
-
- /* grow or shrink the file */
- ret = fallocate(fd, flags, fa_offset, page_sz);
-
- if (ret < 0) {
- RTE_LOG(DEBUG, EAL, "%s(): fallocate() failed: %s\n",
- __func__,
- strerror(errno));
- return -1;
- }
- /* increase/decrease total segment count */
- fd_list[list_idx].count += (grow ? 1 : -1);
- if (!grow && fd_list[list_idx].count == 0) {
- close(fd_list[list_idx].memseg_list_fd);
- fd_list[list_idx].memseg_list_fd = -1;
- }
- return 0;
- }
-
do {
if (fallocate_supported == 0) {
/* we cannot deallocate memory if fallocate() is not
@@ -583,9 +583,27 @@ resize_hugefile(int fd, char *path, int list_idx, int seg_idx,
}
}
} while (again);
+
return 0;
}
+
+static int
+resize_hugefile(int fd, char *path, int list_idx, int seg_idx,
+ uint64_t fa_offset, uint64_t page_sz, bool grow)
+{
+
+ /* in-memory mode is a special case, because we don't need to perform
+ * any locking, and we can be sure that fallocate() is supported.
+ */
+ if (internal_config.in_memory)
+ return resize_hugefile_in_memory(fd, list_idx, fa_offset,
+ page_sz, grow);
+
+ return resize_hugefile_in_filesystem(fd, path, list_idx, seg_idx,
+ fa_offset, page_sz, grow);
+}
+
static int
alloc_seg(struct rte_memseg *ms, void *addr, int socket_id,
struct hugepage_info *hi, unsigned int list_idx,
--
2.17.1
next prev parent reply other threads:[~2019-03-29 17:55 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-22 17:12 [dpdk-dev] [PATCH] eal: add option to not store segment fd's Anatoly Burakov
2019-03-29 9:50 ` David Marchand
2019-03-29 9:50 ` David Marchand
2019-03-29 10:33 ` Burakov, Anatoly
2019-03-29 10:33 ` Burakov, Anatoly
2019-03-29 11:34 ` Thomas Monjalon
2019-03-29 11:34 ` Thomas Monjalon
2019-03-29 12:05 ` Burakov, Anatoly
2019-03-29 12:05 ` Burakov, Anatoly
2019-03-29 12:40 ` Thomas Monjalon
2019-03-29 12:40 ` Thomas Monjalon
2019-03-29 13:24 ` Burakov, Anatoly
2019-03-29 13:24 ` Burakov, Anatoly
2019-03-29 13:34 ` Thomas Monjalon
2019-03-29 13:34 ` Thomas Monjalon
2019-03-29 14:21 ` Burakov, Anatoly
2019-03-29 14:21 ` Burakov, Anatoly
2019-03-29 13:35 ` Maxime Coquelin
2019-03-29 13:35 ` Maxime Coquelin
2019-03-29 17:55 ` Anatoly Burakov [this message]
2019-03-29 17:55 ` [dpdk-dev] [PATCH v2 1/2] memalloc: refactor segment resizing code Anatoly Burakov
2019-03-29 17:55 ` [dpdk-dev] [PATCH v2 2/2] memalloc: do not use lockfiles for single file segments mode Anatoly Burakov
2019-03-29 17:55 ` Anatoly Burakov
2019-04-02 14:08 ` Thomas Monjalon
2019-04-02 14:08 ` Thomas Monjalon
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=728c19fa1ed26cdd319fe65e23c4058363dbf2dd.1553882085.git.anatoly.burakov@intel.com \
--to=anatoly.burakov@intel.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=maxime.coquelin@redhat.com \
--cc=thomas@monjalon.net \
/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).