DPDK patches and discussions
 help / color / mirror / Atom feed
From: Anatoly Burakov <anatoly.burakov@intel.com>
To: dev@dpdk.org
Cc: reshma.pattan@intel.com
Subject: [dpdk-dev] [PATCH v3 2/3] mem: improve memory preallocation on 32-bit
Date: Tue, 24 Apr 2018 11:19:23 +0100	[thread overview]
Message-ID: <9bd2877ea94d32f99ea6d17afb6e5f16f4340649.1524564892.git.anatoly.burakov@intel.com> (raw)
In-Reply-To: <c8375f94e07e2ed99090eaefb4f4c4bb657c5206.1524564892.git.anatoly.burakov@intel.com>
In-Reply-To: <c8375f94e07e2ed99090eaefb4f4c4bb657c5206.1524237907.git.anatoly.burakov@intel.com>

Previously, if we couldn't preallocate VA space on 32-bit for
one page size, we simply bailed out, even though we could've
tried allocating VA space with other page sizes.

For example, if user had both 1G and 2M pages enabled, and
has asked DPDK to allocate memory on both sockets, DPDK
would've tried to allocate VA space for 1x1G page on both
sockets, failed and never tried again, even though it
could've allocated the same 1G of VA space for 512x2M pages.

Fix this by retrying with different page sizes if VA space
reservation failed.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 lib/librte_eal/common/eal_common_memory.c | 42 +++++++++++++++++++++++++------
 1 file changed, 35 insertions(+), 7 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_memory.c b/lib/librte_eal/common/eal_common_memory.c
index c0d4673..d819abe 100644
--- a/lib/librte_eal/common/eal_common_memory.c
+++ b/lib/librte_eal/common/eal_common_memory.c
@@ -142,6 +142,17 @@ get_mem_amount(uint64_t page_sz, uint64_t max_mem)
 }
 
 static int
+free_memseg_list(struct rte_memseg_list *msl)
+{
+	if (rte_fbarray_destroy(&msl->memseg_arr)) {
+		RTE_LOG(ERR, EAL, "Cannot destroy memseg list\n");
+		return -1;
+	}
+	memset(msl, 0, sizeof(*msl));
+	return 0;
+}
+
+static int
 alloc_memseg_list(struct rte_memseg_list *msl, uint64_t page_sz,
 		uint64_t max_mem, int socket_id, int type_msl_idx)
 {
@@ -339,24 +350,41 @@ memseg_primary_init_32(void)
 					return -1;
 				}
 
-				msl = &mcfg->memsegs[msl_idx++];
+				msl = &mcfg->memsegs[msl_idx];
 
 				if (alloc_memseg_list(msl, hugepage_sz,
 						max_pagesz_mem, socket_id,
-						type_msl_idx))
+						type_msl_idx)) {
+					/* failing to allocate a memseg list is
+					 * a serious error.
+					 */
+					RTE_LOG(ERR, EAL, "Cannot allocate memseg list\n");
 					return -1;
+				}
+
+				if (alloc_va_space(msl)) {
+					/* if we couldn't allocate VA space, we
+					 * can try with smaller page sizes.
+					 */
+					RTE_LOG(ERR, EAL, "Cannot allocate VA space for memseg list, retrying with different page size\n");
+					/* deallocate memseg list */
+					if (free_memseg_list(msl))
+						return -1;
+					break;
+				}
 
 				total_segs += msl->memseg_arr.len;
 				cur_pagesz_mem = total_segs * hugepage_sz;
 				type_msl_idx++;
-
-				if (alloc_va_space(msl)) {
-					RTE_LOG(ERR, EAL, "Cannot allocate VA space for memseg list\n");
-					return -1;
-				}
+				msl_idx++;
 			}
 			cur_socket_mem += cur_pagesz_mem;
 		}
+		if (cur_socket_mem == 0) {
+			RTE_LOG(ERR, EAL, "Cannot allocate VA space on socket %u\n",
+				socket_id);
+			return -1;
+		}
 	}
 
 	return 0;
-- 
2.7.4

  parent reply	other threads:[~2018-04-24 10:19 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-20 14:41 [dpdk-dev] [PATCH 1/3] mem: fix 32-bit memory upper limit for non-legacy mode Anatoly Burakov
2018-04-20 14:41 ` [dpdk-dev] [PATCH 2/3] mem: improve memory preallocation on 32-bit Anatoly Burakov
2018-04-20 14:41 ` [dpdk-dev] [PATCH 3/3] mem: improve autodetection of hugepage counts " Anatoly Burakov
2018-04-20 15:12   ` Burakov, Anatoly
2018-04-20 15:25 ` [dpdk-dev] [PATCH v2 1/3] mem: fix 32-bit memory upper limit for non-legacy mode Anatoly Burakov
2018-04-24 10:19   ` [dpdk-dev] [PATCH v3 " Anatoly Burakov
2018-04-25 13:26     ` Pattan, Reshma
2018-04-24 10:19   ` Anatoly Burakov [this message]
2018-04-25 13:27     ` [dpdk-dev] [PATCH v3 2/3] mem: improve memory preallocation on 32-bit Pattan, Reshma
2018-04-24 10:19   ` [dpdk-dev] [PATCH v3 3/3] mem: improve autodetection of hugepage counts " Anatoly Burakov
2018-04-25 13:28     ` Pattan, Reshma
2018-04-27 21:47       ` Thomas Monjalon
2018-04-20 15:25 ` [dpdk-dev] [PATCH v2 2/3] mem: improve memory preallocation " Anatoly Burakov
2018-04-20 15:25 ` [dpdk-dev] [PATCH v2 3/3] mem: improve autodetection of hugepage counts " 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=9bd2877ea94d32f99ea6d17afb6e5f16f4340649.1524564892.git.anatoly.burakov@intel.com \
    --to=anatoly.burakov@intel.com \
    --cc=dev@dpdk.org \
    --cc=reshma.pattan@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).