Re: Improve LWLock tranche name visibility across backends
Sami Imseih <samimseih@gmail.com>
From: Sami Imseih <samimseih@gmail.com>
To: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Cc: Nathan Bossart <nathandbossart@gmail.com>,
pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2025-08-06T16:54:33Z
Lists: pgsql-hackers
Thanks for testing!
> which is what we expect.
>
> But if I look at LWLockTrancheNames.local (for the process that queried pg_stat_activity):
>
> (gdb) p LWLockTrancheNames.local[0]
> $1 = 0x0
> (gdb) p LWLockTrancheNames.local[1]
> $2 = 0x7b759a81b038 "BDT_Lck"
>
> It looks like there is an indexing issue, as we should start at index 0.
>
> Issue 2 / question --
>
> If I call LWLockNewTrancheId("BDT_play2") multiple times to ensure that
>
>
> Then if, in another backend, I call GetLWTrancheName by querying pg_stat_activity
> then I see "BDT_Lck" being reported as wait event name (which is good).
>
> The thing that worries me a bit is that the local cache is populated only for
> "BDT_Lck", but not for all the other "BDT_play2".
Issue #1 and issue #2 are related. In both cases you have a registered wait
event that only lives in shared memory, but was never required to be
accessed by pg_stat_activity, so it was never cached locally.
> When we need to populate the local cache, would it be better to populate
> it with the whole dsa content instead of just the current missing ID as done
> in GetLWTrancheName():
I do agree that we should just sync the local cache totally whenever we
can't find the tranche name in the local cache. Will fix in the next rev.
--
Sami
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