summaryrefslogtreecommitdiff
path: root/src/backend/storage/ipc
diff options
context:
space:
mode:
authorTom Lane1999-03-07 02:01:09 +0000
committerTom Lane1999-03-07 02:01:09 +0000
commit2ecbf94430265822e08758df375ffea9d041a86a (patch)
treefbbdbe291eeec725547069f0b15536697eff69c3 /src/backend/storage/ipc
parent0fda84bfcd7e3ab1a8bcca7282e2b319930f7070 (diff)
Retrofit hashtable and shared-mem-size-estimation bug fixesREL6_4
into REL6_4.
Diffstat (limited to 'src/backend/storage/ipc')
-rw-r--r--src/backend/storage/ipc/ipci.c15
-rw-r--r--src/backend/storage/ipc/shmem.c32
2 files changed, 25 insertions, 22 deletions
diff --git a/src/backend/storage/ipc/ipci.c b/src/backend/storage/ipc/ipci.c
index f6ce9eda241..38a964b15e6 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.16 1998/09/01 03:25:10 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.16.2.1 1999/03/07 02:00:46 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -71,11 +71,17 @@ CreateSharedMemoryAndSemaphores(IPCKey key)
* ----------------
*/
CreateSpinlocks(IPCKeyGetSpinLockSemaphoreKey(key));
- size = BufferShmemSize() + LockShmemSize();
+ /*
+ * Size of the primary shared-memory block is estimated via
+ * moderately-accurate estimates for the big hogs, plus 100K for
+ * the stuff that's too small to bother with estimating.
+ */
+ size = BufferShmemSize() + LockShmemSize();
#ifdef STABLE_MEMORY_STORAGE
size += MMShmemSize();
#endif
+ size += 100000;
if (DebugLvl > 1)
{
@@ -113,8 +119,6 @@ CreateSharedMemoryAndSemaphores(IPCKey key)
void
AttachSharedMemoryAndSemaphores(IPCKey key)
{
- int size;
-
/* ----------------
* create rather than attach if using private key
* ----------------
@@ -136,8 +140,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/ipc/shmem.c b/src/backend/storage/ipc/shmem.c
index 18b8d718d67..67bac2f239d 100644
--- a/src/backend/storage/ipc/shmem.c
+++ b/src/backend/storage/ipc/shmem.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.31 1998/09/01 04:31:49 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.31.2.1 1999/03/07 02:00:46 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -215,7 +215,7 @@ InitShmem(unsigned int key, unsigned int size)
/* create OR attach to the shared memory shmem index */
info.keysize = SHMEM_INDEX_KEYSIZE;
info.datasize = SHMEM_INDEX_DATASIZE;
- hash_flags = (HASH_ELEM);
+ hash_flags = HASH_ELEM;
/* This will acquire the shmem index lock, but not release it. */
ShmemIndex = ShmemInitHash("ShmemIndex",
@@ -340,8 +340,8 @@ ShmemIsValid(unsigned long addr)
*/
HTAB *
ShmemInitHash(char *name, /* table string name for shmem index */
- long init_size, /* initial size */
- long max_size, /* max size of the table */
+ long init_size, /* initial table size */
+ long max_size, /* max size of the table (NOT USED) */
HASHCTL *infoP, /* info about key and bucket size */
int hash_flags) /* info about infoP */
{
@@ -349,18 +349,20 @@ ShmemInitHash(char *name, /* table string name for shmem index */
long *location;
/*
- * shared memory hash tables have a fixed max size so that the control
- * structures don't try to grow. The segbase is for calculating
- * pointer values. The shared memory allocator must be specified.
+ * Hash tables allocated in shared memory have a fixed directory;
+ * it can't grow or other backends wouldn't be able to find it.
+ * The segbase is for calculating pointer values.
+ * The shared memory allocator must be specified too.
*/
+ infoP->dsize = infoP->max_dsize = DEF_DIRSIZE;
infoP->segbase = (long *) ShmemBase;
infoP->alloc = ShmemAlloc;
- infoP->max_size = max_size;
- hash_flags |= HASH_SHARED_MEM;
+ hash_flags |= HASH_SHARED_MEM | HASH_DIRSIZE;
/* look it up in the shmem index */
- location =
- ShmemInitStruct(name, my_log2(max_size) + sizeof(HHDR), &found);
+ location = ShmemInitStruct(name,
+ sizeof(HHDR) + DEF_DIRSIZE * sizeof(SEG_OFFSET),
+ &found);
/*
* shmem index is corrupted. Let someone else give the error
@@ -376,13 +378,11 @@ ShmemInitHash(char *name, /* table string name for shmem index */
if (found)
hash_flags |= HASH_ATTACH;
- /* these structures were allocated or bound in ShmemInitStruct */
- /* control information and parameters */
+ /* Now provide the header and directory pointers */
infoP->hctl = (long *) location;
- /* directory for hash lookup */
- infoP->dir = (long *) (location + sizeof(HHDR));
+ infoP->dir = (long *) (((char*) location) + sizeof(HHDR));
- return hash_create(init_size, infoP, hash_flags);;
+ return hash_create(init_size, infoP, hash_flags);
}
/*