PostgreSQL Source Code git master
Loading...
Searching...
No Matches
ipci.c File Reference
#include "postgres.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "storage/dsm.h"
#include "storage/ipc.h"
#include "storage/lock.h"
#include "storage/pg_shmem.h"
#include "storage/proc.h"
#include "storage/shmem_internal.h"
#include "storage/subsystems.h"
#include "utils/guc.h"
#include "storage/subsystemlist.h"
Include dependency graph for ipci.c:

Go to the source code of this file.

Macros

#define PG_SHMEM_SUBSYSTEM(subsystem_callbacks)    RegisterShmemCallbacks(&(subsystem_callbacks));
 

Functions

void RequestAddinShmemSpace (Size size)
 
Size CalculateShmemSize (void)
 
void CreateSharedMemoryAndSemaphores (void)
 
void RegisterBuiltinShmemCallbacks (void)
 
void InitializeShmemGUCs (void)
 

Variables

int shared_memory_type = DEFAULT_SHARED_MEMORY_TYPE
 
shmem_startup_hook_type shmem_startup_hook = NULL
 
static Size total_addin_request = 0
 

Macro Definition Documentation

◆ PG_SHMEM_SUBSYSTEM

Function Documentation

◆ CalculateShmemSize()

Size CalculateShmemSize ( void  )

Definition at line 57 of file ipci.c.

58{
59 Size size;
60
61 /*
62 * Size of the Postgres shared-memory block is estimated via moderately-
63 * accurate estimates for the big hogs, plus 100K for the stuff that's too
64 * small to bother with estimating.
65 *
66 * We take some care to ensure that the total size request doesn't
67 * overflow size_t. If this gets through, we don't need to be so careful
68 * during the actual allocation phase.
69 */
70 size = 100000;
71 size = add_size(size, ShmemGetRequestedSize());
72
73 /* include additional requested shmem from preload libraries */
74 size = add_size(size, total_addin_request);
75
76 /* might as well round it off to a multiple of a typical page size */
77 size = add_size(size, 8192 - (size % 8192));
78
79 return size;
80}
size_t Size
Definition c.h:689
static Size total_addin_request
Definition ipci.c:33
Size add_size(Size s1, Size s2)
Definition shmem.c:1048
size_t ShmemGetRequestedSize(void)
Definition shmem.c:392

References add_size(), ShmemGetRequestedSize(), and total_addin_request.

Referenced by CreateSharedMemoryAndSemaphores(), and InitializeShmemGUCs().

◆ CreateSharedMemoryAndSemaphores()

void CreateSharedMemoryAndSemaphores ( void  )

Definition at line 120 of file ipci.c.

121{
124 Size size;
125
127
128 /* Compute the size of the shared-memory block */
129 size = CalculateShmemSize();
130 elog(DEBUG3, "invoking IpcMemoryCreate(size=%zu)", size);
131
132 /*
133 * Create the shmem segment
134 */
136
137 /*
138 * Make sure that huge pages are never reported as "unknown" while the
139 * server is running.
140 */
141 Assert(strcmp("unknown",
142 GetConfigOption("huge_pages_status", false, false)) != 0);
143
144 /*
145 * Set up shared memory allocation mechanism
146 */
148
149 /* Initialize all shmem areas */
151
152 /* Initialize dynamic shared memory facilities. */
154
155 /*
156 * Now give loadable modules a chance to set up their shmem allocations
157 */
160}
#define Assert(condition)
Definition c.h:943
void dsm_postmaster_startup(PGShmemHeader *shim)
Definition dsm.c:187
#define DEBUG3
Definition elog.h:29
#define elog(elevel,...)
Definition elog.h:228
bool IsUnderPostmaster
Definition globals.c:122
const char * GetConfigOption(const char *name, bool missing_ok, bool restrict_privileged)
Definition guc.c:4257
shmem_startup_hook_type shmem_startup_hook
Definition ipci.c:31
Size CalculateShmemSize(void)
Definition ipci.c:57
static int fb(int x)
void InitShmemAllocator(PGShmemHeader *seghdr)
Definition shmem.c:638
void ShmemInitRequested(void)
Definition shmem.c:425
PGShmemHeader * PGSharedMemoryCreate(Size size, PGShmemHeader **shim)
Definition sysv_shmem.c:702

References Assert, CalculateShmemSize(), DEBUG3, dsm_postmaster_startup(), elog, fb(), GetConfigOption(), InitShmemAllocator(), IsUnderPostmaster, PGSharedMemoryCreate(), shmem_startup_hook, and ShmemInitRequested().

Referenced by BootstrapModeMain(), PostgresSingleUserMain(), PostmasterMain(), and PostmasterStateMachine().

◆ InitializeShmemGUCs()

void InitializeShmemGUCs ( void  )

Definition at line 189 of file ipci.c.

190{
191 char buf[64];
192 Size size_b;
195
196 /*
197 * Calculate the shared memory size and round up to the nearest megabyte.
198 */
200 size_mb = add_size(size_b, (1024 * 1024) - 1) / (1024 * 1024);
201 sprintf(buf, "%zu", size_mb);
202 SetConfigOption("shared_memory_size", buf,
204
205 /*
206 * Calculate the number of huge pages required.
207 */
209 if (hp_size != 0)
210 {
212
214 if (size_b % hp_size != 0)
216 sprintf(buf, "%zu", hp_required);
217 SetConfigOption("shared_memory_size_in_huge_pages", buf,
219 }
220
221 sprintf(buf, "%d", ProcGlobalSemas());
223}
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition guc.c:4234
@ PGC_S_DYNAMIC_DEFAULT
Definition guc.h:114
@ PGC_INTERNAL
Definition guc.h:73
static char buf[DEFAULT_XLOG_SEG_SIZE]
#define sprintf
Definition port.h:262
int ProcGlobalSemas(void)
Definition proc.c:130
void GetHugePageSize(Size *hugepagesize, int *mmap_flags)
Definition sysv_shmem.c:480

References add_size(), buf, CalculateShmemSize(), fb(), GetHugePageSize(), PGC_INTERNAL, PGC_S_DYNAMIC_DEFAULT, ProcGlobalSemas(), SetConfigOption(), and sprintf.

Referenced by PostgresSingleUserMain(), and PostmasterMain().

◆ RegisterBuiltinShmemCallbacks()

void RegisterBuiltinShmemCallbacks ( void  )

Definition at line 168 of file ipci.c.

169{
170 /*
171 * Call RegisterShmemCallbacks(...) on each subsystem listed in
172 * subsystemslist.h
173 */
174#define PG_SHMEM_SUBSYSTEM(subsystem_callbacks) \
175 RegisterShmemCallbacks(&(subsystem_callbacks));
176
178
179#undef PG_SHMEM_SUBSYSTEM
180}

Referenced by BootstrapModeMain(), PostgresSingleUserMain(), and PostmasterMain().

◆ RequestAddinShmemSpace()

void RequestAddinShmemSpace ( Size  size)

Definition at line 45 of file ipci.c.

46{
48 elog(FATAL, "cannot request additional shared memory outside shmem_request_hook");
50}
#define FATAL
Definition elog.h:42
bool process_shmem_requests_in_progress
Definition miscinit.c:1792

References add_size(), elog, FATAL, process_shmem_requests_in_progress, and total_addin_request.

Variable Documentation

◆ shared_memory_type

int shared_memory_type = DEFAULT_SHARED_MEMORY_TYPE

Definition at line 29 of file ipci.c.

Referenced by PGSharedMemoryCreate().

◆ shmem_startup_hook

shmem_startup_hook_type shmem_startup_hook = NULL

Definition at line 31 of file ipci.c.

Referenced by CreateSharedMemoryAndSemaphores().

◆ total_addin_request

Size total_addin_request = 0
static

Definition at line 33 of file ipci.c.

Referenced by CalculateShmemSize(), and RequestAddinShmemSpace().