Minor adjustments to improve the accuracy of our computation of required

shared memory size.
This commit is contained in:
Tom Lane 2004-09-29 15:15:56 +00:00
parent 1bb38bb4e5
commit 0fb3152ea9
5 changed files with 44 additions and 22 deletions

View File

@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.35 2004/09/28 20:46:27 tgl Exp $
* $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.36 2004/09/29 15:15:54 tgl Exp $
*
*
* NOTES:
@ -330,7 +330,7 @@ FreeSpaceShmemSize(void)
size = MAXALIGN(sizeof(FSMHeader));
/* hash table, including the FSMRelation objects */
size += hash_estimate_size(MaxFSMRelations, sizeof(FSMRelation));
size += hash_estimate_size(MaxFSMRelations + 1, sizeof(FSMRelation));
/* page-storage arena */
nchunks = (MaxFSMPages - 1) / CHUNKPAGES + 1;

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/ipc/ipci.c,v 1.71 2004/08/29 05:06:48 momjian Exp $
* $PostgreSQL: pgsql/src/backend/storage/ipc/ipci.c,v 1.72 2004/09/29 15:15:55 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -69,6 +69,7 @@ CreateSharedMemoryAndSemaphores(bool makePrivate,
size = hash_estimate_size(SHMEM_INDEX_SIZE, sizeof(ShmemIndexEnt));
size += BufferShmemSize();
size += LockShmemSize(maxBackends);
size += ProcGlobalShmemSize(maxBackends);
size += XLOGShmemSize();
size += CLOGShmemSize();
size += SUBTRANSShmemSize();

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.141 2004/09/28 20:46:32 tgl Exp $
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.142 2004/09/29 15:15:55 tgl Exp $
*
* NOTES
* Outside modules can create a lock table and acquire/release
@ -1689,15 +1689,17 @@ LockReassignCurrentOwner(void)
}
/*
* Estimate shared-memory space used for lock tables
*/
int
LockShmemSize(int maxBackends)
{
int size = 0;
long max_table_size = NLOCKENTS(maxBackends);
size += MAXALIGN(sizeof(PROC_HDR)); /* ProcGlobal */
size += maxBackends * MAXALIGN(sizeof(PGPROC)); /* each MyProc */
size += MAX_LOCK_METHODS * MAXALIGN(sizeof(LockMethodData)); /* each lock method */
/* lock method headers */
size += MAX_LOCK_METHODS * MAXALIGN(sizeof(LockMethodData));
/* lockHash table */
size += hash_estimate_size(max_table_size, sizeof(LOCK));
@ -1706,6 +1708,9 @@ LockShmemSize(int maxBackends)
size += hash_estimate_size(max_table_size, sizeof(PROCLOCK));
/*
* Note we count only one pair of hash tables, since the userlocks
* table actually overlays the main one.
*
* Since the lockHash entry count above is only an estimate, add 10%
* safety margin.
*/

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.153 2004/08/29 05:06:48 momjian Exp $
* $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.154 2004/09/29 15:15:55 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -89,6 +89,22 @@ static void DummyProcKill(int code, Datum arg);
static bool CheckStatementTimeout(void);
/*
* Report shared-memory space needed by InitProcGlobal.
*/
int
ProcGlobalShmemSize(int maxBackends)
{
int size = 0;
size += MAXALIGN(sizeof(PROC_HDR)); /* ProcGlobal */
size += MAXALIGN(NUM_DUMMY_PROCS * sizeof(PGPROC)); /* DummyProcs */
size += MAXALIGN(maxBackends * sizeof(PGPROC)); /* MyProcs */
size += MAXALIGN(sizeof(slock_t)); /* ProcStructLock */
return size;
}
/*
* Report number of semaphores needed by InitProcGlobal.
*/
@ -134,7 +150,7 @@ InitProcGlobal(int maxBackends)
* processes, too. These do not get linked into the freeProcs list.
*/
DummyProcs = (PGPROC *)
ShmemInitStruct("DummyProcs", sizeof(PGPROC) * NUM_DUMMY_PROCS,
ShmemInitStruct("DummyProcs", NUM_DUMMY_PROCS * sizeof(PGPROC),
&foundDummy);
if (foundProcGlobal || foundDummy)
@ -147,6 +163,7 @@ InitProcGlobal(int maxBackends)
/*
* We're the first - initialize.
*/
PGPROC *procs;
int i;
ProcGlobal->freeProcs = INVALID_OFFSET;
@ -155,22 +172,20 @@ InitProcGlobal(int maxBackends)
* Pre-create the PGPROC structures and create a semaphore for
* each.
*/
procs = (PGPROC *) ShmemAlloc(maxBackends * sizeof(PGPROC));
if (!procs)
ereport(FATAL,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of shared memory")));
MemSet(procs, 0, maxBackends * sizeof(PGPROC));
for (i = 0; i < maxBackends; i++)
{
PGPROC *proc;
proc = (PGPROC *) ShmemAlloc(sizeof(PGPROC));
if (!proc)
ereport(FATAL,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of shared memory")));
MemSet(proc, 0, sizeof(PGPROC));
PGSemaphoreCreate(&proc->sem);
proc->links.next = ProcGlobal->freeProcs;
ProcGlobal->freeProcs = MAKE_OFFSET(proc);
PGSemaphoreCreate(&(procs[i].sem));
procs[i].links.next = ProcGlobal->freeProcs;
ProcGlobal->freeProcs = MAKE_OFFSET(&procs[i]);
}
MemSet(DummyProcs, 0, sizeof(PGPROC) * NUM_DUMMY_PROCS);
MemSet(DummyProcs, 0, NUM_DUMMY_PROCS * sizeof(PGPROC));
for (i = 0; i < NUM_DUMMY_PROCS; i++)
{
DummyProcs[i].pid = 0; /* marks dummy proc as not in use */

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/storage/proc.h,v 1.75 2004/08/29 05:06:58 momjian Exp $
* $PostgreSQL: pgsql/src/include/storage/proc.h,v 1.76 2004/09/29 15:15:56 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -122,6 +122,7 @@ extern int StatementTimeout;
* Function Prototypes
*/
extern int ProcGlobalSemas(int maxBackends);
extern int ProcGlobalShmemSize(int maxBackends);
extern void InitProcGlobal(int maxBackends);
extern void InitProcess(void);
extern void InitDummyProcess(int proctype);