RFR: 8371701: Add ability to set NUMA-affinity for threads

Joel Sikström jsikstro at openjdk.org
Wed Nov 12 11:15:04 UTC 2025


On Wed, 12 Nov 2025 10:59:58 GMT, Albert Mingkun Yang <ayang at openjdk.org> wrote:

>> Hello,
>> 
>> This PR adds support for setting the affinity of threads to run on CPUs associated with specific NUMA nodes on Linux. Support for this is needed for [JDK-8371702](https://bugs.openjdk.org/browse/JDK-8371702) to improve performance in the Relocation Phase of ZGC on a NUMA machine.
>> 
>> Testing:
>> * I've run significant performance testing locally on a NUMA machine and performed functional testing to see that the affinity is actually changed. Affinity of a thread can be inspected on Linux using `taskset -cp <tid>`.
>> * Running through Oracle's tier1-2
>
> src/hotspot/share/runtime/os.hpp line 537:
> 
>> 535: 
>> 536:   // NUMA-specific interface
>> 537:   static bool   numa_set_thread_affinity(Thread* thread, int node);
> 
> How to interpret the returned value? What do you suggest callers do with the return-value?

I'm seeing the return value as "was this operation successful or not". I could add a comment in the header file with something like the following if you think it would make things clearer.

// Sets the affinity of a thread to the CPUs associated with a NUMA node. Passing node
// as -1 sets the affinity to all CPUs the JVM is allowed to run on. Returns true if
// the thread's affinity has been changed, false otherwise.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/28261#discussion_r2517897188


More information about the hotspot-runtime-dev mailing list