Re: use a non-locking initial test in TAS_SPIN on AArch64
Re: use a non-locking initial test in TAS_SPIN on AArch64
От:
Jingtang Zhang <mrdrivingduck@gmail.com>
Дата:
Hi~
Upon closer inspection, I noticed that we don't implement a custom
TAS_SPIN() for this architecture, so I quickly hacked together the attached
patch and ran a couple of benchmarks that stressed the spinlock code. I
found no discussion about TAS_SPIN() on ARM in the archives, but I did
notice that the initial AArch64 support was added [0] before x86_64 started
using a non-locking test [1].
It reminds me of a discussion about improving spinlock performance on ARM
in 2020 [0], though the discussion is about CAS and TAS, not TAS_SPIN() itself.
in 2020 [0], though the discussion is about CAS and TAS, not TAS_SPIN() itself.
tps = 74135.100891 (without initial connection time)
tps = 549462.785554 (without initial connection time)
The result looks great, but the discussion in [0] shows that the result may
vary among different ARM chips. Could you provide the chip model of this
test? So that we can do a cross validation of this patch. Not sure if compiler
version is necessary too. I'm willing to test it on Alibaba Cloud Yitian 710test? So that we can do a cross validation of this patch. Not sure if compiler
if I have time.
- Regards
Jingtang
Re: use a non-locking initial test in TAS_SPIN on AArch64
От:
Nathan Bossart <nathandbossart@gmail.com>
Дата:
On Wed, Oct 23, 2024 at 11:01:05AM +0800, Jingtang Zhang wrote: > The result looks great, but the discussion in [0] shows that the result may > vary among different ARM chips. Could you provide the chip model of this > test? So that we can do a cross validation of this patch. This is on a c8g.24xlarge, which is using Neoverse-V2 and Armv9.0-a [0]. > I'm willing to test it on Alibaba Cloud Yitian 710 if I have time. That would be great. I have a couple of Apple M-series machines I can test, too. [0] https://github.com/aws/aws-graviton-getting-started/blob/main/README.md#building-for-graviton -- nathan
Re: use a non-locking initial test in TAS_SPIN on AArch64
От:
Nathan Bossart <nathandbossart@gmail.com>
Дата:
On Wed, Oct 23, 2024 at 09:46:56AM -0500, Nathan Bossart wrote: > I have a couple of Apple M-series machines I can test, too. After some preliminary tests on an M3, I'm not seeing any gains outside the noise range. That's not too surprising because it's likely more difficult to create a lot of spinlock contention on these smaller machines. But, at the very least, I'm not seeing a regression. -- nathan
Re: use a non-locking initial test in TAS_SPIN on AArch64
От:
Jingtang Zhang <mrdrivingduck@gmail.com>
Дата:
Hi, Nathan. I just realized that I almost forgot about this thread :) > The result looks great, but the discussion in [0] shows that the result may > vary among different ARM chips. Could you provide the chip model of this > test? So that we can do a cross validation of this patch. Not sure if compiler > version is necessary too. I'm willing to test it on Alibaba Cloud Yitian 710 > if I have time. I did some benchmark on Yitian 710. On c8y.16xlarge (64 cores): Without the patch: 80.31% postgres [.] __aarch64_swp4_acq 1.77% postgres [.] __aarch64_ldadd4_acq_rel 1.13% postgres [.] hash_search_with_hash_value 0.87% pg_stat_statements.so [.] __aarch64_swp4_acq 0.72% postgres [.] perform_spin_delay 0.44% postgres [.] _bt_compare tps = 295272.628421 (including connections establishing) tps = 295335.660323 (excluding connections establishing) Patched: 9.94% postgres [.] s_lock 6.07% postgres [.] __aarch64_swp4_acq 5.73% postgres [.] hash_search_with_hash_value 2.81% postgres [.] perform_spin_delay 2.29% postgres [.] _bt_compare 2.15% postgres [.] PinBuffer tps = 864519.764125 (including connections establishing) tps = 864638.244443 (excluding connections establishing) Seems that great performance could be gained if s_lock contention is severe. This may be more likely to happen on bigger machines. On c8y.2xlarge (8 cores), I failed to make s_lock contended severely, and as a result this patch didn’t bring any difference outside the noise. Regards, Jingtang
Re: use a non-locking initial test in TAS_SPIN on AArch64
От:
Nathan Bossart <nathandbossart@gmail.com>
Дата:
On Wed, Jan 15, 2025 at 07:50:38PM +0800, Jingtang Zhang wrote: > Seems that great performance could be gained if s_lock contention is severe. > This may be more likely to happen on bigger machines. > > On c8y.2xlarge (8 cores), I failed to make s_lock contended severely, and > as a result this patch didn´t bring any difference outside the noise. Thanks for sharing. -- nathan
Re: use a non-locking initial test in TAS_SPIN on AArch64
От:
Nathan Bossart <nathandbossart@gmail.com>
Дата:
On Tue, Sep 15, 2026 at 11:46:23AM +0000, Salvatore Dipietro wrote:
> I'd like to propose backporting this commit 3d0b4b1068 ("Use a
> non-locking initial test in TAS_SPIN on AArch64.", Nathan Bossart,
> 2025-01-10), which first shipped in PostgreSQL 18, to the supported
> back branches: REL_17_STABLE, REL_16_STABLE and REL_15_STABLE.
I think that's fine. It was likely an oversight when AArch64 support was
first added to this file, anyway. We could also back-patch to v14, but
that would look a little different since it is missing commit a82a5eee31
("Use ISB as a spin-delay instruction on ARM64"). Since v14 is set to go
out-of-support in a couple months, I'd probably just stop at v15 and call
it a day, though.
> With huge_pages=on both effects largely disappear: huge pages mask the
> paging defect, and TTAS is neutral.
>
> The change is a one-line, so a backport looks low-risk and would spare
> pre-18 AArch64 users a severe regression as PREEMPT_LAZY kernels ship.
I'm curious why you are testing without huge pages enabled. My
understanding is that any serious workload on the kinds of machines you are
using for your benchmarks would use them.
--
nathan
Re: use a non-locking initial test in TAS_SPIN on AArch64
От:
"Burd, Greg" <greg@burd.me>
Дата:
> On Sep 15, 2026, at 10:51 AM, Nathan Bossart wrote:
>
> On Tue, Sep 15, 2026 at 11:46:23AM +0000, Salvatore Dipietro wrote:
>> I'd like to propose backporting this commit 3d0b4b1068 ("Use a
>> non-locking initial test in TAS_SPIN on AArch64.", Nathan Bossart,
>> 2025-01-10), which first shipped in PostgreSQL 18, to the supported
>> back branches: REL_17_STABLE, REL_16_STABLE and REL_15_STABLE.
>
> I think that's fine. It was likely an oversight when AArch64 support was
> first added to this file, anyway. We could also back-patch to v14, but
> that would look a little different since it is missing commit a82a5eee31
> ("Use ISB as a spin-delay instruction on ARM64"). Since v14 is set to go
> out-of-support in a couple months, I'd probably just stop at v15 and call
> it a day, though.
+1 for backpatching to v15
> With huge_pages=on both effects largely disappear: huge pages mask the
>> paging defect, and TTAS is neutral.
>>
>> The change is a one-line, so a backport looks low-risk and would spare
>> pre-18 AArch64 users a severe regression as PREEMPT_LAZY kernels ship.
>
> I'm curious why you are testing without huge pages enabled. My
> understanding is that any serious workload on the kinds of machines you are
> using for your benchmarks would use them.
I agree with Nathan, that should have a positive impact. 95GiB shared_buffers
on 4 KB pages is a TLB disaster. With ~4 KB pages, a buffer pool that size
needs ~25 million page-table entries; the TLB on Graviton4 cores covers only
a few thousand entries, so heavy concurrent access to shared memory causes
constant TLB misses and page-table walks. I bet you can measure for this
effect to validate that's happening.
2 MB (or larger) pages cut the translation footprint by ~500x, give it a
try.
best.
-greg
> --
> nathan
Re: use a non-locking initial test in TAS_SPIN on AArch64
От:
Salvatore Dipietro <dipiets@amazon.it>
Дата:
>> On Sep 15, 2026, at 10:51 AM, Nathan Bossart wrote: >> I'm curious why you are testing without huge pages enabled. My >> understanding is that any serious workload on the kinds of machines you are >> using for your benchmarks would use them. > > On Sep 15, 2026, at 13:51 AM, Burd, Greg wrote: > I agree with Nathan, that should have a positive impact. 95GiB shared_buffers > on 4 KB pages is a TLB disaster. With ~4 KB pages, a buffer pool that size > needs ~25 million page-table entries; the TLB on Graviton4 cores covers only > a few thousand entries, so heavy concurrent access to shared memory causes > constant TLB misses and page-table walks. I bet you can measure for this > effect to validate that's happening. > > 2 MB (or larger) pages cut the translation footprint by ~500x, give it a > try. We routinely test both huge_pages=on and huge_pages=off. The hp=off case matters because huge_pages defaults to "try" and Linux does not preallocate a hugepage pool, so unless the operator sets it manually the server falls back to 4K pages. The regression is also more evident on this instance because of the high core count and the contention that comes with it; I would expect it on smaller instances too with a more limited impact, though I have not measured that. As expected, with hugepage=off the system is more under stress and TTAS shows a bigger improvement, but we tested hugepage=on as well (2 MB pages, preallocated pool of 54,612 pages for the 95 GB shared_buffers): | PG | 6.1 | v7.2 | v7.2+fix | |-------------|--------:|--------:|---------:| | 17.10 stock | 144,162 | 176,377 | 156,885 | | 17.10 TTAS | 148,997 | 185,961 | 185,524 | | 17.10 gain | +3.4% | +5.4% | +18.3% | Even with PG 17 and hugepages, TTAS still delivers some gains with kernel v7.2, though the gain is much smaller than with hugepage=off. For PG 15 and 16 with huge_pages=on, stock and TTAS come out close, 83-92k either way, so the limiter there is elsewhere. Salvatore AMAZON DEVELOPMENT CENTER ITALY SRL, viale Monte Grappa 3/5, 20124 Milano, Italia, Registro delle Imprese di Milano Monza Brianza Lodi REA n. 2504859, Capitale Sociale: 10.000 EUR i.v., Cod. Fisc. e P.IVA 10100050961, Societa con Socio Unico