Move MAX_BACKENDS to procnumber.h
authorAndres Freund <[email protected]>
Mon, 24 Feb 2025 10:39:17 +0000 (05:39 -0500)
committerAndres Freund <[email protected]>
Mon, 24 Feb 2025 11:23:41 +0000 (06:23 -0500)
MAX_BACKENDS influences many things besides postmaster. I e.g. noticed that we
don't have static assertions ensuring BUF_REFCOUNT_MASK is big enough for
MAX_BACKENDS, adding them would require including postmaster.h in
buf_internals.h which doesn't seem right.

While at that, add MAX_BACKENDS_BITS, as that's useful in various places for
static assertions (to be added in subsequent commits).

Reviewed-by: Thomas Munro <[email protected]>
Discussion: https://postgr.es/m/wptizm4qt6yikgm2pt52xzyv6ycmqiutloyvypvmagn7xvqkce@d4xuv3mylpg4

src/backend/storage/lmgr/lwlock.c
src/backend/utils/adt/xid8funcs.c
src/backend/utils/init/postinit.c
src/backend/utils/misc/guc_tables.c
src/include/postmaster/postmaster.h
src/include/storage/procnumber.h

index 8a7fb6a22c6a44206ebd3fcfcc7153b9c790f642..79cc48b23c486e5806860f87de5c039bbb66548f 100644 (file)
@@ -80,9 +80,9 @@
 #include "pg_trace.h"
 #include "pgstat.h"
 #include "port/pg_bitutils.h"
-#include "postmaster/postmaster.h"
 #include "storage/proc.h"
 #include "storage/proclist.h"
+#include "storage/procnumber.h"
 #include "storage/spin.h"
 #include "utils/memutils.h"
 
index 20b28b2528c8f2df96b41f84aca28912beb2fd87..88d798fbf4bc5522215c11fb768cbd7423ac2df1 100644 (file)
@@ -32,9 +32,9 @@
 #include "lib/qunique.h"
 #include "libpq/pqformat.h"
 #include "miscadmin.h"
-#include "postmaster/postmaster.h"
 #include "storage/lwlock.h"
 #include "storage/procarray.h"
+#include "storage/procnumber.h"
 #include "utils/builtins.h"
 #include "utils/memutils.h"
 #include "utils/snapmgr.h"
index 01bb6a410cb83702e77be18191840f2da393ec82..318600d6d02e2785071a3d5abd14baa76c6d0ea6 100644 (file)
@@ -49,6 +49,7 @@
 #include "storage/lmgr.h"
 #include "storage/proc.h"
 #include "storage/procarray.h"
+#include "storage/procnumber.h"
 #include "storage/procsignal.h"
 #include "storage/sinvaladt.h"
 #include "storage/smgr.h"
index 3f1c7b1ebf630fe2ff9f59c4b37ab0550f6f6458..690bf96ef030b4daba8e87b139324fdf45cfd569 100644 (file)
@@ -77,6 +77,7 @@
 #include "storage/large_object.h"
 #include "storage/pg_shmem.h"
 #include "storage/predicate.h"
+#include "storage/procnumber.h"
 #include "storage/standby.h"
 #include "tcop/backend_startup.h"
 #include "tcop/tcopprot.h"
index d8a9f14b3b89222b61bfe37c5c80ba4e42c81cbd..b6a3f275a1b4b1427dc8a0c7239715f022e6b232 100644 (file)
@@ -126,18 +126,6 @@ extern PMChild *AllocDeadEndChild(void);
 extern bool ReleasePostmasterChildSlot(PMChild *pmchild);
 extern PMChild *FindPostmasterChildByPid(int pid);
 
-/*
- * Note: MAX_BACKENDS is limited to 2^18-1 because that's the width reserved
- * for buffer references in buf_internals.h.  This limitation could be lifted
- * by using a 64bit state; but it's unlikely to be worthwhile as 2^18-1
- * backends exceed currently realistic configurations. Even if that limitation
- * were removed, we still could not a) exceed 2^23-1 because inval.c stores
- * the ProcNumber as a 3-byte signed integer, b) INT_MAX/4 because some places
- * compute 4*MaxBackends without any overflow check.  This is rechecked in the
- * relevant GUC check hooks and in RegisterBackgroundWorker().
- */
-#define MAX_BACKENDS   0x3FFFF
-
 /*
  * These values correspond to the special must-be-first options for dispatching
  * to various subprograms.  parse_dispatch_option() can be used to convert an
index 7cf981ab673273c319f4866ec6b6ed799bd41da7..75c2c7a17c05af4435e9f08050c0b944cb27a4c6 100644 (file)
@@ -25,6 +25,19 @@ typedef int ProcNumber;
 
 #define INVALID_PROC_NUMBER        (-1)
 
+/*
+ * Note: MAX_BACKENDS_BITS is 18 as that is the space available for buffer
+ * refcounts in buf_internals.h.  This limitation could be lifted by using a
+ * 64bit state; but it's unlikely to be worthwhile as 2^18-1 backends exceed
+ * currently realistic configurations. Even if that limitation were removed,
+ * we still could not a) exceed 2^23-1 because inval.c stores the ProcNumber
+ * as a 3-byte signed integer, b) INT_MAX/4 because some places compute
+ * 4*MaxBackends without any overflow check.  This is rechecked in the
+ * relevant GUC check hooks and in RegisterBackgroundWorker().
+ */
+#define MAX_BACKENDS_BITS      18
+#define MAX_BACKENDS           ((1U << MAX_BACKENDS_BITS)-1)
+
 /*
  * Proc number of this backend (same as GetNumberFromPGProc(MyProc))
  */