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: 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-26T20:14:39Z
Lists: pgsql-hackers
On Tue, Aug 26, 2025 at 02:56:22PM -0500, Sami Imseih wrote: > Here is v12 that replaces the LWLock to access the shared memory with a > ShmemLock and implements a local counter. This looks much closer to what I was imagining. /* Initialize the LWLock tranche for the DSA. */ - dsa_state->tranche = LWLockNewTrancheId(); + dsa_state->tranche = LWLockNewTrancheId(dsa_state->tranche_name); sprintf(dsa_state->tranche_name, "%s%s", name, DSMR_DSA_TRANCHE_SUFFIX); - LWLockRegisterTranche(dsa_state->tranche, dsa_state->tranche_name); /* Initialize the LWLock tranche for the dshash table. */ - dsh_state->tranche = LWLockNewTrancheId(); + dsh_state->tranche = LWLockNewTrancheId(dsh_state->tranche_name); strcpy(dsh_state->tranche_name, name); - LWLockRegisterTranche(dsh_state->tranche, dsh_state->tranche_name); We probably need to do the sprintf/strcpy before LWLockNewTrancheId(). Also, I'm thinking we should just use the same tranche for both the DSA and the dshash table [0] to evade the DSMR_DSA_TRANCHE_SUFFIX problem, i.e., those tranche names potentially require more space. + /* Space for name of each tranche. */ + size = add_size(size, mul_size(MAX_NAMED_TRANCHES, MAX_NAMED_TRANCHES)); Presumably one of the mul_size() arguments should be MAX_NAMED_TRANCHES_NAME_LEN. +NamedLWLockTrancheArray "Waiting to access the named LWLock tranches array." +PG_LWLOCK(54, NamedLWLockTrancheArray) These can be removed now, right? [0] https://postgr.es/m/aKzIg1JryN1qhNuy%40nathan -- 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