DPDK patches and discussions
 help / color / mirror / Atom feed
From: Anatoly Burakov <anatoly.burakov@intel.com>
To: dev@dpdk.org
Cc: maxime.leroy@6wind.com
Subject: [dpdk-dev] [PATCH 3/3] eal: attempt multiple hugepage allocations at init
Date: Fri, 22 Feb 2019 16:14:03 +0000	[thread overview]
Message-ID: <0a770fb3968c0a270eb57ff7764d6fba4cf6f76d.1550851998.git.anatoly.burakov@intel.com> (raw)
In-Reply-To: <def930b90366501f8e301a693b08d27967479633.1550851998.git.anatoly.burakov@intel.com>
In-Reply-To: <def930b90366501f8e301a693b08d27967479633.1550851998.git.anatoly.burakov@intel.com>

When requesting memory with ``-m`` or ``--socket-mem`` flags,
currently the init will fail if the requested memory amount was
bigger than any one memseg list, even if total amount of
available memory was sufficient.

Fix this by making EAL to attempt to allocate pages multiple
times, until we either fulfill our memory requirements, or run
out of hugepages to allocate.

Bugzilla ID: 95

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 lib/librte_eal/linuxapp/eal/eal_memory.c | 47 ++++++++++++++++--------
 1 file changed, 32 insertions(+), 15 deletions(-)

diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
index 1b96b576e..361109eb3 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
@@ -1784,30 +1784,47 @@ eal_hugepage_init(void)
 			struct rte_memseg **pages;
 			struct hugepage_info *hpi = &used_hp[hp_sz_idx];
 			unsigned int num_pages = hpi->num_pages[socket_id];
-			int num_pages_alloc, i;
+			unsigned int num_pages_alloc;
 
 			if (num_pages == 0)
 				continue;
 
-			pages = malloc(sizeof(*pages) * num_pages);
-
 			RTE_LOG(DEBUG, EAL, "Allocating %u pages of size %" PRIu64 "M on socket %i\n",
 				num_pages, hpi->hugepage_sz >> 20, socket_id);
 
-			num_pages_alloc = eal_memalloc_alloc_seg_bulk(pages,
-					num_pages, hpi->hugepage_sz,
-					socket_id, true);
-			if (num_pages_alloc < 0) {
+			/* we may not be able to allocate all pages in one go,
+			 * because we break up our memory map into multiple
+			 * memseg lists. therefore, try allocating multiple
+			 * times and see if we can get the desired number of
+			 * pages from multiple allocations.
+			 */
+
+			num_pages_alloc = 0;
+			do {
+				int i, cur_pages, needed;
+
+				needed = num_pages - num_pages_alloc;
+
+				pages = malloc(sizeof(*pages) * needed);
+
+				/* do not request exact number of pages */
+				cur_pages = eal_memalloc_alloc_seg_bulk(pages,
+						needed, hpi->hugepage_sz,
+						socket_id, false);
+				if (cur_pages <= 0) {
+					free(pages);
+					return -1;
+				}
+
+				/* mark preallocated pages as unfreeable */
+				for (i = 0; i < cur_pages; i++) {
+					struct rte_memseg *ms = pages[i];
+					ms->flags |= RTE_MEMSEG_FLAG_DO_NOT_FREE;
+				}
 				free(pages);
-				return -1;
-			}
 
-			/* mark preallocated pages as unfreeable */
-			for (i = 0; i < num_pages_alloc; i++) {
-				struct rte_memseg *ms = pages[i];
-				ms->flags |= RTE_MEMSEG_FLAG_DO_NOT_FREE;
-			}
-			free(pages);
+				num_pages_alloc += cur_pages;
+			} while (num_pages_alloc != num_pages);
 		}
 	}
 	/* if socket limits were specified, set them */
-- 
2.17.1

  parent reply	other threads:[~2019-02-22 16:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-22 16:14 [dpdk-dev] [PATCH 1/3] fbarray: add API to find biggest used or free chunks Anatoly Burakov
2019-02-22 16:14 ` [dpdk-dev] [PATCH 2/3] memalloc: improve best-effort allocation Anatoly Burakov
2019-02-22 16:14 ` Anatoly Burakov [this message]
2019-03-28 22:22   ` [dpdk-dev] [PATCH 3/3] eal: attempt multiple hugepage allocations at init Thomas Monjalon
2019-03-28 22:22     ` 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=0a770fb3968c0a270eb57ff7764d6fba4cf6f76d.1550851998.git.anatoly.burakov@intel.com \
    --to=anatoly.burakov@intel.com \
    --cc=dev@dpdk.org \
    --cc=maxime.leroy@6wind.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).