]> git.droids-corp.org - dpdk.git/commitdiff
malloc: fix allocation with unknown socket ID
authorIlyes Ben Hamouda <ilyes.ben_hamouda@6wind.com>
Fri, 29 Oct 2021 09:49:29 +0000 (11:49 +0200)
committerDavid Marchand <david.marchand@redhat.com>
Fri, 5 Nov 2021 14:28:49 +0000 (15:28 +0100)
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")
Cc: stable@dpdk.org
Signed-off-by: Ilyes Ben Hamouda <ilyes.ben_hamouda@6wind.com>
Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
Acked-by: David Marchand <david.marchand@redhat.com>
lib/eal/common/malloc_heap.c
lib/eal/common/malloc_heap.h

index 775d6789dfeff7757caa721b25a0a57e4aa3d615..55aad2711b392a9b20c230932d2bcaaab83968d2 100644 (file)
@@ -699,6 +699,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)
index 3a6ec6ecf03b7c10ebc03ce09fcc8e18f719f52e..3a29d024b4ca45f9fc941c59f5a2a3d72766db78 100644 (file)
@@ -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);