diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 1999-02-22 06:16:57 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 1999-02-22 06:16:57 +0000 |
commit | bcfdc9df046c159e973149f2a82acc99d07d7b83 (patch) | |
tree | 9b31789e9b1e9239073a3965d00a332828e1e222 /src/backend/storage/ipc | |
parent | ceb233ed1105a0ac6022fc6a4558c2cfaf0d240b (diff) |
Repair some pretty serious problems in dynahash.c and
shared memory space allocation. It's a wonder we have not seen bug
reports traceable to this area ... it's quite clear that the routine
dir_realloc() has never worked correctly, for example.
Diffstat (limited to 'src/backend/storage/ipc')
-rw-r--r-- | src/backend/storage/ipc/ipci.c | 12 | ||||
-rw-r--r-- | src/backend/storage/ipc/shmem.c | 32 |
2 files changed, 26 insertions, 18 deletions
diff --git a/src/backend/storage/ipc/ipci.c b/src/backend/storage/ipc/ipci.c index 49259807b40..2f5d1d3a193 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.21 1999/02/21 01:41:44 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.22 1999/02/22 06:16:49 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -72,11 +72,19 @@ CreateSharedMemoryAndSemaphores(IPCKey key, int maxBackends) * ---------------- */ CreateSpinlocks(IPCKeyGetSpinLockSemaphoreKey(key)); - size = BufferShmemSize() + LockShmemSize(maxBackends); + /* + * 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. + * Then we add 10% for a safety margin. + */ + size = BufferShmemSize() + LockShmemSize(maxBackends); #ifdef STABLE_MEMORY_STORAGE size += MMShmemSize(); #endif + size += 100000; + size += size / 10; if (DebugLvl > 1) { diff --git a/src/backend/storage/ipc/shmem.c b/src/backend/storage/ipc/shmem.c index afc32068980..3653e844ab6 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.36 1999/02/13 23:18:13 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.37 1999/02/22 06:16:48 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -65,7 +65,6 @@ #include "storage/shmem.h" #include "storage/spin.h" #include "storage/proc.h" -#include "utils/dynahash.h" #include "utils/hsearch.h" #include "utils/memutils.h" #include "access/xact.h" @@ -215,7 +214,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 +339,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,17 +348,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 @@ -375,13 +377,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); } /* |