[v3] malloc: enhance NUMA affinity heuristic

Message ID 20230103133216.961495-1-david.marchand@redhat.com (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers
Series [v3] malloc: enhance NUMA affinity heuristic |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-broadcom-Performance success Performance Testing PASS
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-testing fail Testing issues
ci/iol-x86_64-unit-testing fail Testing issues
ci/iol-abi-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS

Commit Message

David Marchand Jan. 3, 2023, 1:32 p.m. UTC
  Trying to allocate memory on the first detected numa node has less
chance to find some memory actually available rather than on the main
lcore numa node (especially when the DPDK application is started only
on one numa node).

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
Changes since v2:
- add uncommitted local change and fix compilation,

Changes since v1:
- accomodate for configurations with main lcore running on multiples
  physical cores belonging to different numa,

---
 lib/eal/common/malloc_heap.c | 4 ++++
 1 file changed, 4 insertions(+)
  

Comments

Kaisen You Jan. 31, 2023, 3:23 a.m. UTC | #1
> -----Original Message-----
> From: David Marchand <david.marchand@redhat.com>
> Sent: 2023年1月3日 21:32
> To: dev@dpdk.org
> Cc: Matz, Olivier <olivier.matz@6wind.com>; ferruh.yigit@amd.com; You,
> KaisenX <kaisenx.you@intel.com>; zhoumin@loongson.cn; Burakov, Anatoly
> <anatoly.burakov@intel.com>
> Subject: [PATCH v3] malloc: enhance NUMA affinity heuristic
> 
> Trying to allocate memory on the first detected numa node has less chance
> to find some memory actually available rather than on the main lcore numa
> node (especially when the DPDK application is started only on one numa
> node).
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> ---
> Changes since v2:
> - add uncommitted local change and fix compilation,
> 
> Changes since v1:
> - accomodate for configurations with main lcore running on multiples
>   physical cores belonging to different numa,
> 
> ---
>  lib/eal/common/malloc_heap.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/lib/eal/common/malloc_heap.c b/lib/eal/common/malloc_heap.c
> index d7c410b786..3ee19aee15 100644
> --- a/lib/eal/common/malloc_heap.c
> +++ b/lib/eal/common/malloc_heap.c
> @@ -717,6 +717,10 @@ malloc_get_numa_socket(void)
>  			return socket_id;
>  	}
> 
> +	socket_id = rte_lcore_to_socket_id(rte_get_main_lcore());
> +	if (socket_id != (unsigned int)SOCKET_ID_ANY)
> +		return socket_id;
> +
>  	return rte_socket_id_by_idx(0);
>  }
> 
Because the initial "socket_id" of the interrupt thread is not necessarily 
"SOCKET_ID_ANY"(-1), in malloc_get_numa_socket(void) function, It may 
be returned before the content modified by this patch, resulting in the 
subsequent search for memory being performed on the socket that initializes 
the unallocated memory. 

To avoid this, I will submit the V4 version to fix this problem.

> --
> 2.39.0
  

Patch

diff --git a/lib/eal/common/malloc_heap.c b/lib/eal/common/malloc_heap.c
index d7c410b786..3ee19aee15 100644
--- a/lib/eal/common/malloc_heap.c
+++ b/lib/eal/common/malloc_heap.c
@@ -717,6 +717,10 @@  malloc_get_numa_socket(void)
 			return socket_id;
 	}
 
+	socket_id = rte_lcore_to_socket_id(rte_get_main_lcore());
+	if (socket_id != (unsigned int)SOCKET_ID_ANY)
+		return socket_id;
+
 	return rte_socket_id_by_idx(0);
 }