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/[email protected]
Backpatch-through: 16

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/d4a7e1886c1c34ab548f1a84374ba248faa2ae8a

Modified Files
--------------
src/test/modules/test_slru/test_slru.c | 35 +++++++++++++++++++++++++---------
src/tools/pgindent/typedefs.list       |  1 +
2 files changed, 27 insertions(+), 9 deletions(-)

Reply via email to