agora inbox for [email protected]  
help / color / mirror / Atom feed
[PATCH v9a 06/22] ci: windows-2022 already openssl installed
87+ messages / 2 participants
[nested] [flat]

* [PATCH v9a 06/22] ci: windows-2022 already openssl installed
@ 2026-06-03 06:19  Andres Freund <[email protected]>
  0 siblings, 0 replies; 87+ messages in thread

From: Andres Freund @ 2026-06-03 06:19 UTC (permalink / raw)

The other installer is outdated and takes a while.
---
 .github/workflows/pg-ci.yml | 12 ------------
 1 file changed, 12 deletions(-)

diff --git a/.github/workflows/pg-ci.yml b/.github/workflows/pg-ci.yml
index 5ae8162d635..b05c3539ab6 100644
--- a/.github/workflows/pg-ci.yml
+++ b/.github/workflows/pg-ci.yml
@@ -767,17 +767,6 @@ jobs:
           # meson + ninja aren't preinstalled on windows-2022. Install via pip
           python -m pip install --upgrade meson ninja
 
-          # OpenSSL 1.1 via the slproweb installer (pinned to match the
-          # version used elsewhere in postgres CI).
-          curl.exe -fsSL -o openssl-setup.exe https://slproweb.com/download/Win64OpenSSL-1_1_1w.exe
-          Start-Process -Wait -FilePath ./openssl-setup.exe `
-            -ArgumentList '/DIR=d:\openssl\1.1\ /VERYSILENT /SP- /SUPPRESSMSGBOXES'
-          # The slproweb installer puts libcrypto-1_1-x64.dll / libssl-1_1-x64.dll
-          # in d:\openssl\1.1\bin\ and updates the system PATH. GH Actions
-          # snapshots PATH at job start though, so the running job won't
-          # see those DLLs and initdb.exe would crash silently at runtime.
-          # Push the bin dir onto GITHUB_PATH so it persists for later steps.
-          Add-Content $env:GITHUB_PATH "d:\openssl\1.1\bin"
 
           # Install IPC::Run.
           # - recommends_policy=0 keeps cpan from pulling in IO::Tty / IO::Pty,
@@ -811,7 +800,6 @@ jobs:
             ${{env.MESON_FEATURES}} ^
             --buildtype debug ^
             -Db_pch=true ^
-            -Dextra_lib_dirs=d:\openssl\1.1\lib -Dextra_include_dirs=d:\openssl\1.1\include ^
             -DTAR=${{env.TAR}} ^
             build
 
-- 
2.54.0.380.gc69baaf57b


--lyfxwjjve3vodszg
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
	filename="v9a-0007-ci-windows-Install-bison-flex-via-msys.patch"



^ permalink  raw  reply  [nested|flat] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ 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; 87+ 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] 87+ messages in thread


end of thread, other threads:[~2026-07-22 15:32 UTC | newest]

Thread overview: 87+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-06-03 06:19 [PATCH v9a 06/22] ci: windows-2022 already openssl installed Andres Freund <[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