1 /*-------------------------------------------------------------------------
4 * POSTGRES inter-process communication initialization code.
6 * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.45 2001/11/04 19:55:31 tgl Exp $
13 *-------------------------------------------------------------------------
17 #include <sys/types.h>
19 #include "miscadmin.h"
20 #include "access/clog.h"
21 #include "access/xlog.h"
22 #include "storage/bufmgr.h"
23 #include "storage/freespace.h"
24 #include "storage/lmgr.h"
25 #include "storage/lwlock.h"
26 #include "storage/pmsignal.h"
27 #include "storage/proc.h"
28 #include "storage/sinval.h"
29 #include "storage/spin.h"
33 * CreateSharedMemoryAndSemaphores
34 * Creates and initializes shared memory and semaphores.
36 * This is called by the postmaster or by a standalone backend.
37 * It is NEVER called by a backend forked from the postmaster;
38 * for such a backend, the shared memory is already ready-to-go.
40 * If "makePrivate" is true then we only need private memory, not shared
41 * memory. This is true for a standalone backend, false for a postmaster.
44 CreateSharedMemoryAndSemaphores(bool makePrivate, int maxBackends)
47 PGShmemHeader *seghdr;
50 * Size of the Postgres shared-memory block is estimated via
51 * moderately-accurate estimates for the big hogs, plus 100K for the
52 * stuff that's too small to bother with estimating.
54 size = BufferShmemSize();
55 size += LockShmemSize(maxBackends);
56 size += XLOGShmemSize();
57 size += CLOGShmemSize();
58 size += LWLockShmemSize();
59 size += SInvalShmemSize(maxBackends);
60 size += FreeSpaceShmemSize();
61 #ifdef STABLE_MEMORY_STORAGE
62 size += MMShmemSize();
65 /* might as well round it off to a multiple of a typical page size */
66 size += 8192 - (size % 8192);
69 fprintf(stderr, "invoking IpcMemoryCreate(size=%d)\n", size);
72 * Create the shmem segment
74 seghdr = IpcMemoryCreate(size, makePrivate, IPCProtection);
77 * First initialize spinlocks --- needed by InitShmemAllocation()
82 * Set up shared memory allocation mechanism
84 InitShmemAllocation(seghdr);
87 * Now initialize LWLocks, which do shared memory allocation and are
88 * needed for InitShmemIndex.
93 * Set up shmem.c index hashtable
98 * Set up xlog, clog, and buffers
105 * Set up lock manager
108 if (InitLockTable(maxBackends) == INVALID_TABLEID)
109 elog(FATAL, "Couldn't create the lock table");
112 * Set up process table
114 InitProcGlobal(maxBackends);
117 * Set up shared-inval messaging
119 CreateSharedInvalidationState(maxBackends);
122 * Set up free-space map
127 * Set up child-to-postmaster signaling mechanism