Re: Improve LWLock tranche name visibility across backends

Bertrand Drouvot <bertranddrouvot.pg@gmail.com>

From: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
To: Nathan Bossart <nathandbossart@gmail.com>
Cc: Sami Imseih <samimseih@gmail.com>, Tom Lane <tgl@sss.pgh.pa.us>, Andres Freund <andres@anarazel.de>, Rahila Syed <rahilasyed90@gmail.com>, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2025-09-01T10:18:46Z
Lists: pgsql-hackers

Attachments

Hi,

On Sat, Aug 30, 2025 at 09:14:46AM -0500, Nathan Bossart wrote:
> On Fri, Aug 29, 2025 at 09:51:38PM -0500, Nathan Bossart wrote:
> > I've also attached a rebased patch that addresses all the latest feedback.
> > A reworked verison of the test patch is also included, but that's mostly
> > intended for CI purposes and is still not intended for commit (yet).
> 
> And here's an attempt at fixing the alignment problems revealed by cfbot.

Indeed:

==24409==Using libbacktrace symbolizer.
../src/backend/storage/lmgr/lwlock.c:441:31: runtime error: store to misaligned address 0x7f7644188904 for type 'char *', which requires 8 byte alignment

Changes look good.

Not directly related, but I think that we can get rid of:

size = add_size(size, LWLOCK_PADDED_SIZE);

in LWLockShmemSize() and of:

ptr += LWLOCK_PADDED_SIZE - ((uintptr_t) ptr) % LWLOCK_PADDED_SIZE;

in CreateLWLocks(), and just make use of CACHELINEALIGN().

Attached, a patch doing so. It applies on top of your v20.

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

Commits

  1. test_dsa: Avoid leaking LWLock tranches.

  2. Teach DSM registry to ERROR if attaching to an uninitialized entry.

  3. Add a test harness for the LWLock tranche code.

  4. Revert recent change to RequestNamedLWLockTranche().

  5. Move dynamically-allocated LWLock tranche names to shared memory.

  6. Prepare DSM registry for upcoming changes to LWLock tranche names.

  7. Add GetNamedDSA() and GetNamedDSHash().