PostgreSQL Source Code git master
pg_shmem.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * pg_shmem.h
4 * Platform-independent API for shared memory support.
5 *
6 * Every port is expected to support shared memory with approximately
7 * SysV-ish semantics; in particular, a memory block is not anonymous
8 * but has an ID, and we must be able to tell whether there are any
9 * remaining processes attached to a block of a specified ID.
10 *
11 * To simplify life for the SysV implementation, the ID is assumed to
12 * consist of two unsigned long values (these are key and ID in SysV
13 * terms). Other platforms may ignore the second value if they need
14 * only one ID number.
15 *
16 *
17 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
18 * Portions Copyright (c) 1994, Regents of the University of California
19 *
20 * src/include/storage/pg_shmem.h
21 *
22 *-------------------------------------------------------------------------
23 */
24#ifndef PG_SHMEM_H
25#define PG_SHMEM_H
26
27#include "storage/dsm_impl.h"
28
29typedef struct PGShmemHeader /* standard header for all Postgres shmem */
30{
31 int32 magic; /* magic # to identify Postgres segments */
32#define PGShmemMagic 679834894
33 pid_t creatorPID; /* PID of creating process (set but unread) */
34 Size totalsize; /* total size of segment */
35 Size freeoffset; /* offset to first free space */
36 dsm_handle dsm_control; /* ID of dynamic shared memory control seg */
37 void *index; /* pointer to ShmemIndex table */
38#ifndef WIN32 /* Windows doesn't have useful inode#s */
39 dev_t device; /* device data directory is on */
40 ino_t inode; /* inode number of data directory */
41#endif
43
44/* GUC variables */
46extern PGDLLIMPORT int huge_pages;
48
49/* Possible values for huge_pages and huge_pages_status */
50typedef enum
51{
54 HUGE_PAGES_TRY, /* only for huge_pages */
55 HUGE_PAGES_UNKNOWN, /* only for huge_pages_status */
57
58/* Possible values for shared_memory_type */
59typedef enum
60{
65
66#ifndef WIN32
67extern PGDLLIMPORT unsigned long UsedShmemSegID;
68#else
69extern PGDLLIMPORT HANDLE UsedShmemSegID;
71#endif
72extern PGDLLIMPORT void *UsedShmemSegAddr;
73
74#if !defined(WIN32) && !defined(EXEC_BACKEND)
75#define DEFAULT_SHARED_MEMORY_TYPE SHMEM_TYPE_MMAP
76#elif !defined(WIN32)
77#define DEFAULT_SHARED_MEMORY_TYPE SHMEM_TYPE_SYSV
78#else
79#define DEFAULT_SHARED_MEMORY_TYPE SHMEM_TYPE_WINDOWS
80#endif
81
82#ifdef EXEC_BACKEND
83extern void PGSharedMemoryReAttach(void);
84extern void PGSharedMemoryNoReAttach(void);
85#endif
86
88 PGShmemHeader **shim);
89extern bool PGSharedMemoryIsInUse(unsigned long id1, unsigned long id2);
90extern void PGSharedMemoryDetach(void);
91extern void GetHugePageSize(Size *hugepagesize, int *mmap_flags);
92
93#endif /* PG_SHMEM_H */
#define PGDLLIMPORT
Definition: c.h:1277
int32_t int32
Definition: c.h:484
size_t Size
Definition: c.h:562
uint32 dsm_handle
Definition: dsm_impl.h:55
HugePagesType
Definition: pg_shmem.h:51
@ HUGE_PAGES_UNKNOWN
Definition: pg_shmem.h:55
@ HUGE_PAGES_ON
Definition: pg_shmem.h:53
@ HUGE_PAGES_OFF
Definition: pg_shmem.h:52
@ HUGE_PAGES_TRY
Definition: pg_shmem.h:54
void PGSharedMemoryDetach(void)
Definition: sysv_shmem.c:970
PGShmemType
Definition: pg_shmem.h:60
@ SHMEM_TYPE_MMAP
Definition: pg_shmem.h:63
@ SHMEM_TYPE_SYSV
Definition: pg_shmem.h:62
@ SHMEM_TYPE_WINDOWS
Definition: pg_shmem.h:61
PGShmemHeader * PGSharedMemoryCreate(Size size, PGShmemHeader **shim)
Definition: sysv_shmem.c:700
PGDLLIMPORT void * UsedShmemSegAddr
Definition: sysv_shmem.c:95
struct PGShmemHeader PGShmemHeader
PGDLLIMPORT int huge_page_size
Definition: guc_tables.c:563
PGDLLIMPORT unsigned long UsedShmemSegID
Definition: sysv_shmem.c:94
void GetHugePageSize(Size *hugepagesize, int *mmap_flags)
Definition: sysv_shmem.c:479
PGDLLIMPORT int huge_pages
Definition: guc_tables.c:562
bool PGSharedMemoryIsInUse(unsigned long id1, unsigned long id2)
Definition: sysv_shmem.c:317
PGDLLIMPORT int shared_memory_type
Definition: ipci.c:55
static pg_noinline void Size size
Definition: slab.c:607
dsm_handle dsm_control
Definition: pg_shmem.h:36
ino_t inode
Definition: pg_shmem.h:40
Size freeoffset
Definition: pg_shmem.h:35
pid_t creatorPID
Definition: pg_shmem.h:33
void * index
Definition: pg_shmem.h:37
dev_t device
Definition: pg_shmem.h:39
int32 magic
Definition: pg_shmem.h:31
Size totalsize
Definition: pg_shmem.h:34
void PGSharedMemoryReAttach(void)
Definition: win32_shmem.c:424
void * ShmemProtectiveRegion
Definition: win32_shmem.c:42
void PGSharedMemoryNoReAttach(void)
Definition: win32_shmem.c:472