Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Add static asserts for MAX_BACKENDS limiting factors
authorAndres Freund <andres@anarazel.de>
Mon, 24 Feb 2025 10:39:27 +0000 (05:39 -0500)
committerAndres Freund <andres@anarazel.de>
Mon, 24 Feb 2025 11:23:41 +0000 (06:23 -0500)
So far the various dependencies were documented in the comment above
MAX_BACKENDS, but not checked.

Discussion: https://postgr.es/m/CA+COZaBO_s3LfALq=b+HcBHFSOEGiApVjrRacCe4VP9m7CJsNQ@mail.gmail.com

src/backend/storage/lmgr/deadlock.c
src/backend/utils/cache/inval.c
src/include/storage/buf_internals.h

index dc6923f8132dc0b42d085f8acbe1ed11d6d6af0f..c4bfaaa67ac8c8c1922c63a33e099e732c405cb8 100644 (file)
@@ -30,6 +30,7 @@
 #include "pgstat.h"
 #include "storage/lmgr.h"
 #include "storage/proc.h"
+#include "storage/procnumber.h"
 #include "utils/memutils.h"
 
 
@@ -191,6 +192,8 @@ InitDeadLockChecking(void)
     * last MaxBackends entries in possibleConstraints[] are reserved as
     * output workspace for FindLockCycle.
     */
+   StaticAssertStmt(MAX_BACKENDS_BITS <= (32 - 3),
+                    "MAX_BACKENDS_BITS too big for * 4");
    maxPossibleConstraints = MaxBackends * 4;
    possibleConstraints =
        (EDGE *) palloc(maxPossibleConstraints * sizeof(EDGE));
index 6aff1ec01d78da379f388c4182480f3e3fdfb2c9..700ccb6df9b8726e299eaedcca320867899939d1 100644 (file)
 #include "catalog/catalog.h"
 #include "catalog/pg_constraint.h"
 #include "miscadmin.h"
+#include "storage/procnumber.h"
 #include "storage/sinval.h"
 #include "storage/smgr.h"
 #include "utils/catcache.h"
@@ -1651,6 +1652,10 @@ CacheInvalidateSmgr(RelFileLocatorBackend rlocator)
 {
    SharedInvalidationMessage msg;
 
+   /* verify optimization stated above stays valid */
+   StaticAssertStmt(MAX_BACKENDS_BITS <= 23,
+                    "MAX_BACKEND_BITS is too big for inval.c");
+
    msg.sm.id = SHAREDINVALSMGR_ID;
    msg.sm.backend_hi = rlocator.backend >> 16;
    msg.sm.backend_lo = rlocator.backend & 0xffff;
index d830d5c98418b99e4c22ac717b0fb4c32c9f9dc9..8b32fb108b037e6a081e2a8567f563803896cdb4 100644 (file)
@@ -21,6 +21,7 @@
 #include "storage/bufmgr.h"
 #include "storage/condition_variable.h"
 #include "storage/lwlock.h"
+#include "storage/procnumber.h"
 #include "storage/shmem.h"
 #include "storage/smgr.h"
 #include "storage/spin.h"
@@ -86,6 +87,8 @@ StaticAssertDecl(BUF_REFCOUNT_BITS + BUF_USAGECOUNT_BITS + BUF_FLAG_BITS == 32,
 
 StaticAssertDecl(BM_MAX_USAGE_COUNT < (1 << BUF_USAGECOUNT_BITS),
                 "BM_MAX_USAGE_COUNT doesn't fit in BUF_USAGECOUNT_BITS bits");
+StaticAssertDecl(MAX_BACKENDS_BITS <= BUF_REFCOUNT_BITS,
+                "MAX_BACKENDS_BITS needs to be <= BUF_REFCOUNT_BITS");
 
 /*
  * Buffer tag identifies which disk block the buffer contains.