agora inbox for [email protected]help / color / mirror / Atom feed
[PATCH 3/6] Move conversion of a "historic" to MVCC snapshot to a separate function. 93+ messages / 2 participants [nested] [flat]
* [PATCH 3/6] Move conversion of a "historic" to MVCC snapshot to a separate function. @ 2026-01-12 16:30 Antonin Houska <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Antonin Houska @ 2026-01-12 16:30 UTC (permalink / raw) The conversion is now handled by SnapBuildMVCCFromHistoric(). REPACK CONCURRENTLY will also need it. --- src/backend/replication/logical/snapbuild.c | 59 +++++++++++++++++---- src/backend/utils/time/snapmgr.c | 3 +- src/include/replication/snapbuild.h | 1 + src/include/utils/snapmgr.h | 1 + 4 files changed, 52 insertions(+), 12 deletions(-) diff --git a/src/backend/replication/logical/snapbuild.c b/src/backend/replication/logical/snapbuild.c index 7f79621b57e..a738ad8a864 100644 --- a/src/backend/replication/logical/snapbuild.c +++ b/src/backend/replication/logical/snapbuild.c @@ -440,10 +440,7 @@ Snapshot SnapBuildInitialSnapshot(SnapBuild *builder) { Snapshot snap; - TransactionId xid; TransactionId safeXid; - TransactionId *newxip; - int newxcnt = 0; Assert(XactIsoLevel == XACT_REPEATABLE_READ); Assert(builder->building_full_snapshot); @@ -485,7 +482,35 @@ SnapBuildInitialSnapshot(SnapBuild *builder) MyProc->xmin = snap->xmin; - /* allocate in transaction context */ + /* Convert the historic snapshot to MVCC snapshot. */ + return SnapBuildMVCCFromHistoric(snap, true); +} + +/* + * Turn a historic MVCC snapshot into an ordinary MVCC snapshot. + * + * Unlike a regular (non-historic) MVCC snapshot, the 'xip' array of this + * snapshot contains not only running main transactions, but also their + * subtransactions. On the other hand, 'subxip' will usually be empty. This + * difference does not affect the result of XidInMVCCSnapshot() because it + * searches both in 'xip' and 'subxip'. + * + * Pass true for 'in_place' if you don't care about modifying the source + * snapshot. If you need a new instance, and one that was allocated as a + * single chunk of memory, pass false. + */ +Snapshot +SnapBuildMVCCFromHistoric(Snapshot snapshot, bool in_place) +{ + TransactionId xid; + TransactionId *oldxip = snapshot->xip; + uint32 oldxcnt = snapshot->xcnt; + TransactionId *newxip; + int newxcnt = 0; + Snapshot result; + + Assert(snapshot->snapshot_type == SNAPSHOT_HISTORIC_MVCC); + newxip = palloc_array(TransactionId, GetMaxSnapshotXidCount()); /* @@ -494,7 +519,7 @@ SnapBuildInitialSnapshot(SnapBuild *builder) * classical snapshot by marking all non-committed transactions as * in-progress. This can be expensive. */ - for (xid = snap->xmin; NormalTransactionIdPrecedes(xid, snap->xmax);) + for (xid = snapshot->xmin; NormalTransactionIdPrecedes(xid, snapshot->xmax);) { void *test; @@ -502,7 +527,7 @@ SnapBuildInitialSnapshot(SnapBuild *builder) * Check whether transaction committed using the decoding snapshot * meaning of ->xip. */ - test = bsearch(&xid, snap->xip, snap->xcnt, + test = bsearch(&xid, snapshot->xip, snapshot->xcnt, sizeof(TransactionId), xidComparator); if (test == NULL) @@ -519,11 +544,25 @@ SnapBuildInitialSnapshot(SnapBuild *builder) } /* adjust remaining snapshot fields as needed */ - snap->snapshot_type = SNAPSHOT_MVCC; - snap->xcnt = newxcnt; - snap->xip = newxip; + snapshot->xcnt = newxcnt; + snapshot->xip = newxip; + + if (in_place) + result = snapshot; + else + { + result = CopySnapshot(snapshot); + + /* Restore the original values so the source is intact. */ + snapshot->xip = oldxip; + snapshot->xcnt = oldxcnt; + + /* newxip has been copied */ + pfree(newxip); + } + result->snapshot_type = SNAPSHOT_MVCC; - return snap; + return result; } /* diff --git a/src/backend/utils/time/snapmgr.c b/src/backend/utils/time/snapmgr.c index 2e6197f5f35..3af1b366adf 100644 --- a/src/backend/utils/time/snapmgr.c +++ b/src/backend/utils/time/snapmgr.c @@ -213,7 +213,6 @@ typedef struct ExportedSnapshot static List *exportedSnapshots = NIL; /* Prototypes for local functions */ -static Snapshot CopySnapshot(Snapshot snapshot); static void UnregisterSnapshotNoOwner(Snapshot snapshot); static void FreeSnapshot(Snapshot snapshot); static void SnapshotResetXmin(void); @@ -604,7 +603,7 @@ SetTransactionSnapshot(Snapshot sourcesnap, VirtualTransactionId *sourcevxid, * The copy is palloc'd in TopTransactionContext and has initial refcounts set * to 0. The returned snapshot has the copied flag set. */ -static Snapshot +Snapshot CopySnapshot(Snapshot snapshot) { Snapshot newsnap; diff --git a/src/include/replication/snapbuild.h b/src/include/replication/snapbuild.h index ccded021433..34383dea776 100644 --- a/src/include/replication/snapbuild.h +++ b/src/include/replication/snapbuild.h @@ -73,6 +73,7 @@ extern void FreeSnapshotBuilder(SnapBuild *builder); extern void SnapBuildSnapDecRefcount(Snapshot snap); extern Snapshot SnapBuildInitialSnapshot(SnapBuild *builder); +extern Snapshot SnapBuildMVCCFromHistoric(Snapshot snapshot, bool in_place); extern const char *SnapBuildExportSnapshot(SnapBuild *builder); extern void SnapBuildClearExportedSnapshot(void); extern void SnapBuildResetExportedSnapshotState(void); diff --git a/src/include/utils/snapmgr.h b/src/include/utils/snapmgr.h index b8c01a291a1..de824945f0b 100644 --- a/src/include/utils/snapmgr.h +++ b/src/include/utils/snapmgr.h @@ -63,6 +63,7 @@ extern Snapshot GetTransactionSnapshot(void); extern Snapshot GetLatestSnapshot(void); extern void SnapshotSetCommandId(CommandId curcid); +extern Snapshot CopySnapshot(Snapshot snapshot); extern Snapshot GetCatalogSnapshot(Oid relid); extern Snapshot GetNonHistoricCatalogSnapshot(Oid relid); extern void InvalidateCatalogSnapshot(void); -- 2.47.3 --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=v30-0004-Add-CONCURRENTLY-option-to-REPACK-command.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
* [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait @ 2026-07-22 15:32 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 93+ messages in thread From: Nathan Bossart @ 2026-07-22 15:32 UTC (permalink / raw) --- src/backend/storage/buffer/bufmgr.c | 16 ++++++++-------- src/backend/storage/lmgr/proc.c | 20 ++++++++++---------- src/include/storage/proc.h | 9 +++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3908529872a..a85547fa492 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6806,12 +6806,12 @@ LockBufferForCleanup(Buffer buffer) if (log_recovery_conflict_waits && waitStart == 0) waitStart = GetCurrentTimestamp(); - /* Publish the bufid that Startup process waits on */ - SetStartupBufferPinWaitBufId(buffer - 1); + /* Publish the buffer that Startup process waits on */ + SetStartupBufferPinWaitBuf(buffer); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); - /* Reset the published bufid */ - SetStartupBufferPinWaitBufId(-1); + /* Reset the published buffer */ + SetStartupBufferPinWaitBuf(InvalidBuffer); } else ProcWaitForSignal(WAIT_EVENT_BUFFER_CLEANUP); @@ -6865,18 +6865,18 @@ cleanup_lock_acquired: bool HoldingBufferPinThatDelaysRecovery(void) { - int bufid = GetStartupBufferPinWaitBufId(); + Buffer buffer = GetStartupBufferPinWaitBuf(); /* * If we get woken slowly then it's possible that the Startup process was * already woken by other backends before we got here. Also possible that * we get here by multiple interrupts or interrupts at inappropriate - * times, so make sure we do nothing if the bufid is not set. + * times, so make sure we do nothing if the buffer is not set. */ - if (bufid < 0) + if (buffer == InvalidBuffer) return false; - if (GetPrivateRefCount(bufid + 1) > 0) + if (GetPrivateRefCount(buffer) > 0) return true; return false; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9d6e69175a5..f973494abb1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -239,7 +239,7 @@ ProcGlobalShmemInit(void *arg) dlist_init(&ProcGlobal->autovacFreeProcs); dlist_init(&ProcGlobal->bgworkerFreeProcs); dlist_init(&ProcGlobal->walsenderFreeProcs); - ProcGlobal->startupBufferPinWaitBufId = -1; + ProcGlobal->startupBufferPinWaitBuf = InvalidBuffer; pg_atomic_init_u32(&ProcGlobal->avLauncherProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->walwriterProc, INVALID_PROC_NUMBER); pg_atomic_init_u32(&ProcGlobal->checkpointerProc, INVALID_PROC_NUMBER); @@ -760,30 +760,30 @@ InitAuxiliaryProcess(void) /* * Used from bufmgr to share the value of the buffer that Startup waits on, - * or to reset the value to "not waiting" (-1). This allows processing - * of recovery conflicts for buffer pins. Set is made before backends look - * at this value, so locking not required, especially since the set is - * an atomic integer set operation. + * or to reset the value to "not waiting" (InvalidBuffer). This allows + * processing of recovery conflicts for buffer pins. Set is made before + * backends look at this value, so locking not required, especially since + * the set is an atomic integer set operation. */ void -SetStartupBufferPinWaitBufId(int bufid) +SetStartupBufferPinWaitBuf(Buffer buffer) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - procglobal->startupBufferPinWaitBufId = bufid; + procglobal->startupBufferPinWaitBuf = buffer; } /* * Used by backends when they receive a request to check for buffer pin waits. */ -int -GetStartupBufferPinWaitBufId(void) +Buffer +GetStartupBufferPinWaitBuf(void) { /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - return procglobal->startupBufferPinWaitBufId; + return procglobal->startupBufferPinWaitBuf; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 03a1a466fa8..4c3f431b4eb 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -17,6 +17,7 @@ #include "access/xlogdefs.h" #include "lib/ilist.h" #include "miscadmin.h" +#include "storage/buf.h" #include "storage/latch.h" #include "storage/lock.h" #include "storage/pg_sema.h" @@ -498,8 +499,8 @@ typedef struct PROC_HDR /* Current shared estimate of appropriate spins_per_delay value */ int spins_per_delay; - /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ - int startupBufferPinWaitBufId; + /* Buffer that Startup process waits for pin on, or InvalidBuffer */ + Buffer startupBufferPinWaitBuf; } PROC_HDR; extern PGDLLIMPORT PROC_HDR *ProcGlobal; @@ -558,8 +559,8 @@ extern void InitProcess(void); extern void InitProcessPhase2(void); extern void InitAuxiliaryProcess(void); -extern void SetStartupBufferPinWaitBufId(int bufid); -extern int GetStartupBufferPinWaitBufId(void); +extern void SetStartupBufferPinWaitBuf(Buffer buffer); +extern Buffer GetStartupBufferPinWaitBuf(void); extern bool HaveNFreeProcs(int n, int *nfree); extern void ProcReleaseLocks(bool isCommit); -- 2.50.1 (Apple Git-155) --Xf36GNcW+0xZNily Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0005-convert-PROC_HDR-startupBufferPinWaitBuf-to-an-at.patch ^ permalink raw reply [nested|flat] 93+ messages in thread
end of thread, other threads:[~2026-07-22 15:32 UTC | newest] Thread overview: 93+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-01-12 16:30 [PATCH 3/6] Move conversion of a "historic" to MVCC snapshot to a separate function. Antonin Houska <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]> 2026-07-22 15:32 [PATCH v2 4/9] use Buffer instead of buffer ID for startup's buffer pin wait Nathan Bossart <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox