From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 352CFA00C3 for ; Tue, 14 Dec 2021 14:36:58 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2B48840041; Tue, 14 Dec 2021 14:36:58 +0100 (CET) Received: from smtpservice.6wind.com (unknown [185.13.181.2]) by mails.dpdk.org (Postfix) with ESMTP id 99DF940041 for ; Fri, 10 Dec 2021 11:34:06 +0100 (CET) Received: from rush.dev.6wind.com (rush.dev.6wind.com [10.17.1.169]) by smtpservice.6wind.com (Postfix) with ESMTP id 6B6D0180; Fri, 10 Dec 2021 11:34:06 +0100 (CET) From: Ilyes Ben Hamouda To: stable@dpdk.org Cc: Ilyes Ben Hamouda , Olivier Matz , David Marchand Subject: [PATCH 19.11] malloc: fix allocation with unknown socket ID Date: Fri, 10 Dec 2021 11:33:34 +0100 Message-Id: <20211210103334.17943-1-ilyes.ben_hamouda@6wind.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Tue, 14 Dec 2021 14:36:56 +0100 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org [ 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 Signed-off-by: Olivier Matz Acked-by: David Marchand --- lib/librte_eal/common/malloc_heap.c | 19 +++++++++++++++++++ lib/librte_eal/common/malloc_heap.h | 11 ----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/librte_eal/common/malloc_heap.c b/lib/librte_eal/common/malloc_heap.c index bd5065698d..90a46767ea 100644 --- a/lib/librte_eal/common/malloc_heap.c +++ b/lib/librte_eal/common/malloc_heap.c @@ -691,6 +691,25 @@ malloc_heap_alloc_on_heap_id(const char *type, size_t size, return ret; } +static unsigned int +malloc_get_numa_socket(void) +{ + 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 (internal_config.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.30.2