1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-19 13:42:17 +03:00

Revert the addition of GetMaxBackends() and related stuff.

This reverts commits 0147fc7, 4567596, aa64f23, and 5ecd018.
There is no longer agreement that introducing this function
was the right way to address the problem. The consensus now
seems to favor trying to make a correct value for MaxBackends
available to mdules executing their _PG_init() functions.

Nathan Bossart

Discussion: http://postgr.es/m/20220323045229.i23skfscdbvrsuxa@jrouhaud
This commit is contained in:
Robert Haas
2022-04-12 14:45:23 -04:00
parent 2c9381840f
commit 7fc0e7de9f
19 changed files with 142 additions and 227 deletions

View File

@@ -166,7 +166,7 @@ dsm_postmaster_startup(PGShmemHeader *shim)
/* Determine size for new control segment. */
maxitems = PG_DYNSHMEM_FIXED_SLOTS
+ PG_DYNSHMEM_SLOTS_PER_BACKEND * GetMaxBackends();
+ PG_DYNSHMEM_SLOTS_PER_BACKEND * MaxBackends;
elog(DEBUG2, "dynamic shared memory system will support %u segments",
maxitems);
segsize = dsm_control_bytes_needed(maxitems);

View File

@@ -97,7 +97,7 @@ typedef struct ProcArrayStruct
/* oldest catalog xmin of any replication slot */
TransactionId replication_slot_catalog_xmin;
/* indexes into allProcs[], has ProcArrayMaxProcs entries */
/* indexes into allProcs[], has PROCARRAY_MAXPROCS entries */
int pgprocnos[FLEXIBLE_ARRAY_MEMBER];
} ProcArrayStruct;
@@ -355,17 +355,6 @@ static void MaintainLatestCompletedXidRecovery(TransactionId latestXid);
static inline FullTransactionId FullXidRelativeTo(FullTransactionId rel,
TransactionId xid);
static void GlobalVisUpdateApply(ComputeXidHorizonsResult *horizons);
static inline int GetProcArrayMaxProcs(void);
/*
* Retrieve the number of slots in the ProcArray structure.
*/
static inline int
GetProcArrayMaxProcs(void)
{
return GetMaxBackends() + max_prepared_xacts;
}
/*
* Report shared-memory space needed by CreateSharedProcArray.
@@ -376,8 +365,10 @@ ProcArrayShmemSize(void)
Size size;
/* Size of the ProcArray structure itself */
#define PROCARRAY_MAXPROCS (MaxBackends + max_prepared_xacts)
size = offsetof(ProcArrayStruct, pgprocnos);
size = add_size(size, mul_size(sizeof(int), GetProcArrayMaxProcs()));
size = add_size(size, mul_size(sizeof(int), PROCARRAY_MAXPROCS));
/*
* During Hot Standby processing we have a data structure called
@@ -393,7 +384,7 @@ ProcArrayShmemSize(void)
* shared memory is being set up.
*/
#define TOTAL_MAX_CACHED_SUBXIDS \
((PGPROC_MAX_CACHED_SUBXIDS + 1) * GetProcArrayMaxProcs())
((PGPROC_MAX_CACHED_SUBXIDS + 1) * PROCARRAY_MAXPROCS)
if (EnableHotStandby)
{
@@ -420,7 +411,7 @@ CreateSharedProcArray(void)
ShmemInitStruct("Proc Array",
add_size(offsetof(ProcArrayStruct, pgprocnos),
mul_size(sizeof(int),
GetProcArrayMaxProcs())),
PROCARRAY_MAXPROCS)),
&found);
if (!found)
@@ -429,7 +420,7 @@ CreateSharedProcArray(void)
* We're the first - initialize.
*/
procArray->numProcs = 0;
procArray->maxProcs = GetProcArrayMaxProcs();
procArray->maxProcs = PROCARRAY_MAXPROCS;
procArray->maxKnownAssignedXids = TOTAL_MAX_CACHED_SUBXIDS;
procArray->numKnownAssignedXids = 0;
procArray->tailKnownAssignedXids = 0;
@@ -4645,7 +4636,7 @@ KnownAssignedXidsCompress(bool force)
*/
int nelements = head - tail;
if (nelements < 4 * GetProcArrayMaxProcs() ||
if (nelements < 4 * PROCARRAY_MAXPROCS ||
nelements < 2 * pArray->numKnownAssignedXids)
return;
}

View File

@@ -81,6 +81,13 @@ typedef struct
ProcSignalSlot psh_slot[FLEXIBLE_ARRAY_MEMBER];
} ProcSignalHeader;
/*
* We reserve a slot for each possible BackendId, plus one for each
* possible auxiliary process type. (This scheme assumes there is not
* more than one of any auxiliary process type at a time.)
*/
#define NumProcSignalSlots (MaxBackends + NUM_AUXPROCTYPES)
/* Check whether the relevant type bit is set in the flags. */
#define BARRIER_SHOULD_CHECK(flags, type) \
(((flags) & (((uint32) 1) << (uint32) (type))) != 0)
@@ -95,20 +102,6 @@ static ProcSignalSlot *MyProcSignalSlot = NULL;
static bool CheckProcSignal(ProcSignalReason reason);
static void CleanupProcSignalState(int status, Datum arg);
static void ResetProcSignalBarrierBits(uint32 flags);
static inline int GetNumProcSignalSlots(void);
/*
* GetNumProcSignalSlots
*
* We reserve a slot for each possible BackendId, plus one for each possible
* auxiliary process type. (This scheme assume there is not more than one of
* any auxiliary process type at a time.)
*/
static inline int
GetNumProcSignalSlots(void)
{
return GetMaxBackends() + NUM_AUXPROCTYPES;
}
/*
* ProcSignalShmemSize
@@ -119,7 +112,7 @@ ProcSignalShmemSize(void)
{
Size size;
size = mul_size(GetNumProcSignalSlots(), sizeof(ProcSignalSlot));
size = mul_size(NumProcSignalSlots, sizeof(ProcSignalSlot));
size = add_size(size, offsetof(ProcSignalHeader, psh_slot));
return size;
}
@@ -133,7 +126,6 @@ ProcSignalShmemInit(void)
{
Size size = ProcSignalShmemSize();
bool found;
int numProcSignalSlots = GetNumProcSignalSlots();
ProcSignal = (ProcSignalHeader *)
ShmemInitStruct("ProcSignal", size, &found);
@@ -145,7 +137,7 @@ ProcSignalShmemInit(void)
pg_atomic_init_u64(&ProcSignal->psh_barrierGeneration, 0);
for (i = 0; i < numProcSignalSlots; ++i)
for (i = 0; i < NumProcSignalSlots; ++i)
{
ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
@@ -171,7 +163,7 @@ ProcSignalInit(int pss_idx)
ProcSignalSlot *slot;
uint64 barrier_generation;
Assert(pss_idx >= 1 && pss_idx <= GetNumProcSignalSlots());
Assert(pss_idx >= 1 && pss_idx <= NumProcSignalSlots);
slot = &ProcSignal->psh_slot[pss_idx - 1];
@@ -300,7 +292,7 @@ SendProcSignal(pid_t pid, ProcSignalReason reason, BackendId backendId)
*/
int i;
for (i = GetNumProcSignalSlots() - 1; i >= 0; i--)
for (i = NumProcSignalSlots - 1; i >= 0; i--)
{
slot = &ProcSignal->psh_slot[i];
@@ -341,7 +333,6 @@ EmitProcSignalBarrier(ProcSignalBarrierType type)
{
uint32 flagbit = 1 << (uint32) type;
uint64 generation;
int numProcSignalSlots = GetNumProcSignalSlots();
/*
* Set all the flags.
@@ -351,7 +342,7 @@ EmitProcSignalBarrier(ProcSignalBarrierType type)
* anything that we do afterwards. (This is also true of the later call to
* pg_atomic_add_fetch_u64.)
*/
for (int i = 0; i < numProcSignalSlots; i++)
for (int i = 0; i < NumProcSignalSlots; i++)
{
volatile ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
@@ -377,7 +368,7 @@ EmitProcSignalBarrier(ProcSignalBarrierType type)
* backends that need to update state - but they won't actually need to
* change any state.
*/
for (int i = numProcSignalSlots - 1; i >= 0; i--)
for (int i = NumProcSignalSlots - 1; i >= 0; i--)
{
volatile ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
pid_t pid = slot->pss_pid;
@@ -402,7 +393,7 @@ WaitForProcSignalBarrier(uint64 generation)
{
Assert(generation <= pg_atomic_read_u64(&ProcSignal->psh_barrierGeneration));
for (int i = GetNumProcSignalSlots() - 1; i >= 0; i--)
for (int i = NumProcSignalSlots - 1; i >= 0; i--)
{
ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
uint64 oldval;

View File

@@ -213,7 +213,7 @@ SInvalShmemSize(void)
* free slot. This is because the autovacuum launcher and worker processes,
* which are included in MaxBackends, are not started in Hot Standby mode.
*/
size = add_size(size, mul_size(sizeof(ProcState), GetMaxBackends()));
size = add_size(size, mul_size(sizeof(ProcState), MaxBackends));
return size;
}
@@ -239,7 +239,7 @@ CreateSharedInvalidationState(void)
shmInvalBuffer->maxMsgNum = 0;
shmInvalBuffer->nextThreshold = CLEANUP_MIN;
shmInvalBuffer->lastBackend = 0;
shmInvalBuffer->maxBackends = GetMaxBackends();
shmInvalBuffer->maxBackends = MaxBackends;
SpinLockInit(&shmInvalBuffer->msgnumLock);
/* The buffer[] array is initially all unused, so we need not fill it */