diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2000-11-28 23:27:57 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2000-11-28 23:27:57 +0000 |
commit | c715fdea267843fd7fae4253aee0ae91e941393c (patch) | |
tree | b19e41edd57afe461ebc3dae271c8a5d17eba710 /src/backend/storage/ipc/ipci.c | |
parent | 914822713c9a8ce452860fb895ef79ecfd583746 (diff) | |
download | postgresql-c715fdea267843fd7fae4253aee0ae91e941393c.tar.gz postgresql-c715fdea267843fd7fae4253aee0ae91e941393c.zip |
Significant cleanups in SysV IPC handling (shared mem and semaphores).
IPC key assignment will now work correctly even when multiple postmasters
are using same logical port number (which is possible given -k switch).
There is only one shared-mem segment per postmaster now, not 3.
Rip out broken code for non-TAS case in bufmgr and xlog, substitute a
complete S_LOCK emulation using semaphores in spin.c. TAS and non-TAS
logic is now exactly the same.
When deadlock is detected, "Deadlock detected" is now the elog(ERROR)
message, rather than a NOTICE that comes out before an unhelpful ERROR.
Diffstat (limited to 'src/backend/storage/ipc/ipci.c')
-rw-r--r-- | src/backend/storage/ipc/ipci.c | 147 |
1 files changed, 45 insertions, 102 deletions
diff --git a/src/backend/storage/ipc/ipci.c b/src/backend/storage/ipc/ipci.c index 5c7e88af73e..7a5813df57d 100644 --- a/src/backend/storage/ipc/ipci.c +++ b/src/backend/storage/ipc/ipci.c @@ -8,148 +8,91 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.34 2000/11/21 21:16:01 petere Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.35 2000/11/28 23:27:56 tgl Exp $ * *------------------------------------------------------------------------- */ -#include <sys/types.h> - #include "postgres.h" +#include <sys/types.h> + #include "miscadmin.h" #include "access/xlog.h" #include "storage/bufmgr.h" +#include "storage/proc.h" #include "storage/sinval.h" +#include "storage/spin.h" -/* - * SystemPortAddressCreateMemoryKey - * Returns a memory key given a port address. - */ -IPCKey -SystemPortAddressCreateIPCKey(SystemPortAddress address) -{ - Assert(address < 32768); /* XXX */ - - return SystemPortAddressGetIPCKey(address); -} /* * CreateSharedMemoryAndSemaphores * Creates and initializes shared memory and semaphores. + * + * This is called by the postmaster or by a standalone backend. + * It is NEVER called by a backend forked from the postmaster; + * for such a backend, the shared memory is already ready-to-go. + * + * If "private" is true then we only need private memory, not shared + * memory. This is true for a standalone backend, false for a postmaster. */ -/************************************************** - - CreateSharedMemoryAndSemaphores - is called exactly *ONCE* by the postmaster. - It is *NEVER* called by the postgres backend, - except in the case of a standalone backend. - - 0) destroy any existing semaphores for both buffer - and lock managers. - 1) create the appropriate *SHARED* memory segments - for the two resource managers. - 2) create shared semaphores as needed. - - **************************************************/ - void -CreateSharedMemoryAndSemaphores(IPCKey key, int maxBackends) +CreateSharedMemoryAndSemaphores(bool private, int maxBackends) { int size; - -#ifdef HAS_TEST_AND_SET - - /* - * Create shared memory for slocks - */ - CreateAndInitSLockMemory(IPCKeyGetSLockSharedMemoryKey(key)); -#endif - - /* - * Kill and create the buffer manager buffer pool (and semaphore) - */ - CreateSpinlocks(IPCKeyGetSpinLockSemaphoreKey(key)); + PGShmemHeader *seghdr; /* - * Size of the primary shared-memory block is estimated via + * Size of the Postgres 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(maxBackends) + XLOGShmemSize(); + size = BufferShmemSize() + LockShmemSize(maxBackends) + + XLOGShmemSize() + SLockShmemSize() + SInvalShmemSize(maxBackends); #ifdef STABLE_MEMORY_STORAGE size += MMShmemSize(); #endif size += 100000; - /* might as well round it off to a multiple of a K or so... */ - size += 1024 - (size % 1024); + /* might as well round it off to a multiple of a typical page size */ + size += 8192 - (size % 8192); if (DebugLvl > 1) - { - fprintf(stderr, "binding ShmemCreate(key=%x, size=%d)\n", - IPCKeyGetBufferMemoryKey(key), size); - } - ShmemCreate(IPCKeyGetBufferMemoryKey(key), size); - ShmemIndexReset(); - InitShmem(key, size); - XLOGShmemInit(); - InitBufferPool(key); + fprintf(stderr, "invoking IpcMemoryCreate(size=%d)\n", size); - /* ---------------- - * do the lock table stuff - * ---------------- + /* + * Create the shmem segment */ - InitLocks(); - if (InitLockTable() == INVALID_TABLEID) - elog(FATAL, "Couldn't create the lock table"); + seghdr = IpcMemoryCreate(size, private, IPCProtection); - /* ---------------- - * do process table stuff - * ---------------- + /* + * First initialize spinlocks --- needed by InitShmemAllocation() */ - InitProcGlobal(key, maxBackends); - - CreateSharedInvalidationState(key, maxBackends); -} - + CreateSpinlocks(seghdr); -/* - * AttachSharedMemoryAndSemaphores - * Attachs existant shared memory and semaphores. - */ -void -AttachSharedMemoryAndSemaphores(IPCKey key) -{ - /* ---------------- - * create rather than attach if using private key - * ---------------- + /* + * Set up shmem.c hashtable */ - if (key == PrivateIPCKey) - { - CreateSharedMemoryAndSemaphores(key, 16); - return; - } + InitShmemAllocation(seghdr); -#ifdef HAS_TEST_AND_SET - /* ---------------- - * attach the slock shared memory - * ---------------- - */ - AttachSLockMemory(IPCKeyGetSLockSharedMemoryKey(key)); -#endif - /* ---------------- - * attach the buffer manager buffer pool (and semaphore) - * ---------------- + /* + * Set up xlog and buffers */ - InitShmem(key, 0); - InitBufferPool(key); + XLOGShmemInit(); + InitBufferPool(); - /* ---------------- - * initialize lock table stuff - * ---------------- + /* + * Set up lock manager */ InitLocks(); if (InitLockTable() == INVALID_TABLEID) - elog(FATAL, "Couldn't attach to the lock table"); + elog(FATAL, "Couldn't create the lock table"); + + /* + * Set up process table + */ + InitProcGlobal(maxBackends); - AttachSharedInvalidationState(key); + /* + * Set up shared-inval messaging + */ + CreateSharedInvalidationState(maxBackends); } |