]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Rename MAX_NAMED_TRANCHES to MAX_USER_DEFINED_TRANCHES
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Thu, 26 Mar 2026 21:46:04 +0000 (23:46 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Thu, 26 Mar 2026 21:46:04 +0000 (23:46 +0200)
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 <nathandbossart@gmail.com>
Reviewed-by: Sami Imseih <samimseih@gmail.com>
Discussion: https://www.postgresql.org/message-id/47aaf57e-1b7b-4e12-bda2-0316081ff50e@iki.fi

src/backend/storage/lmgr/lwlock.c

index 49382de88fc3d64be4ad78d7d3178a2fd0da5385..0980fcc55f9c94948607759415484ecf74e9a3d6 100644 (file)
@@ -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)++;