Re: Improve LWLock tranche name visibility across backends
Nathan Bossart <nathandbossart@gmail.com>
From: Nathan Bossart <nathandbossart@gmail.com>
To: Sami Imseih <samimseih@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2025-07-11T21:24:18Z
Lists: pgsql-hackers
On Wed, Jul 09, 2025 at 04:39:48PM -0500, Sami Imseih wrote: > Attached is a proof of concept that does not alter the > LWLockRegisterTranche API. IMHO we should consider modifying the API, because right now you have to call LWLockRegisterTranche() in each backend. Why not accept the name as an argument for LWLockNewTrancheId() and only require it to be called once during your shared memory initialization? In any case, a lot of existing code will continue to call it in each backend unless the API changes. > Instead, it detects when a registration is > performed by a normal backend and stores the tranche name in shared memory, > using a dshash keyed by tranche ID. Tranche name lookup now proceeds in > the order of built-in names, the local list, and finally the shared memory. > The fallback name "extension" can still be returned if an extension does > not register a tranche. Why do we need three different places for the lock names? Is there a reason we can't put it all in shared memory? > 1/ There is currently no mechanism for deleting entries. I am not sure whether > this is a concern, since the size of the table would grow only with the > number of extensions and the number of LWLocks they initialize, which is > typically small. That said, others may have different thoughts on this. I don't see any strong reason to allow deletion unless we started to reclaim tranche IDs, and I don't see any strong reason for that, either. > 2/ What is the appropriate size limit for a tranche name. The work done > in [0] caps the tranche name to 128 bytes for the dshash tranche, and > 128 bytes + length of " DSA" suffix for the dsa tranche. Also, the > existing RequestNamedLWLockTranche caps the name to NAMEDATALEN. Currently, > LWLockRegisterTranche does not have a limit on the tranche name. I wonder > if we also need to take care of this and implement some common limit that > applies to tranch names regardless of how they're created? Do we need to set a limit? If we're using a DSA and dshash, we could let folks use arbitrary long tranche names, right? The reason for the limit in the DSM registry is because the name is used as the key for the dshash table. -- nathan
Commits
-
test_dsa: Avoid leaking LWLock tranches.
- c5c74282f2ea 19 (unreleased) landed
-
Teach DSM registry to ERROR if attaching to an uninitialized entry.
- b26d76f64327 18.2 landed
- ac2800ddc185 17.8 landed
- 1165a933aab1 19 (unreleased) landed
-
Add a test harness for the LWLock tranche code.
- 16607718c010 19 (unreleased) landed
-
Revert recent change to RequestNamedLWLockTranche().
- d814d7fc3d52 19 (unreleased) landed
-
Move dynamically-allocated LWLock tranche names to shared memory.
- 38b602b0289f 19 (unreleased) landed
-
Prepare DSM registry for upcoming changes to LWLock tranche names.
- 5487058b56e0 19 (unreleased) landed
-
Add GetNamedDSA() and GetNamedDSHash().
- fe07100e82b0 19 (unreleased) cited