]> git.ipfire.org Git - thirdparty/postgresql.git/commit
test_slru: Fix LWLock initialization for EXEC_BACKEND builds
authorMichael Paquier <michael@paquier.xyz>
Tue, 26 May 2026 03:26:36 +0000 (12:26 +0900)
committerMichael Paquier <michael@paquier.xyz>
Tue, 26 May 2026 03:26:36 +0000 (12:26 +0900)
commitd4a7e1886c1c34ab548f1a84374ba248faa2ae8a
tree308f70e66062109c574c8600b30eeb1f602746e7
parent273be484aadd03b8f8d45dd3aa6768ab4512d702
test_slru: Fix LWLock initialization for EXEC_BACKEND builds

The LWLock used by this test module was defined as a process-local
variable, which was broken under -DEXEC_BACKEND, each backend getting
its own copy of the lock state.  The shmem_startup_hook unconditionally
called LWLockRegisterTranche() and LWLockInitialize(), which means that
every backend would allocate a new tranche ID (which is still OK for
this module) but reset the lock's atomic state (which was bad).

This commit moves the LWLock to shared memory, so as it is initialized
only once, similarly to pg_prewarm/autoprewarm.c.

This change is only for REL_16_STABLE, per a report from buildfarm
member gokiburi (the system has been upgraded recently, so perhaps it
began failing due to some ALSR changes?).  I have been able to reproduce
the problem on the same host with -DEXEC_BACKEND, and checked that this
commit addresses the issue.  In v17 and v18, the test module wastes
tranche IDs, which only impacts the visibility of the locks like in
pg_stat_activity.  The use of the SLRU bank locks ensures that the
LWLock state is safe.  On HEAD, the logic of the module is safer thanks
to 38b602b0289f.

Discussion: https://postgr.es/m/agr6-cIQ4EUA86Cs@paquier.xyz
Backpatch-through: 16
src/test/modules/test_slru/test_slru.c
src/tools/pgindent/typedefs.list