diff options
author | Andres Freund <andres@anarazel.de> | 2025-02-24 05:39:17 -0500 |
---|---|---|
committer | Andres Freund <andres@anarazel.de> | 2025-02-24 06:23:41 -0500 |
commit | 6394a3a61c0deae34ad9e94505d319cebe9e09a1 (patch) | |
tree | da5a4d71d31eff6d36e3455a05ce2ab7a0c4b9c1 /src/include/storage/procnumber.h | |
parent | 0600d276d485a8222eb6b571b08889c9f539e86f (diff) | |
download | postgresql-6394a3a61c0deae34ad9e94505d319cebe9e09a1.tar.gz postgresql-6394a3a61c0deae34ad9e94505d319cebe9e09a1.zip |
Move MAX_BACKENDS to procnumber.h
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 <thomas.munro@gmail.com>
Discussion: https://postgr.es/m/wptizm4qt6yikgm2pt52xzyv6ycmqiutloyvypvmagn7xvqkce@d4xuv3mylpg4
Diffstat (limited to 'src/include/storage/procnumber.h')
-rw-r--r-- | src/include/storage/procnumber.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/include/storage/procnumber.h b/src/include/storage/procnumber.h index 7cf981ab673..75c2c7a17c0 100644 --- a/src/include/storage/procnumber.h +++ b/src/include/storage/procnumber.h @@ -26,6 +26,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)) */ extern PGDLLIMPORT ProcNumber MyProcNumber; |