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.37 2000/12/03 17:18:10 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/lmgr.h"
23
#include "storage/proc.h"
B
Bruce Momjian 已提交
24
#include "storage/sinval.h"
25
#include "storage/spin.h"
26 27 28


/*
B
Bruce Momjian 已提交
29
 * CreateSharedMemoryAndSemaphores
30
 *		Creates and initializes shared memory and semaphores.
31 32 33 34 35
 *
 * 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.
 *
36
 * If "makePrivate" is true then we only need private memory, not shared
37
 * memory.  This is true for a standalone backend, false for a postmaster.
38 39
 */
void
40
CreateSharedMemoryAndSemaphores(bool makePrivate, int maxBackends)
41
{
42
	int			size;
43
	PGShmemHeader *seghdr;
44

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

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

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

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

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

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

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

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

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