1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-16 06:01:02 +03:00

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
This commit is contained in:
Andres Freund
2025-02-24 05:39:27 -05:00
parent 418451bfe1
commit 5ee75e32fa
3 changed files with 11 additions and 0 deletions

View File

@ -30,6 +30,7 @@
#include "pgstat.h" #include "pgstat.h"
#include "storage/lmgr.h" #include "storage/lmgr.h"
#include "storage/proc.h" #include "storage/proc.h"
#include "storage/procnumber.h"
#include "utils/memutils.h" #include "utils/memutils.h"
@ -191,6 +192,8 @@ InitDeadLockChecking(void)
* last MaxBackends entries in possibleConstraints[] are reserved as * last MaxBackends entries in possibleConstraints[] are reserved as
* output workspace for FindLockCycle. * output workspace for FindLockCycle.
*/ */
StaticAssertStmt(MAX_BACKENDS_BITS <= (32 - 3),
"MAX_BACKENDS_BITS too big for * 4");
maxPossibleConstraints = MaxBackends * 4; maxPossibleConstraints = MaxBackends * 4;
possibleConstraints = possibleConstraints =
(EDGE *) palloc(maxPossibleConstraints * sizeof(EDGE)); (EDGE *) palloc(maxPossibleConstraints * sizeof(EDGE));

View File

@ -120,6 +120,7 @@
#include "catalog/catalog.h" #include "catalog/catalog.h"
#include "catalog/pg_constraint.h" #include "catalog/pg_constraint.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "storage/procnumber.h"
#include "storage/sinval.h" #include "storage/sinval.h"
#include "storage/smgr.h" #include "storage/smgr.h"
#include "utils/catcache.h" #include "utils/catcache.h"
@ -1651,6 +1652,10 @@ CacheInvalidateSmgr(RelFileLocatorBackend rlocator)
{ {
SharedInvalidationMessage msg; 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.id = SHAREDINVALSMGR_ID;
msg.sm.backend_hi = rlocator.backend >> 16; msg.sm.backend_hi = rlocator.backend >> 16;
msg.sm.backend_lo = rlocator.backend & 0xffff; msg.sm.backend_lo = rlocator.backend & 0xffff;

View File

@ -21,6 +21,7 @@
#include "storage/bufmgr.h" #include "storage/bufmgr.h"
#include "storage/condition_variable.h" #include "storage/condition_variable.h"
#include "storage/lwlock.h" #include "storage/lwlock.h"
#include "storage/procnumber.h"
#include "storage/shmem.h" #include "storage/shmem.h"
#include "storage/smgr.h" #include "storage/smgr.h"
#include "storage/spin.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), StaticAssertDecl(BM_MAX_USAGE_COUNT < (1 << BUF_USAGECOUNT_BITS),
"BM_MAX_USAGE_COUNT doesn't fit in BUF_USAGECOUNT_BITS 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. * Buffer tag identifies which disk block the buffer contains.