pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nathan Bossart <nathandbossart@gmail.com>
To: Sami Imseih <samimseih@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Andres Freund <andres@anarazel.de>
Cc: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Cc: Rahila Syed <rahilasyed90@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: Improve LWLock tranche name visibility across backends
Date: Tue, 26 Aug 2025 15:14:39 -0500
Message-ID: <aK4Vr0puSQqPI5vS@nathan> (raw)
In-Reply-To: <CAA5RZ0u=Fb8dDdPrEzawYjVqAmYB_PTP4Yy3tV78=_gcvXrjjA@mail.gmail.com>
References: <CAA5RZ0tg0-O3KVrP9UrZWm18OECxK87WNJo=cZy=Gevc+Ui5oA@mail.gmail.com>
	<aKTqiofwo1Eif_3w@nathan>
	<CAA5RZ0tKoQeTuRsFmUjPAOEXBiyEGyePsqCAy-_oX4eFHSCmHw@mail.gmail.com>
	<aKzP-H-KzPay-ByM@nathan>
	<CAA5RZ0vh7jrGDwJgkKtw-LR5fBH-tRNpGJnPivdKedtqJ7HGCQ@mail.gmail.com>
	<aKzZV8Acib6pFesE@nathan>
	<CAA5RZ0vWh2uxG99iUb3P4nsoDLk0x7Yuai83AbbGs3YZvJM8QQ@mail.gmail.com>
	<aKz8cHo2oBr-6uq5@nathan>
	<CAA5RZ0uYpXw8yTpCPiDAvwt9WtXesKM_vebbCjBm4MQBVnchMw@mail.gmail.com>
	<CAA5RZ0u=Fb8dDdPrEzawYjVqAmYB_PTP4Yy3tV78=_gcvXrjjA@mail.gmail.com>

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





view thread (107+ messages)  latest in thread

Message-ID: <aK4Vr0puSQqPI5vS@nathan>
Permalink:  ../aK4Vr0puSQqPI5vS@nathan/
Also on:    postgresql.org/message-id/aK4Vr0puSQqPI5vS@nathan

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: nathandbossart@gmail.com, samimseih@gmail.com, tgl@sss.pgh.pa.us, andres@anarazel.de, bertranddrouvot.pg@gmail.com, rahilasyed90@gmail.com
  Subject: Re: Improve LWLock tranche name visibility across backends
  In-Reply-To: <aK4Vr0puSQqPI5vS@nathan>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox