Re: Improve LWLock tranche name visibility across backends - Mailing list pgsql-hackers

From Nathan Bossart
Subject Re: Improve LWLock tranche name visibility across backends
Date
Msg-id aK4Vr0puSQqPI5vS@nathan
Whole thread Raw
In response to Re: Improve LWLock tranche name visibility across backends  (Sami Imseih <samimseih@gmail.com>)
Responses Re: Improve LWLock tranche name visibility across backends
List 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



pgsql-hackers by date:

Previous
From: Jacob Champion
Date:
Subject: Re: pgsql: oauth: Add unit tests for multiplexer handling
Next
From: Bruce Momjian
Date:
Subject: Re: plan shape work