public inbox for dev@dpdk.org
 help / color / mirror / Atom feed
From: Jake Freeland <jfree@FreeBSD.org>
To: Anatoly Burakov <anatoly.burakov@intel.com>,
	Bruce Richardson <bruce.richardson@intel.com>
Cc: Jake Freeland <jfree@FreeBSD.org>, dev@dpdk.org
Subject: [PATCH v3 2/3] eal/freebsd: avoid claiming memseg holes
Date: Wed, 14 Jan 2026 18:31:28 +0900	[thread overview]
Message-ID: <20260114093140.3256584-3-jfree@FreeBSD.org> (raw)
In-Reply-To: <20260114093140.3256584-1-jfree@FreeBSD.org>

When need_hole is false, memseg searches will only be done for a single
element. If the search starts at beginning of the list, an element that
was previously reserved as a hole may be wrongly claimed.

To avoid this, begin the search following the last used entry. This way,
we ignore all pre-existing holes.

Signed-off-by: Jake Freeland <jfree@FreeBSD.org>
---
 lib/eal/freebsd/eal_memory.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/lib/eal/freebsd/eal_memory.c b/lib/eal/freebsd/eal_memory.c
index 8c315d97d5..5790f095c9 100644
--- a/lib/eal/freebsd/eal_memory.c
+++ b/lib/eal/freebsd/eal_memory.c
@@ -143,6 +143,7 @@ rte_eal_hugepage_init(void)
 
 			for (msl_idx = 0; msl_idx < RTE_MAX_MEMSEG_LISTS;
 					msl_idx++) {
+				int start_idx, num_elems;
 				bool empty, need_hole;
 				msl = &mcfg->memsegs[msl_idx];
 				arr = &msl->memseg_arr;
@@ -157,10 +158,22 @@ rte_eal_hugepage_init(void)
 				 * adjacent to current one.
 				 */
 				need_hole = !empty && !is_adjacent;
+				if (need_hole) {
+					start_idx = 0;
+					/* we need 1, plus hole */
+					num_elems = 2;
+				} else {
+					/* begin our search after the last used
+					 * element in the list, skipping over
+					 * any previously placed holes
+					 */
+					start_idx = rte_fbarray_find_prev_n_used(
+							arr, arr->len - 1, 1) + 1;
+					num_elems = 1;
+				}
 
-				/* we need 1, plus hole if not adjacent */
 				ms_idx = rte_fbarray_find_next_n_free(arr,
-						0, 1 + (need_hole ? 1 : 0));
+						start_idx, num_elems);
 
 				/* memseg list is full? */
 				if (ms_idx < 0)
-- 
2.51.0


  parent reply	other threads:[~2026-01-14  9:32 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-14 21:32 [PATCH v2 0/3] EAL memory fixes Jake Freeland
2025-08-14 21:32 ` [PATCH v2 1/3] eal/freebsd: Do not use prev_ms_idx for hole detection Jake Freeland
2025-10-13 12:23   ` Burakov, Anatoly
2025-10-14  9:06   ` Burakov, Anatoly
2025-08-14 21:32 ` [PATCH v2 2/3] eal/freebsd: Avoid claiming memseg holes Jake Freeland
2025-10-13 12:36   ` Burakov, Anatoly
2025-10-13 13:12   ` Burakov, Anatoly
2025-08-14 21:32 ` [PATCH v2 3/3] eal/linux: Check hugepage access permissions Jake Freeland
2025-10-13 12:43   ` Burakov, Anatoly
2025-10-15 16:53 ` [PATCH v2 0/3] EAL memory fixes Thomas Monjalon
2026-01-14  6:37 ` Stephen Hemminger
2026-01-14  9:31 ` [PATCH v3 " Jake Freeland
2026-01-14  9:31   ` [PATCH v3 1/3] eal/freebsd: do not use prev_ms_idx for hole detection Jake Freeland
2026-01-14  9:31   ` Jake Freeland [this message]
2026-01-14  9:31   ` [PATCH v3 3/3] eal/linux: check hugepage access permissions Jake Freeland
2026-01-14 10:04     ` [PATCH v4] " Jake Freeland
2026-02-13 16:01     ` [PATCH v3 3/3] " David Marchand
2026-02-13 16:02   ` [PATCH v3 0/3] EAL memory fixes David Marchand
2026-01-23  5:09 ` [PATCH v2 " Stephen Hemminger
2026-01-23 17:43   ` Jake Freeland

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=20260114093140.3256584-3-jfree@FreeBSD.org \
    --to=jfree@freebsd.org \
    --cc=anatoly.burakov@intel.com \
    --cc=bruce.richardson@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