pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nathan Bossart <nathan@postgresql.org>
Subject: [PATCH v1 1/1] fix LWLock shmem reinitialization
Date: Tue, 16 Sep 2025 22:11:47 -0500

---
 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--

Message-ID: <no-message-id-19396@localhost>
Permalink:  ../no-message-id-19396@localhost/
Also on:    postgresql.org/message-id/no-message-id-19396@localhost

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: nathan@postgresql.org
  Subject: Re: [PATCH v1 1/1] fix LWLock shmem reinitialization
  In-Reply-To: <no-message-id-19396@localhost>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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