Re: Improve LWLock tranche name visibility across backends

Bertrand Drouvot <bertranddrouvot.pg@gmail.com>

From: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
To: Sami Imseih <samimseih@gmail.com>
Cc: Nathan Bossart <nathandbossart@gmail.com>, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2025-08-04T07:56:43Z
Lists: pgsql-hackers
Hi,

On Fri, Aug 01, 2025 at 01:15:24PM -0500, Sami Imseih wrote:
> I think we could add a local backend copy that stays up to date with the
> DSA. One idea would be to use an atomic counter to track the number of
> entries in the DSA and compare it with a local backend counter whenever the
> tranche name lookup occurs. If the atomic counter is higher (since we
> don't have deletions),
> we can update the local copy. Updating the local table should be a
> rare occurrence, but it would
> require an additional atomic fetch every time the name lookup occurs, in all the
> above code paths.
> 
> Perhaps there's a better approach?

I was thinking to switch to the DSA (and update local copy) when a name is
not found in the local copy. That way there is no need to maintain a counter and
the DSA overhead should be rare enough.

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().