Re: Improve LWLock tranche name visibility across backends
Sami Imseih <samimseih@gmail.com>
From: Sami Imseih <samimseih@gmail.com>
To: Nathan Bossart <nathandbossart@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, Andres Freund <andres@anarazel.de>, Bertrand Drouvot <bertranddrouvot.pg@gmail.com>,
Rahila Syed <rahilasyed90@gmail.com>, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2025-08-22T20:01:53Z
Lists: pgsql-hackers
Attachments
- v11-0001-Improve-LWLock-tranche-registration.patch (application/octet-stream) patch v11-0001
- v11-0002-Tests-for-LWLock-tranche-registration-improvemen.patch (application/octet-stream) patch v11-0002
>> If there is agreement on setting limits, may I propose >> 1024 tranches and NAMEDATALEN. Both seem reasonably sufficient. > Let's proceed with that approach for now. We can worry about the exact > limits once this is closer to commit. v11 implements the fixed size shared memory as discussed. So, as previous versions, we totally got rid of LWLockRegisterTranche and users can register tranches with either RequestNamedLWLockTranche ( during startup ) or LWLockNewTrancheId ( after startup ). The NamedLWLockTrancheArray, allocated at the end of MainLWLockArray with a fixed size limited to the number of tranches requested via RequestNamedLWLockTranche, has been changed in v11. It can now grow, up to a maximum number of total tranches, currently 1024, indexed by LWLockCounter. We don't need to keep track of the number of tranches in a separate variable, and can rely on LWLockCounter only. I kept the local array to serve consecutive reads and to avoid having to take a shared lock on shared memory every time GetLWTrancheName is called. A new LWLock to protect this array is required. LWLockInitialize also errors if the tranche used has not been registered, as was the case in the previous patch versions. Several error message to enforce the fixed size limits have also been added. The next patch set has 0001 which is the core change, and 0002 are the tests ( not sure if we need them, but they help in the review ). The tests in 0002 fail on EXEC_BACKEND due to a newly discovered bug [0], that repros on HEAD and likely other branches. -- Sami [0] https://www.postgresql.org/message-id/CAA5RZ0v1_15QPg5Sqd2Qz5rh_qcsyCeHHmRDY89xVHcy2yt5BQ%40mail.gmail.com
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