DPDK patches and discussions
 help / color / mirror / Atom feed
From: Olivier Matz <olivier.matz@6wind.com>
To: dev@dpdk.org
Cc: Anatoly Burakov <anatoly.burakov@intel.com>,
	Ilyes Ben Hamouda <ilyes.ben_hamouda@6wind.com>,
	stable@dpdk.org
Subject: [dpdk-dev] [PATCH] eal: fix mem alloc from control thread if socket 0 is unused
Date: Fri, 29 Oct 2021 11:49:29 +0200	[thread overview]
Message-ID: <20211029094929.29864-1-olivier.matz@6wind.com> (raw)

From: Ilyes Ben Hamouda <ilyes.ben_hamouda@6wind.com>

When using rte_malloc() from a control thread, the used heap is the one
from numa socket 0, which may not have available memory.

Fix this by selecting the first socket which has available memory.

Note: malloc_get_numa_socket() is only used from one .c file, so move
it there, and remove the inline keyword.

Fixes: b94580d6887e ("malloc: avoid unknown socket id")
Cc: stable@dpdk.org

Signed-off-by: Ilyes Ben Hamouda <ilyes.ben_hamouda@6wind.com>
Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
---
 lib/eal/common/malloc_heap.c | 20 ++++++++++++++++++++
 lib/eal/common/malloc_heap.h | 11 -----------
 2 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/lib/eal/common/malloc_heap.c b/lib/eal/common/malloc_heap.c
index ee400f38ec..6eff9a2284 100644
--- a/lib/eal/common/malloc_heap.c
+++ b/lib/eal/common/malloc_heap.c
@@ -694,6 +694,26 @@ malloc_heap_alloc_on_heap_id(const char *type, size_t size,
 	return ret;
 }
 
+static unsigned int
+malloc_get_numa_socket(void)
+{
+	const struct internal_config *conf = eal_get_internal_configuration();
+	unsigned int socket_id = rte_socket_id();
+	unsigned int idx;
+
+	if (socket_id != (unsigned int)SOCKET_ID_ANY)
+		return socket_id;
+
+	/* for control threads, return first socket where memory is available */
+	for (idx = 0; idx < rte_socket_count(); idx++) {
+		socket_id = rte_socket_id_by_idx(idx);
+		if (conf->socket_mem[socket_id] != 0)
+			return socket_id;
+	}
+
+	return rte_socket_id_by_idx(0);
+}
+
 void *
 malloc_heap_alloc(const char *type, size_t size, int socket_arg,
 		unsigned int flags, size_t align, size_t bound, bool contig)
diff --git a/lib/eal/common/malloc_heap.h b/lib/eal/common/malloc_heap.h
index 3a6ec6ecf0..3a29d024b4 100644
--- a/lib/eal/common/malloc_heap.h
+++ b/lib/eal/common/malloc_heap.h
@@ -33,17 +33,6 @@ struct malloc_heap {
 	char name[RTE_HEAP_NAME_MAX_LEN];
 } __rte_cache_aligned;
 
-static inline unsigned
-malloc_get_numa_socket(void)
-{
-	unsigned socket_id = rte_socket_id();
-
-	if (socket_id == (unsigned)SOCKET_ID_ANY)
-		return 0;
-
-	return socket_id;
-}
-
 void *
 malloc_heap_alloc(const char *type, size_t size, int socket, unsigned int flags,
 		size_t align, size_t bound, bool contig);
-- 
2.30.2


             reply	other threads:[~2021-10-29  9:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-29  9:49 Olivier Matz [this message]
2021-11-03 20:26 ` David Marchand
2021-11-04  8:54   ` Olivier Matz
2021-11-05 14:26     ` David Marchand

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=20211029094929.29864-1-olivier.matz@6wind.com \
    --to=olivier.matz@6wind.com \
    --cc=anatoly.burakov@intel.com \
    --cc=dev@dpdk.org \
    --cc=ilyes.ben_hamouda@6wind.com \
    --cc=stable@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).