From cc88481aeb98326c528acb07114dd92f06de28c0 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Thu, 26 Mar 2026 23:46:04 +0200 Subject: [PATCH] Rename MAX_NAMED_TRANCHES to MAX_USER_DEFINED_TRANCHES The "named tranches" term is a little confusing. In most places it refers to tranches requested with RequestNamedLWLockTranche(), even though all built-in tranches and tranches allocated with LWLockNewTrancheId() also have a name. But in MAX_NAMED_TRANCHES, it refers to tranches requested with either RequestNamedLWLockTranche() or LWLockNewTrancheId(), as it's the maximum of all of those in total. The "user defined" term is already used in LWTRANCHE_FIRST_USER_DEFINED, so let's standardize on that to mean tranches allocated with either RequestNamedLWLockTranche() or LWLockNewTrancheId(). Reviewed-by: Nathan Bossart Reviewed-by: Sami Imseih Discussion: https://www.postgresql.org/message-id/47aaf57e-1b7b-4e12-bda2-0316081ff50e@iki.fi --- src/backend/storage/lmgr/lwlock.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c index 49382de88fc..0980fcc55f9 100644 --- a/src/backend/storage/lmgr/lwlock.c +++ b/src/backend/storage/lmgr/lwlock.c @@ -202,7 +202,7 @@ int *LWLockCounter = NULL; /* backend-local counter of registered tranches */ static int LocalLWLockCounter; -#define MAX_NAMED_TRANCHES 256 +#define MAX_USER_DEFINED_TRANCHES 256 static void InitializeLWLocks(void); static inline void LWLockReportWaitStart(LWLock *lock); @@ -392,7 +392,8 @@ NumLWLocksForNamedTranches(void) } /* - * Compute shmem space needed for LWLocks and named tranches. + * Compute shmem space needed for user-defined tranches and the main LWLock + * array. */ Size LWLockShmemSize(void) @@ -415,9 +416,9 @@ LWLockShmemSize(void) /* Space for dynamic allocation counter. */ size = MAXALIGN(sizeof(int)); - /* Space for named tranches. */ - size = add_size(size, mul_size(MAX_NAMED_TRANCHES, sizeof(char *))); - size = add_size(size, mul_size(MAX_NAMED_TRANCHES, NAMEDATALEN)); + /* Space for user-defined tranches. */ + size = add_size(size, mul_size(MAX_USER_DEFINED_TRANCHES, sizeof(char *))); + size = add_size(size, mul_size(MAX_USER_DEFINED_TRANCHES, NAMEDATALEN)); /* * Make space for named tranche requests. This is done for the benefit of @@ -435,8 +436,8 @@ LWLockShmemSize(void) } /* - * Allocate shmem space for the main LWLock array and all tranches and - * initialize it. + * Allocate shmem space for user-defined tranches and the main LWLock array, + * and initialize it. */ void CreateLWLocks(void) @@ -454,10 +455,10 @@ CreateLWLocks(void) *LWLockCounter = LWTRANCHE_FIRST_USER_DEFINED; ptr += MAXALIGN(sizeof(int)); - /* Initialize tranche names */ + /* Initialize user-defined tranche names */ LWLockTrancheNames = (char **) ptr; - ptr += MAX_NAMED_TRANCHES * sizeof(char *); - for (int i = 0; i < MAX_NAMED_TRANCHES; i++) + ptr += MAX_USER_DEFINED_TRANCHES * sizeof(char *); + for (int i = 0; i < MAX_USER_DEFINED_TRANCHES; i++) { LWLockTrancheNames[i] = ptr; ptr += NAMEDATALEN; @@ -616,13 +617,13 @@ LWLockNewTrancheId(const char *name) */ SpinLockAcquire(ShmemLock); - if (*LWLockCounter - LWTRANCHE_FIRST_USER_DEFINED >= MAX_NAMED_TRANCHES) + if (*LWLockCounter - LWTRANCHE_FIRST_USER_DEFINED >= MAX_USER_DEFINED_TRANCHES) { SpinLockRelease(ShmemLock); ereport(ERROR, (errmsg("maximum number of tranches already registered"), errdetail("No more than %d tranches may be registered.", - MAX_NAMED_TRANCHES))); + MAX_USER_DEFINED_TRANCHES))); } result = (*LWLockCounter)++;