Re: Clean up NamedLWLockTranche stuff

Heikki Linnakangas <hlinnaka@iki.fi>

From: Heikki Linnakangas <hlinnaka@iki.fi>
To: Sami Imseih <samimseih@gmail.com>
Cc: Nathan Bossart <nathandbossart@gmail.com>, Robert Haas <robertmhaas@gmail.com>, "pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>
Date: 2026-03-27T09:45:56Z
Lists: pgsql-hackers
On 27/03/2026 06:49, Sami Imseih wrote:
>> +/* backend-local copy of NamedLWLockTranches->num_user_defined */
>> +static int  LocalNumUserDefinedTranches;
> 
>> The comment here should reference "LWLockTranches->num_user_defined "
>> instead.
> 
>> Also, there are a few places in lwlock.c where "named tranches" is mentioned.
>> Maybe we should just say "user-defined tranches" instead?
> 
> Like the attached.

> @@ -460,7 +460,7 @@ LWLockShmemInit(void)
>  }
>  
>  /*
> - * Initialize LWLocks that are fixed and those belonging to named tranches.
> + * Initialize LWLocks that are fixed and those belonging to user-defined tranches.
>   */
>  static void
>  InitializeLWLocks(int numLocks)

Only tranches requested with RequestNamedLWLockTranche() have locks in 
the main array, so I reworded this some more to:

  /*
   * Initialize LWLocks for built-in tranches and those requested with
   * RequestNamedLWLockTranche().
   */

Committed with that little change, thanks!

- Heikki




Commits

  1. Fix outdated comment on MainLWLockArray

  2. Fix RequestNamedLWLockTranche in single-user mode

  3. Minor comment fixes to yesterday's LWLock tranche refactoring

  4. Move ShmemIndexLock into ShmemAllocator

  5. Use ShmemInitStruct to allocate lwlock.c's shared memory

  6. Use a separate spinlock to protect LWLockTranches

  7. Refactor how user-defined LWLock tranches are stored in shmem

  8. Rename MAX_NAMED_TRANCHES to MAX_USER_DEFINED_TRANCHES

  9. Fix re-initialization of LWLock-related shared memory.