pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
[PATCH v1 1/1] fix LWLock shmem reinitialization
1+ messages / 1 participants
[nested] [flat]

* [PATCH v1 1/1] fix LWLock shmem reinitialization
@ 2025-09-17 03:11  Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 1+ messages in thread

From: Nathan Bossart @ 2025-09-17 03:11 UTC (permalink / raw)

---
 src/backend/storage/lmgr/lwlock.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

inline patch 1: src/backend/storage/lmgr/lwlock.c (+10/-8 lines) download inline-1.patchdiff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c index 46c82c63ca5..694e9e33510 100644 --- a/src/backend/storage/lmgr/lwlock.c +++ b/src/backend/storage/lmgr/lwlock.c @@ -192,6 +192,9 @@ typedef struct NamedLWLockTrancheRequest int NamedLWLockTrancheRequests = 0; NamedLWLockTrancheRequest *NamedLWLockTrancheRequestArray = NULL; +/* postmaster's local copy of the request array */ +static NamedLWLockTrancheRequest *LocalNamedLWLockTrancheRequestArray; + /* shared memory counter of registered tranches */ int *LWLockCounter = NULL; @@ -382,7 +385,7 @@ NumLWLocksForNamedTranches(void) int i; for (i = 0; i < NamedLWLockTrancheRequests; i++) - numLocks += NamedLWLockTrancheRequestArray[i].num_lwlocks; + numLocks += LocalNamedLWLockTrancheRequestArray[i].num_lwlocks; return numLocks; } @@ -457,9 +460,8 @@ CreateLWLocks(void) */ if (NamedLWLockTrancheRequests > 0) { - memcpy(ptr, NamedLWLockTrancheRequestArray, + memcpy(ptr, LocalNamedLWLockTrancheRequestArray, NamedLWLockTrancheRequests * sizeof(NamedLWLockTrancheRequest)); - pfree(NamedLWLockTrancheRequestArray); NamedLWLockTrancheRequestArray = (NamedLWLockTrancheRequest *) ptr; ptr += NamedLWLockTrancheRequests * sizeof(NamedLWLockTrancheRequest); } @@ -648,10 +650,10 @@ RequestNamedLWLockTranche(const char *tranche_name, int num_lwlocks) errdetail("LWLock tranche names must be no longer than %d bytes.", NAMEDATALEN - 1))); - if (NamedLWLockTrancheRequestArray == NULL) + if (LocalNamedLWLockTrancheRequestArray == NULL) { NamedLWLockTrancheRequestsAllocated = 16; - NamedLWLockTrancheRequestArray = (NamedLWLockTrancheRequest *) + LocalNamedLWLockTrancheRequestArray = (NamedLWLockTrancheRequest *) MemoryContextAlloc(TopMemoryContext, NamedLWLockTrancheRequestsAllocated * sizeof(NamedLWLockTrancheRequest)); @@ -661,13 +663,13 @@ RequestNamedLWLockTranche(const char *tranche_name, int num_lwlocks) { int i = pg_nextpower2_32(NamedLWLockTrancheRequests + 1); - NamedLWLockTrancheRequestArray = (NamedLWLockTrancheRequest *) - repalloc(NamedLWLockTrancheRequestArray, + LocalNamedLWLockTrancheRequestArray = (NamedLWLockTrancheRequest *) + repalloc(LocalNamedLWLockTrancheRequestArray, i * sizeof(NamedLWLockTrancheRequest)); NamedLWLockTrancheRequestsAllocated = i; } - request = &NamedLWLockTrancheRequestArray[NamedLWLockTrancheRequests]; + request = &LocalNamedLWLockTrancheRequestArray[NamedLWLockTrancheRequests]; strlcpy(request->tranche_name, tranche_name, NAMEDATALEN); request->num_lwlocks = num_lwlocks; NamedLWLockTrancheRequests++; -- 2.39.5 (Apple Git-154)
--90DLrh6oh+Wqjmvg-- ^ permalink raw reply [nested|flat] 1+ messages in thread


only message in thread

Thread overview: 1+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-09-17 03:11 [PATCH v1 1/1] fix LWLock shmem reinitialization Nathan Bossart <nathan@postgresql.org>

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