aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/postmaster/postmaster.c19
-rw-r--r--src/backend/storage/ipc/ipc.c11
-rw-r--r--src/backend/storage/ipc/ipci.c11
-rw-r--r--src/backend/storage/lmgr/lock.c21
-rw-r--r--src/backend/storage/lmgr/proc.c41
5 files changed, 54 insertions, 49 deletions
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 41099d9c05d..281b95fe906 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.102 1999/02/19 06:06:00 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.103 1999/02/21 01:41:43 tgl Exp $
*
* NOTES
*
@@ -162,14 +162,15 @@ static IpcMemoryKey ipc_key;
* adding to this.
*/
-static int MaxBackends = MAXBACKENDS;
+static int MaxBackends = DEF_MAXBACKENDS;
/*
- * MaxBackends is the actual soft limit on the number of backends
- * we will start. It defaults to the hard limit established at compilation
- * time, but can be readjusted with postmaster's xxx switch.
- * One reason to reduce MaxBackends is to allow startup under a kernel
- * that won't let us get MAXBACKENDS semaphores!
+ * MaxBackends is the actual limit on the number of backends we will start.
+ * The default is established by configure, but it can be readjusted
+ * from 1..MAXBACKENDS with the postmaster -N switch.
+ * Note that a larger MaxBackends value will increase the size of the
+ * shared memory area as well as cause the postmaster to grab more
+ * kernel semaphores, even if you never actually use that many backends.
*/
static int NextBackendTag = MAXINT; /* XXX why count down not up? */
@@ -641,8 +642,8 @@ usage(const char *progname)
fprintf(stderr, "\t-b backend\tuse a specific backend server executable\n");
fprintf(stderr, "\t-d [1|2|3]\tset debugging level\n");
fprintf(stderr, "\t-i \t\tlisten on TCP/IP sockets as well as Unix domain socket\n");
- fprintf(stderr, "\t-N nprocs\tset max number of backend servers (1..%d)\n",
- MAXBACKENDS);
+ fprintf(stderr, "\t-N nprocs\tset max number of backends (1..%d, default %d)\n",
+ MAXBACKENDS, DEF_MAXBACKENDS);
fprintf(stderr, "\t-n \t\tdon't reinitialize shared memory after abnormal exit\n");
fprintf(stderr, "\t-o option\tpass 'option' to each backend servers\n");
fprintf(stderr, "\t-p port\tspecify port for postmaster to listen on\n");
diff --git a/src/backend/storage/ipc/ipc.c b/src/backend/storage/ipc/ipc.c
index 511893657f5..62a38e14aae 100644
--- a/src/backend/storage/ipc/ipc.c
+++ b/src/backend/storage/ipc/ipc.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipc.c,v 1.35 1999/02/13 23:18:09 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipc.c,v 1.36 1999/02/21 01:41:44 tgl Exp $
*
* NOTES
*
@@ -677,9 +677,10 @@ struct ipcdummy
SLock *free;
int unused;
slock_t memlock;
- SLock slocks[NSLOCKS];
+ SLock slocks[MAX_SPINS + 1];
};
-static int SLockMemorySize = sizeof(struct ipcdummy);
+
+#define SLOCKMEMORYSIZE sizeof(struct ipcdummy)
void
CreateAndInitSLockMemory(IPCKey key)
@@ -688,7 +689,7 @@ CreateAndInitSLockMemory(IPCKey key)
SLock *slckP;
SLockMemoryId = IpcMemoryCreate(key,
- SLockMemorySize,
+ SLOCKMEMORYSIZE,
0700);
AttachSLockMemory(key);
*FreeSLockPP = NULL;
@@ -713,7 +714,7 @@ AttachSLockMemory(IPCKey key)
struct ipcdummy *slockM;
if (SLockMemoryId == -1)
- SLockMemoryId = IpcMemoryIdGet(key, SLockMemorySize);
+ SLockMemoryId = IpcMemoryIdGet(key, SLOCKMEMORYSIZE);
if (SLockMemoryId == -1)
elog(FATAL, "SLockMemory not in shared memory");
slockM = (struct ipcdummy *) IpcMemoryAttach(SLockMemoryId);
diff --git a/src/backend/storage/ipc/ipci.c b/src/backend/storage/ipc/ipci.c
index 460f0ee10bb..49259807b40 100644
--- a/src/backend/storage/ipc/ipci.c
+++ b/src/backend/storage/ipc/ipci.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.20 1999/02/19 07:10:47 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.21 1999/02/21 01:41:44 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -72,7 +72,7 @@ CreateSharedMemoryAndSemaphores(IPCKey key, int maxBackends)
* ----------------
*/
CreateSpinlocks(IPCKeyGetSpinLockSemaphoreKey(key));
- size = BufferShmemSize() + LockShmemSize();
+ size = BufferShmemSize() + LockShmemSize(maxBackends);
#ifdef STABLE_MEMORY_STORAGE
size += MMShmemSize();
@@ -113,15 +113,13 @@ CreateSharedMemoryAndSemaphores(IPCKey key, int maxBackends)
void
AttachSharedMemoryAndSemaphores(IPCKey key)
{
- int size;
-
/* ----------------
* create rather than attach if using private key
* ----------------
*/
if (key == PrivateIPCKey)
{
- CreateSharedMemoryAndSemaphores(key, 1);
+ CreateSharedMemoryAndSemaphores(key, 16);
return;
}
@@ -136,8 +134,7 @@ AttachSharedMemoryAndSemaphores(IPCKey key)
* attach the buffer manager buffer pool (and semaphore)
* ----------------
*/
- size = BufferShmemSize() + LockShmemSize();
- InitShmem(key, size);
+ InitShmem(key, 0);
InitBufferPool(key);
/* ----------------
diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c
index 06f6fe7b4d6..29424e060fe 100644
--- a/src/backend/storage/lmgr/lock.c
+++ b/src/backend/storage/lmgr/lock.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.42 1999/02/19 06:06:06 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.43 1999/02/21 01:41:46 tgl Exp $
*
* NOTES
* Outside modules can create a lock table and acquire/release
@@ -1478,36 +1478,37 @@ next_item:
}
int
-LockShmemSize()
+LockShmemSize(int maxBackends)
{
int size = 0;
+ int nLockEnts = NLOCKENTS(maxBackends);
int nLockBuckets,
nLockSegs;
int nXidBuckets,
nXidSegs;
- nLockBuckets = 1 << (int) my_log2((NLOCKENTS - 1) / DEF_FFACTOR + 1);
+ nLockBuckets = 1 << (int) my_log2((nLockEnts - 1) / DEF_FFACTOR + 1);
nLockSegs = 1 << (int) my_log2((nLockBuckets - 1) / DEF_SEGSIZE + 1);
nXidBuckets = 1 << (int) my_log2((NLOCKS_PER_XACT - 1) / DEF_FFACTOR + 1);
nXidSegs = 1 << (int) my_log2((nLockBuckets - 1) / DEF_SEGSIZE + 1);
- size += MAXALIGN(MAXBACKENDS * sizeof(PROC)); /* each MyProc */
- size += MAXALIGN(MAXBACKENDS * sizeof(LOCKMETHODCTL)); /* each
+ size += MAXALIGN(maxBackends * sizeof(PROC)); /* each MyProc */
+ size += MAXALIGN(maxBackends * sizeof(LOCKMETHODCTL)); /* each
* lockMethodTable->ctl */
size += MAXALIGN(sizeof(PROC_HDR)); /* ProcGlobal */
- size += MAXALIGN(my_log2(NLOCKENTS) * sizeof(void *));
+ size += MAXALIGN(my_log2(nLockEnts) * sizeof(void *));
size += MAXALIGN(sizeof(HHDR));
size += nLockSegs * MAXALIGN(DEF_SEGSIZE * sizeof(SEGMENT));
- size += NLOCKENTS * /* XXX not multiple of BUCKET_ALLOC_INCR? */
+ size += nLockEnts * /* XXX not multiple of BUCKET_ALLOC_INCR? */
(MAXALIGN(sizeof(BUCKET_INDEX)) +
MAXALIGN(sizeof(LOCK))); /* contains hash key */
- size += MAXALIGN(my_log2(MAXBACKENDS) * sizeof(void *));
+ size += MAXALIGN(my_log2(maxBackends) * sizeof(void *));
size += MAXALIGN(sizeof(HHDR));
size += nXidSegs * MAXALIGN(DEF_SEGSIZE * sizeof(SEGMENT));
- size += MAXBACKENDS * /* XXX not multiple of BUCKET_ALLOC_INCR? */
+ size += maxBackends * /* XXX not multiple of BUCKET_ALLOC_INCR? */
(MAXALIGN(sizeof(BUCKET_INDEX)) +
MAXALIGN(sizeof(XIDLookupEnt))); /* contains hash key */
@@ -1673,8 +1674,8 @@ DeadLockCheck(SHM_QUEUE *lockQueue, LOCK *findlock, bool skip_check)
break;
if (j >= nprocs && lock != findlock)
{
+ Assert(nprocs < MAXBACKENDS);
checked_procs[nprocs++] = proc;
- Assert(nprocs <= MAXBACKENDS);
/*
* For non-MyProc entries, we are looking only
diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c
index 7452270fdf4..2bb66c09d6a 100644
--- a/src/backend/storage/lmgr/proc.c
+++ b/src/backend/storage/lmgr/proc.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.50 1999/02/19 07:10:48 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.51 1999/02/21 01:41:45 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -46,7 +46,7 @@
* This is so that we can support more backends. (system-wide semaphore
* sets run out pretty fast.) -ay 4/95
*
- * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.50 1999/02/19 07:10:48 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.51 1999/02/21 01:41:45 tgl Exp $
*/
#include <sys/time.h>
#include <unistd.h>
@@ -154,23 +154,28 @@ InitProcGlobal(IPCKey key, int maxBackends)
*/
on_shmem_exit(ProcFreeAllSemaphores, NULL);
- /* Pre-create the semaphores for the first maxBackends processes */
- for (i = 0;
- i < (maxBackends+PROC_NSEMS_PER_SET-1) / PROC_NSEMS_PER_SET;
- i++)
+ /* Pre-create the semaphores for the first maxBackends processes,
+ * unless we are running as a standalone backend.
+ */
+ if (key != PrivateIPCKey)
{
- IPCKey semKey = ProcGlobal->currKey + i;
- int semId;
- int semstat;
-
- semId = IpcSemaphoreCreate(semKey,
- PROC_NSEMS_PER_SET,
- IPCProtection,
- IpcSemaphoreDefaultStartValue,
- 0,
- &semstat);
- /* mark this sema set allocated */
- ProcGlobal->freeSemMap[i] = (1 << PROC_NSEMS_PER_SET);
+ for (i = 0;
+ i < (maxBackends+PROC_NSEMS_PER_SET-1) / PROC_NSEMS_PER_SET;
+ i++)
+ {
+ IPCKey semKey = ProcGlobal->currKey + i;
+ int semId;
+ int semstat;
+
+ semId = IpcSemaphoreCreate(semKey,
+ PROC_NSEMS_PER_SET,
+ IPCProtection,
+ IpcSemaphoreDefaultStartValue,
+ 0,
+ &semstat);
+ /* mark this sema set allocated */
+ ProcGlobal->freeSemMap[i] = (1 << PROC_NSEMS_PER_SET);
+ }
}
}
}