diff options
author | Andres Freund <andres@anarazel.de> | 2025-02-24 05:39:27 -0500 |
---|---|---|
committer | Andres Freund <andres@anarazel.de> | 2025-02-24 06:23:41 -0500 |
commit | 5ee75e32fa734e8ae85ff096f1523be8e16e1b8d (patch) | |
tree | 658cb18707e7dfa01c98ab14630e0d9ba9838626 | |
parent | 418451bfe161e4b86c29f098e4d93b2347d35774 (diff) | |
download | postgresql-5ee75e32fa734e8ae85ff096f1523be8e16e1b8d.tar.gz postgresql-5ee75e32fa734e8ae85ff096f1523be8e16e1b8d.zip |
Add static asserts for MAX_BACKENDS limiting factors
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
-rw-r--r-- | src/backend/storage/lmgr/deadlock.c | 3 | ||||
-rw-r--r-- | src/backend/utils/cache/inval.c | 5 | ||||
-rw-r--r-- | src/include/storage/buf_internals.h | 3 |
3 files changed, 11 insertions, 0 deletions
diff --git a/src/backend/storage/lmgr/deadlock.c b/src/backend/storage/lmgr/deadlock.c index dc6923f8132..c4bfaaa67ac 100644 --- a/src/backend/storage/lmgr/deadlock.c +++ b/src/backend/storage/lmgr/deadlock.c @@ -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)); diff --git a/src/backend/utils/cache/inval.c b/src/backend/utils/cache/inval.c index 6aff1ec01d7..700ccb6df9b 100644 --- a/src/backend/utils/cache/inval.c +++ b/src/backend/utils/cache/inval.c @@ -120,6 +120,7 @@ #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; diff --git a/src/include/storage/buf_internals.h b/src/include/storage/buf_internals.h index d830d5c9841..8b32fb108b0 100644 --- a/src/include/storage/buf_internals.h +++ b/src/include/storage/buf_internals.h @@ -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. |