PostgreSQL Source Code git master
Loading...
Searching...
No Matches
shmem.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * shmem.h
4 * shared memory management structures
5 *
6 * Historical note:
7 * A long time ago, Postgres' shared memory region was allowed to be mapped
8 * at a different address in each process, and shared memory "pointers" were
9 * passed around as offsets relative to the start of the shared memory region.
10 * That is no longer the case: each process must map the shared memory region
11 * at the same address. This means shared memory pointers can be passed
12 * around directly between different processes.
13 *
14 * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
15 * Portions Copyright (c) 1994, Regents of the University of California
16 *
17 * src/include/storage/shmem.h
18 *
19 *-------------------------------------------------------------------------
20 */
21#ifndef SHMEM_H
22#define SHMEM_H
23
24#include "storage/spin.h"
25#include "utils/hsearch.h"
26
27
28/* shmem.c */
30typedef struct PGShmemHeader PGShmemHeader; /* avoid including
31 * storage/pg_shmem.h here */
33extern void *ShmemAlloc(Size size);
34extern void *ShmemAllocNoError(Size size);
35extern bool ShmemAddrIsValid(const void *addr);
36extern void InitShmemIndex(void);
37extern HTAB *ShmemInitHash(const char *name, int64 init_size, int64 max_size,
39extern void *ShmemInitStruct(const char *name, Size size, bool *foundPtr);
40extern Size add_size(Size s1, Size s2);
41extern Size mul_size(Size s1, Size s2);
42
44
45/* ipci.c */
46extern void RequestAddinShmemSpace(Size size);
47
48/* size constants for the shmem index table */
49 /* max size of data structure string name */
50#define SHMEM_INDEX_KEYSIZE (48)
51 /* estimated size of the shmem index table (not a hard limit) */
52#define SHMEM_INDEX_SIZE (64)
53
54/* this is a hash bucket in the shmem index table */
55typedef struct
56{
57 char key[SHMEM_INDEX_KEYSIZE]; /* string name */
58 void *location; /* location in shared mem */
59 Size size; /* # bytes requested for the structure */
60 Size allocated_size; /* # bytes actually allocated */
62
63#endif /* SHMEM_H */
#define PGDLLIMPORT
Definition c.h:1334
int64_t int64
Definition c.h:543
size_t Size
Definition c.h:619
static int fb(int x)
char * s1
char * s2
bool ShmemAddrIsValid(const void *addr)
Definition shmem.c:265
void InitShmemAllocator(PGShmemHeader *seghdr)
Definition shmem.c:122
void InitShmemIndex(void)
Definition shmem.c:274
Size add_size(Size s1, Size s2)
Definition shmem.c:482
PGDLLIMPORT Size pg_get_shmem_pagesize(void)
Definition shmem.c:738
PGDLLIMPORT slock_t * ShmemLock
Definition shmem.c:105
void * ShmemAllocNoError(Size size)
Definition shmem.c:202
Size mul_size(Size s1, Size s2)
Definition shmem.c:497
void * ShmemAlloc(Size size)
Definition shmem.c:182
HTAB * ShmemInitHash(const char *name, int64 init_size, int64 max_size, HASHCTL *infoP, int hash_flags)
Definition shmem.c:323
void RequestAddinShmemSpace(Size size)
Definition ipci.c:75
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition shmem.c:378
#define SHMEM_INDEX_KEYSIZE
Definition shmem.h:50
void * location
Definition shmem.h:58
Size size
Definition shmem.h:59
Size allocated_size
Definition shmem.h:60
const char * name