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 "storage/spin.h"
25 #include "utils/hsearch.h"
26 
27 
28 /* shmem.c */
29 extern PGDLLIMPORT slock_t *ShmemLock;
30 struct PGShmemHeader; /* avoid including storage/pg_shmem.h here */
31 extern void InitShmemAccess(struct PGShmemHeader *seghdr);
32 extern void InitShmemAllocation(void);
33 extern void *ShmemAlloc(Size size);
34 extern void *ShmemAllocNoError(Size size);
35 extern void *ShmemAllocUnlocked(Size size);
36 extern bool ShmemAddrIsValid(const void *addr);
37 extern void InitShmemIndex(void);
38 extern HTAB *ShmemInitHash(const char *name, long init_size, long max_size,
39  HASHCTL *infoP, int hash_flags);
40 extern void *ShmemInitStruct(const char *name, Size size, bool *foundPtr);
41 extern Size add_size(Size s1, Size s2);
42 extern Size mul_size(Size s1, Size s2);
43 
44 /* ipci.c */
45 extern void RequestAddinShmemSpace(Size size);
46 
47 /* size constants for the shmem index table */
48  /* max size of data structure string name */
49 #define SHMEM_INDEX_KEYSIZE (48)
50  /* estimated size of the shmem index table (not a hard limit) */
51 #define SHMEM_INDEX_SIZE (64)
52 
53 /* this is a hash bucket in the shmem index table */
54 typedef struct
55 {
56  char key[SHMEM_INDEX_KEYSIZE]; /* string name */
57  void *location; /* location in shared mem */
58  Size size; /* # bytes requested for the structure */
59  Size allocated_size; /* # bytes actually allocated */
61 
62 #endif /* SHMEM_H */
#define PGDLLIMPORT
Definition: c.h:1274
size_t Size
Definition: c.h:559
char * s1
char * s2
bool ShmemAddrIsValid(const void *addr)
Definition: shmem.c:269
void * ShmemAlloc(Size size)
Definition: shmem.c:147
void * ShmemAllocNoError(Size size)
Definition: shmem.c:167
void InitShmemIndex(void)
Definition: shmem.c:278
Size add_size(Size s1, Size s2)
Definition: shmem.c:488
void InitShmemAccess(struct PGShmemHeader *seghdr)
Definition: shmem.c:97
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:382
PGDLLIMPORT slock_t * ShmemLock
Definition: shmem.c:87
Size mul_size(Size s1, Size s2)
Definition: shmem.c:505
void InitShmemAllocation(void)
Definition: shmem.c:110
void RequestAddinShmemSpace(Size size)
Definition: ipci.c:73
HTAB * ShmemInitHash(const char *name, long init_size, long max_size, HASHCTL *infoP, int hash_flags)
Definition: shmem.c:327
void * ShmemAllocUnlocked(Size size)
Definition: shmem.c:233
#define SHMEM_INDEX_KEYSIZE
Definition: shmem.h:49
static pg_noinline void Size size
Definition: slab.c:607
Definition: dynahash.c:220
void * location
Definition: shmem.h:57
Size size
Definition: shmem.h:58
Size allocated_size
Definition: shmem.h:59
const char * name