From 02fbbbf691ab28f267f5426bb4f3ba7c8cd950dc Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Sun, 26 Jan 2025 14:13:57 -0500
Subject: [PATCH v1 2/3] bufmgr: Assert that MAX_BACKENDS is compatible with
 BufferDesc.state

Author:
Reviewed-by:
Discussion: https://postgr.es/m/
Backpatch:
---
 src/include/storage/buf_internals.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/include/storage/buf_internals.h b/src/include/storage/buf_internals.h
index 1a65342177d..d93493f746b 100644
--- a/src/include/storage/buf_internals.h
+++ b/src/include/storage/buf_internals.h
@@ -39,8 +39,9 @@
  *
  * The definition of buffer state components is below.
  */
+#define BUF_REFCOUNT_BITS 18
 #define BUF_REFCOUNT_ONE 1
-#define BUF_REFCOUNT_MASK ((1U << 18) - 1)
+#define BUF_REFCOUNT_MASK ((1U << BUF_REFCOUNT_BITS) - 1)
 #define BUF_USAGECOUNT_MASK 0x003C0000U
 #define BUF_USAGECOUNT_ONE (1U << 18)
 #define BUF_USAGECOUNT_SHIFT 18
@@ -77,6 +78,9 @@
  */
 #define BM_MAX_USAGE_COUNT	5
 
+StaticAssertDecl(MAX_BACKENDS <= ((1 << BUF_REFCOUNT_BITS) - 1),
+				 "MAX_BACKENDS is too big for BUF_REFCOUNT_BITS");
+
 /*
  * Buffer tag identifies which disk block the buffer contains.
  *
-- 
2.48.1.76.g4e746b1a31.dirty

