DPDK patches and discussions
 help / color / mirror / Atom feed
From: Anatoly Burakov <anatoly.burakov@intel.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH v2 3/3] mem: improve autodetection of hugepage counts on 32-bit
Date: Fri, 20 Apr 2018 16:25:27 +0100	[thread overview]
Message-ID: <79dd25146593211c90a12bb7e0538e1c5ff80ca7.1524237907.git.anatoly.burakov@intel.com> (raw)
In-Reply-To: <c8375f94e07e2ed99090eaefb4f4c4bb657c5206.1524237907.git.anatoly.burakov@intel.com>
In-Reply-To: <c8375f94e07e2ed99090eaefb4f4c4bb657c5206.1524235066.git.anatoly.burakov@intel.com>

For non-legacy mode, we are preallocating space for hugepages, so
we know in advance which pages we will be able to allocate, and
which we won't. However, the init procedure was using hugepage
counts gathered from sysfs and paid no attention to hugepage
sizes that were actually available for reservation, and failed
on attempts to reserve unavailable pages.

Fix this by limiting total page counts by number of pages
actually preallocated.

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

diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
index fadc1de..6f2cdf8 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
@@ -1603,6 +1603,18 @@ eal_legacy_hugepage_init(void)
 	return -1;
 }
 
+static int __rte_unused
+hugepage_count_walk(const struct rte_memseg_list *msl, void *arg)
+{
+	struct hugepage_info *hpi = arg;
+
+	if (msl->page_sz != hpi->hugepage_sz)
+		return 0;
+
+	hpi->num_pages[msl->socket_id] += msl->memseg_arr.len;
+	return 0;
+}
+
 static int
 eal_hugepage_init(void)
 {
@@ -1617,10 +1629,29 @@ eal_hugepage_init(void)
 	for (hp_sz_idx = 0;
 			hp_sz_idx < (int) internal_config.num_hugepage_sizes;
 			hp_sz_idx++) {
+#ifndef RTE_ARCH_64
+		struct hugepage_info dummy;
+		unsigned int i;
+#endif
 		/* also initialize used_hp hugepage sizes in used_hp */
 		struct hugepage_info *hpi;
 		hpi = &internal_config.hugepage_info[hp_sz_idx];
 		used_hp[hp_sz_idx].hugepage_sz = hpi->hugepage_sz;
+
+#ifndef RTE_ARCH_64
+		/* for 32-bit, limit number of pages on socket to whatever we've
+		 * preallocated, as we cannot allocate more.
+		 */
+		memset(&dummy, 0, sizeof(dummy));
+		dummy.hugepage_sz = hpi->hugepage_sz;
+		if (rte_memseg_list_walk(hugepage_count_walk, &dummy) < 0)
+			return -1;
+
+		for (i = 0; i < RTE_DIM(dummy.num_pages); i++) {
+			hpi->num_pages[i] = RTE_MIN(hpi->num_pages[i],
+					dummy.num_pages[i]);
+		}
+#endif
 	}
 
 	/* make a copy of socket_mem, needed for balanced allocation. */
-- 
2.7.4

      parent reply	other threads:[~2018-04-20 15:25 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   ` [dpdk-dev] [PATCH v3 2/3] mem: improve memory preallocation on 32-bit Anatoly Burakov
2018-04-25 13:27     ` 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 ` Anatoly Burakov [this message]

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=79dd25146593211c90a12bb7e0538e1c5ff80ca7.1524237907.git.anatoly.burakov@intel.com \
    --to=anatoly.burakov@intel.com \
    --cc=dev@dpdk.org \
    /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).