PostgreSQL Source Code  git master
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-2024, 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 "utils/hsearch.h"
25 
26 
27 /* shmem.c */
28 extern void InitShmemAccess(void *seghdr);
29 extern void InitShmemAllocation(void);
30 extern void *ShmemAlloc(Size size);
31 extern void *ShmemAllocNoError(Size size);
32 extern void *ShmemAllocUnlocked(Size size);
33 extern bool ShmemAddrIsValid(const void *addr);
34 extern void InitShmemIndex(void);
35 extern HTAB *ShmemInitHash(const char *name, long init_size, long max_size,
36  HASHCTL *infoP, int hash_flags);
37 extern void *ShmemInitStruct(const char *name, Size size, bool *foundPtr);
38 extern Size add_size(Size s1, Size s2);
39 extern Size mul_size(Size s1, Size s2);
40 
41 /* ipci.c */
42 extern void RequestAddinShmemSpace(Size size);
43 
44 /* size constants for the shmem index table */
45  /* max size of data structure string name */
46 #define SHMEM_INDEX_KEYSIZE (48)
47  /* estimated size of the shmem index table (not a hard limit) */
48 #define SHMEM_INDEX_SIZE (64)
49 
50 /* this is a hash bucket in the shmem index table */
51 typedef struct
52 {
53  char key[SHMEM_INDEX_KEYSIZE]; /* string name */
54  void *location; /* location in shared mem */
55  Size size; /* # bytes requested for the structure */
56  Size allocated_size; /* # bytes actually allocated */
58 
59 #endif /* SHMEM_H */
size_t Size
Definition: c.h:592
char * s1
char * s2
bool ShmemAddrIsValid(const void *addr)
Definition: shmem.c:274
void * ShmemAlloc(Size size)
Definition: shmem.c:152
void * ShmemAllocNoError(Size size)
Definition: shmem.c:172
void InitShmemIndex(void)
Definition: shmem.c:283
Size add_size(Size s1, Size s2)
Definition: shmem.c:493
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:387
Size mul_size(Size s1, Size s2)
Definition: shmem.c:510
void InitShmemAllocation(void)
Definition: shmem.c:115
void RequestAddinShmemSpace(Size size)
Definition: ipci.c:75
HTAB * ShmemInitHash(const char *name, long init_size, long max_size, HASHCTL *infoP, int hash_flags)
Definition: shmem.c:332
void * ShmemAllocUnlocked(Size size)
Definition: shmem.c:238
void InitShmemAccess(void *seghdr)
Definition: shmem.c:100
#define SHMEM_INDEX_KEYSIZE
Definition: shmem.h:46
static pg_noinline void Size size
Definition: slab.c:607
Definition: dynahash.c:220
void * location
Definition: shmem.h:54
Size size
Definition: shmem.h:55
Size allocated_size
Definition: shmem.h:56
const char * name