ipci.c 2.4 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * ipci.c
4
 *	  POSTGRES inter-process communication initialization code.
5
 *
B
Add:  
Bruce Momjian 已提交
6 7
 * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
 * Portions Copyright (c) 1994, Regents of the University of California
8 9 10
 *
 *
 * IDENTIFICATION
11
 *	  $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.35 2000/11/28 23:27:56 tgl Exp $
12 13 14
 *
 *-------------------------------------------------------------------------
 */
M
Marc G. Fournier 已提交
15
#include "postgres.h"
16

17 18
#include <sys/types.h>

B
Bruce Momjian 已提交
19
#include "miscadmin.h"
20
#include "access/xlog.h"
B
Bruce Momjian 已提交
21
#include "storage/bufmgr.h"
22
#include "storage/proc.h"
B
Bruce Momjian 已提交
23
#include "storage/sinval.h"
24
#include "storage/spin.h"
25 26 27


/*
B
Bruce Momjian 已提交
28
 * CreateSharedMemoryAndSemaphores
29
 *		Creates and initializes shared memory and semaphores.
30 31 32 33 34 35 36
 *
 * 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.
37 38
 */
void
39
CreateSharedMemoryAndSemaphores(bool private, int maxBackends)
40
{
41
	int			size;
42
	PGShmemHeader *seghdr;
43

44
	/*
45
	 * Size of the Postgres shared-memory block is estimated via
B
Bruce Momjian 已提交
46 47
	 * moderately-accurate estimates for the big hogs, plus 100K for the
	 * stuff that's too small to bother with estimating.
48
	 */
49 50
	size = BufferShmemSize() + LockShmemSize(maxBackends) +
		XLOGShmemSize() + SLockShmemSize() + SInvalShmemSize(maxBackends);
51
#ifdef STABLE_MEMORY_STORAGE
52
	size += MMShmemSize();
53
#endif
54
	size += 100000;
55 56
	/* might as well round it off to a multiple of a typical page size */
	size += 8192 - (size % 8192);
57 58

	if (DebugLvl > 1)
59
		fprintf(stderr, "invoking IpcMemoryCreate(size=%d)\n", size);
60

61 62
	/*
	 * Create the shmem segment
63
	 */
64
	seghdr = IpcMemoryCreate(size, private, IPCProtection);
65

66 67
	/*
	 * First initialize spinlocks --- needed by InitShmemAllocation()
68
	 */
69
	CreateSpinlocks(seghdr);
70

71 72
	/*
	 * Set up shmem.c hashtable
73
	 */
74
	InitShmemAllocation(seghdr);
75

76 77
	/*
	 * Set up xlog and buffers
78
	 */
79 80
	XLOGShmemInit();
	InitBufferPool();
81

82 83
	/*
	 * Set up lock manager
84 85
	 */
	InitLocks();
V
Vadim B. Mikheev 已提交
86
	if (InitLockTable() == INVALID_TABLEID)
87 88 89 90 91 92
		elog(FATAL, "Couldn't create the lock table");

	/*
	 * Set up process table
	 */
	InitProcGlobal(maxBackends);
93

94 95 96 97
	/*
	 * Set up shared-inval messaging
	 */
	CreateSharedInvalidationState(maxBackends);
98
}