| From: | Nathan Bossart <nathandbossart(at)gmail(dot)com> |
|---|---|
| To: | pgsql-hackers(at)postgresql(dot)org |
| Subject: | more cleanup for s_lock.h |
| Date: | 2026-11-20 20:13:22 |
| Message-ID: | awCp4lLuKC-4GBcU@nathan |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
While working on recent round of s_lock.h cleanup, I started wondering
whether we really need architecture-specific implementations of anything in
that file besides SPIN_DELAY(). We've been slowly moving away from
spinlocks, and the compiler builtins have been available for ~20 years, so
I doubt all of this hand-rolled code is still buying us much. I'd like to
see how much of it we can get rid of, and the attached patches are a first
step in that direction. This batch just removes some redundancy between
platforms.
0001 removes the parts of the ARM section that are redundant with the
generic __sync code added by commit 1c72d82c25. The TAS_SPIN() and
SPIN_DELAY() definitions for AArch64 stay, and the generated code shouldn't
change.
0002 merges the i386 section into the x86-64 one. The only real difference
is that i386 does an unlocked test before every xchg, whereas x86-64 only
does so in TAS_SPIN(). The comment in the i386 section suggests that i386
should probably follow x86-64's lead, but nobody has tested it. Since
we've disclaimed interest in micro-optimizing for 32-bit builds (see commit
cb7b2e5e8e), IMHO we should just do it.
0003 makes the unlocked test the default for TAS_SPIN() and removes the
platform-specific versions for x86, PPC, and AArch64 (see commits
b03d196be0, bc2a050d40, and 3d0b4b1068). Nothing changes for those three,
but everything else (e.g., s390, SPARC, MIPS, RISC-V, 32-bit ARM, and all
MSVC builds) will now do the unlocked test while waiting for a contended
spinlock.
We've thus far been hesitant to add the unlocked test to platforms without
evidence of improvements, but that means a platform goes without it until
someone happens to notice. AArch64 is the best example. It didn't get the
unlocked test until v18, more than a decade after we added support for it,
despite it being a clear win there. That's one of the main reasons I'd
like to make it the default. AFAICT that reasoning should basically apply
everywhere, and a platform can still override TAS_SPIN() if it turns out to
hurt.
Thoughts?
--
nathan
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Remove-redundant-spinlock-code-for-ARM-ARM64.patch | text/plain | 2.2 KB |
| v1-0002-Merge-i386-and-x86-64-code-in-s_lock.h.patch | text/plain | 4.3 KB |
| v1-0003-Use-unlocked-test-before-test-and-set-in-TAS_SPIN.patch | text/plain | 4.0 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Robert Haas | 2026-11-20 20:15:37 | Re: pg_plan_advice: add NO_ scan and join method tags |
| Previous Message | Tom Lane | 2026-11-20 20:06:20 | Re: [PATCH] Fix encoding-dependent LIKE/regex selectivity estimates |