summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Bossart <nathan@postgresql.org>2025-09-04 15:34:48 -0500
committerNathan Bossart <nathan@postgresql.org>2025-09-04 15:34:48 -0500
commitd814d7fc3d5257ae258b502229fc7ca97c97270a (patch)
treee3a98b10315ffd13c2ea51475f6d94f9da8d230f
parentf0478149c34dfe02e0f43fc5f832a63a864dc364 (diff)
Revert recent change to RequestNamedLWLockTranche().
Commit 38b602b028 modified this function to allocate enough space for MAX_NAMED_TRANCHES (256) requests, which is likely far more than most clusters need. This commit reverts that change so that it first allocates enough space for only 16 requests and resizes the array when necessary. While at it, remove the check for too many tranches from this function. We can now rely on InitializeLWLocks() to do that check via its calls to LWLockNewTrancheId() for the named tranches. Reviewed-by: Sami Imseih <samimseih@gmail.com> Discussion: https://postgr.es/m/aLmzwC2dRbqk14y6%40nathan
-rw-r--r--src/backend/storage/lmgr/lwlock.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index 258cdebd0f5..fcbac5213a5 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -610,6 +610,7 @@ void
RequestNamedLWLockTranche(const char *tranche_name, int num_lwlocks)
{
NamedLWLockTrancheRequest *request;
+ static int NamedLWLockTrancheRequestsAllocated;
if (!process_shmem_requests_in_progress)
elog(FATAL, "cannot request additional LWLocks outside shmem_request_hook");
@@ -628,17 +629,22 @@ RequestNamedLWLockTranche(const char *tranche_name, int num_lwlocks)
if (NamedLWLockTrancheRequestArray == NULL)
{
+ NamedLWLockTrancheRequestsAllocated = 16;
NamedLWLockTrancheRequestArray = (NamedLWLockTrancheRequest *)
MemoryContextAlloc(TopMemoryContext,
- MAX_NAMED_TRANCHES
+ NamedLWLockTrancheRequestsAllocated
* sizeof(NamedLWLockTrancheRequest));
}
- if (NamedLWLockTrancheRequests >= MAX_NAMED_TRANCHES)
- ereport(ERROR,
- (errmsg("maximum number of tranches already registered"),
- errdetail("No more than %d tranches may be registered.",
- MAX_NAMED_TRANCHES)));
+ if (NamedLWLockTrancheRequests >= NamedLWLockTrancheRequestsAllocated)
+ {
+ int i = pg_nextpower2_32(NamedLWLockTrancheRequests + 1);
+
+ NamedLWLockTrancheRequestArray = (NamedLWLockTrancheRequest *)
+ repalloc(NamedLWLockTrancheRequestArray,
+ i * sizeof(NamedLWLockTrancheRequest));
+ NamedLWLockTrancheRequestsAllocated = i;
+ }
request = &NamedLWLockTrancheRequestArray[NamedLWLockTrancheRequests];
strlcpy(request->tranche_name, tranche_name, NAMEDATALEN);