Skip to content

Commit 5ee75e3

Browse files
committed
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
1 parent 418451b commit 5ee75e3

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

src/backend/storage/lmgr/deadlock.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "pgstat.h"
3131
#include "storage/lmgr.h"
3232
#include "storage/proc.h"
33+
#include "storage/procnumber.h"
3334
#include "utils/memutils.h"
3435

3536

@@ -191,6 +192,8 @@ InitDeadLockChecking(void)
191192
* last MaxBackends entries in possibleConstraints[] are reserved as
192193
* output workspace for FindLockCycle.
193194
*/
195+
StaticAssertStmt(MAX_BACKENDS_BITS <= (32 - 3),
196+
"MAX_BACKENDS_BITS too big for * 4");
194197
maxPossibleConstraints = MaxBackends * 4;
195198
possibleConstraints =
196199
(EDGE *) palloc(maxPossibleConstraints * sizeof(EDGE));

src/backend/utils/cache/inval.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
#include "catalog/catalog.h"
121121
#include "catalog/pg_constraint.h"
122122
#include "miscadmin.h"
123+
#include "storage/procnumber.h"
123124
#include "storage/sinval.h"
124125
#include "storage/smgr.h"
125126
#include "utils/catcache.h"
@@ -1651,6 +1652,10 @@ CacheInvalidateSmgr(RelFileLocatorBackend rlocator)
16511652
{
16521653
SharedInvalidationMessage msg;
16531654

1655+
/* verify optimization stated above stays valid */
1656+
StaticAssertStmt(MAX_BACKENDS_BITS <= 23,
1657+
"MAX_BACKEND_BITS is too big for inval.c");
1658+
16541659
msg.sm.id = SHAREDINVALSMGR_ID;
16551660
msg.sm.backend_hi = rlocator.backend >> 16;
16561661
msg.sm.backend_lo = rlocator.backend & 0xffff;

src/include/storage/buf_internals.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "storage/bufmgr.h"
2222
#include "storage/condition_variable.h"
2323
#include "storage/lwlock.h"
24+
#include "storage/procnumber.h"
2425
#include "storage/shmem.h"
2526
#include "storage/smgr.h"
2627
#include "storage/spin.h"
@@ -86,6 +87,8 @@ StaticAssertDecl(BUF_REFCOUNT_BITS + BUF_USAGECOUNT_BITS + BUF_FLAG_BITS == 32,
8687

8788
StaticAssertDecl(BM_MAX_USAGE_COUNT < (1 << BUF_USAGECOUNT_BITS),
8889
"BM_MAX_USAGE_COUNT doesn't fit in BUF_USAGECOUNT_BITS bits");
90+
StaticAssertDecl(MAX_BACKENDS_BITS <= BUF_REFCOUNT_BITS,
91+
"MAX_BACKENDS_BITS needs to be <= BUF_REFCOUNT_BITS");
8992

9093
/*
9194
* Buffer tag identifies which disk block the buffer contains.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy