[dpdk-stable] patch 'malloc: fix allocation with unknown socket ID' has been queued to stable release 20.11.4

Xueming Li xuemingl at nvidia.com
Wed Nov 10 07:31:33 CET 2021


Hi,

FYI, your patch has been queued to stable release 20.11.4

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 11/12/21. So please
shout if anyone has objections.

Also note that after the patch there's a diff of the upstream commit vs the
patch applied to the branch. This will indicate if there was any rebasing
needed to apply to the stable branch. If there were code changes for rebasing
(ie: not only metadata diffs), please double check that the rebase was
correctly done.

Queued patches are on a temporary branch at:
https://github.com/steevenlee/dpdk

This queued commit can be viewed at:
https://github.com/steevenlee/dpdk/commit/3f1ba3396e6701e20eb4b2eead4ca4c36629e5fb

Thanks.

Xueming Li <xuemingl at nvidia.com>

---
>From 3f1ba3396e6701e20eb4b2eead4ca4c36629e5fb Mon Sep 17 00:00:00 2001
From: Ilyes Ben Hamouda <ilyes.ben_hamouda at 6wind.com>
Date: Fri, 29 Oct 2021 11:49:29 +0200
Subject: [PATCH] malloc: fix allocation with unknown socket ID
Cc: Xueming Li <xuemingl at nvidia.com>

[ upstream commit 770d41bf33090462319c765c86a4c1979dc2a148 ]

When using rte_malloc() from a thread which is not bound to a numa
socket (the typical case is a control thread, but it can also happen
on a dataplane thread if its cpu affinity is on cores attached to
several sockets), 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")

Signed-off-by: Ilyes Ben Hamouda <ilyes.ben_hamouda at 6wind.com>
Signed-off-by: Olivier Matz <olivier.matz at 6wind.com>
Acked-by: David Marchand <david.marchand at redhat.com>
---
 lib/librte_eal/common/malloc_heap.c | 20 ++++++++++++++++++++
 lib/librte_eal/common/malloc_heap.h | 11 -----------
 2 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/lib/librte_eal/common/malloc_heap.c b/lib/librte_eal/common/malloc_heap.c
index 5a09247a65..350ff97ee0 100644
--- a/lib/librte_eal/common/malloc_heap.c
+++ b/lib/librte_eal/common/malloc_heap.c
@@ -693,6 +693,26 @@ alloc_unlock:
 	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/librte_eal/common/malloc_heap.h b/lib/librte_eal/common/malloc_heap.h
index 772736b53f..dfd57e6a56 100644
--- a/lib/librte_eal/common/malloc_heap.h
+++ b/lib/librte_eal/common/malloc_heap.h
@@ -37,17 +37,6 @@ struct malloc_heap {
 extern "C" {
 #endif
 
-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.33.0

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2021-11-10 14:17:11.145362466 +0800
+++ 0209-malloc-fix-allocation-with-unknown-socket-ID.patch	2021-11-10 14:17:02.017411557 +0800
@@ -1 +1 @@
-From 770d41bf33090462319c765c86a4c1979dc2a148 Mon Sep 17 00:00:00 2001
+From 3f1ba3396e6701e20eb4b2eead4ca4c36629e5fb Mon Sep 17 00:00:00 2001
@@ -4,0 +5,3 @@
+Cc: Xueming Li <xuemingl at nvidia.com>
+
+[ upstream commit 770d41bf33090462319c765c86a4c1979dc2a148 ]
@@ -18 +20,0 @@
-Cc: stable at dpdk.org
@@ -24,2 +26,2 @@
- lib/eal/common/malloc_heap.c | 20 ++++++++++++++++++++
- lib/eal/common/malloc_heap.h | 11 -----------
+ lib/librte_eal/common/malloc_heap.c | 20 ++++++++++++++++++++
+ lib/librte_eal/common/malloc_heap.h | 11 -----------
@@ -28,5 +30,5 @@
-diff --git a/lib/eal/common/malloc_heap.c b/lib/eal/common/malloc_heap.c
-index 775d6789df..55aad2711b 100644
---- a/lib/eal/common/malloc_heap.c
-+++ b/lib/eal/common/malloc_heap.c
-@@ -699,6 +699,26 @@ alloc_unlock:
+diff --git a/lib/librte_eal/common/malloc_heap.c b/lib/librte_eal/common/malloc_heap.c
+index 5a09247a65..350ff97ee0 100644
+--- a/lib/librte_eal/common/malloc_heap.c
++++ b/lib/librte_eal/common/malloc_heap.c
+@@ -693,6 +693,26 @@ alloc_unlock:
@@ -59,7 +61,7 @@
-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;
+diff --git a/lib/librte_eal/common/malloc_heap.h b/lib/librte_eal/common/malloc_heap.h
+index 772736b53f..dfd57e6a56 100644
+--- a/lib/librte_eal/common/malloc_heap.h
++++ b/lib/librte_eal/common/malloc_heap.h
+@@ -37,17 +37,6 @@ struct malloc_heap {
+ extern "C" {
+ #endif


More information about the stable mailing list