RFR: 8318986: Improve GenericWaitBarrier performance [v2]
Aleksey Shipilev
shade at openjdk.org
Thu Nov 2 12:36:03 UTC 2023
On Thu, 2 Nov 2023 11:03:16 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:
>> See the symptoms, reproducer and analysis in the bug.
>>
>> Current code waits on `disarm()`, which effectively stalls leaving the safepoint if some threads lag behind. Having more runnable threads than CPUs nearly guarantees that we would wait for quite some time, but it also reproduces well if you have enough threads near the CPU count. Just waiting at `arm()` is insufficient, but we can have several `Semaphores` to do what we want.
>>
>> This PR implements a more efficient `GenericWaitBarrier` to recover the performance. Most of the implementation discussion is in the code comments. The key observation that drives this work is that we want to reuse `Semaphore` and related counters without being stuck waiting for threads to leave.
>>
>> (AFAICS, futex-based `LinuxWaitBarrier` does roughly the same, but handles this reuse on futex side, by assigning the "address" per futex.)
>>
>> This issue affects everything except Linux. I initially found this on my M1 Mac, but pretty sure it is easy to reproduce on Windows as well. The safepoints from the reproducer in the bug improved dramatically on a Mac. Note not only the orders of magnitude better safepoint times, but also the several times more GC safepoints in the time-bound allocation test, which means the attainable GC throughput is similarly better, since we don't waste time at this wait barrier.
>>
>> 
>>
>> Additional testing:
>> - [x] MacOS AArch64 server fastdebug, `tier1`
>> - [x] Linux x86_64 server fastdebug, `tier1 tier2 tier3` (generic wait barrier enabled explicitly)
>> - [x] Linux AArch64 server fastdebug, `tier1 tier2 tier3` (generic wait barrier enabled explicitly)
>> - [x] MacOS AArch64 server fastdebug, `tier2 tier3`
>> - [x] Linux x86_64 server fastdebug, `tier4` (generic wait barrier enabled explicitly)
>> - [x] Linux AArch64 server fastdebug, `tier4` (generic wait barrier enabled explicitly)
>
> Aleksey Shipilev has updated the pull request incrementally with one additional commit since the last revision:
>
> Tigthen up memory ordering even more conservatively
Stress tests show there is still a race condition, which can be triggered by putting a small sleep on this path:
diff --git a/src/hotspot/share/utilities/waitBarrier_generic.cpp b/src/hotspot/share/utilities/waitBarrier_generic.cpp
index f886e7b4cf5..13ba12c39a6 100644
--- a/src/hotspot/share/utilities/waitBarrier_generic.cpp
+++ b/src/hotspot/share/utilities/waitBarrier_generic.cpp
@@ -174,6 +174,7 @@ void GenericWaitBarrier::wait(int barrier_tag) {
OrderAccess::fence();
if (Atomic::load_acquire(&_barrier_tag) == barrier_tag) {
+ if (UseNewCode) os::naked_short_nanosleep(100);
Atomic::add(&cell._unsignaled_waits, 1);
// Wait for notification.
It would then fail/hang this `tier4` test:
$ CONF=linux-x86_64-server-fastdebug make images test TEST=vmTestbase/nsk/monitoring/ThreadInfo/isSuspended/issuspended002.java TEST_VM_OPTS="-XX:+UnlockDiagnosticVMOptions -XX:+UseNewCode"
Putting this issue to draft until I figure out the better way to do this.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/16404#issuecomment-1790644526
More information about the hotspot-dev
mailing list