PostgreSQL Source Code git master
Loading...
Searching...
No Matches
shmem.h File Reference
#include "utils/hsearch.h"
Include dependency graph for shmem.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ShmemStructOpts
 
struct  ShmemHashOpts
 
struct  ShmemCallbacks
 

Macros

#define SHMEM_ATTACH_UNKNOWN_SIZE   (-1)
 
#define SHMEM_CALLBACKS_ALLOW_AFTER_STARTUP   0x00000001
 
#define ShmemRequestStruct(...)    ShmemRequestStructWithOpts(&(ShmemStructOpts){__VA_ARGS__})
 
#define ShmemRequestHash(...)    ShmemRequestHashWithOpts(&(ShmemHashOpts){__VA_ARGS__})
 

Typedefs

typedef struct ShmemStructOpts ShmemStructOpts
 
typedef struct ShmemHashOpts ShmemHashOpts
 
typedef void(* ShmemRequestCallback) (void *opaque_arg)
 
typedef void(* ShmemInitCallback) (void *opaque_arg)
 
typedef void(* ShmemAttachCallback) (void *opaque_arg)
 
typedef struct ShmemCallbacks ShmemCallbacks
 

Functions

void RegisterShmemCallbacks (const ShmemCallbacks *callbacks)
 
bool ShmemAddrIsValid (const void *addr)
 
void ShmemRequestStructWithOpts (const ShmemStructOpts *options)
 
void ShmemRequestHashWithOpts (const ShmemHashOpts *options)
 
voidShmemInitStruct (const char *name, Size size, bool *foundPtr)
 
HTABShmemInitHash (const char *name, int64 nelems, HASHCTL *infoP, int hash_flags)
 
voidShmemAlloc (Size size)
 
voidShmemAllocNoError (Size size)
 
PGDLLIMPORT Size pg_get_shmem_pagesize (void)
 
void RequestAddinShmemSpace (Size size)
 

Macro Definition Documentation

◆ SHMEM_ATTACH_UNKNOWN_SIZE

#define SHMEM_ATTACH_UNKNOWN_SIZE   (-1)

Definition at line 69 of file shmem.h.

◆ SHMEM_CALLBACKS_ALLOW_AFTER_STARTUP

#define SHMEM_CALLBACKS_ALLOW_AFTER_STARTUP   0x00000001

Definition at line 167 of file shmem.h.

◆ ShmemRequestHash

#define ShmemRequestHash (   ...)     ShmemRequestHashWithOpts(&(ShmemHashOpts){__VA_ARGS__})

Definition at line 179 of file shmem.h.

180 {__VA_ARGS__})
static int fb(int x)

◆ ShmemRequestStruct

#define ShmemRequestStruct (   ...)     ShmemRequestStructWithOpts(&(ShmemStructOpts){__VA_ARGS__})

Definition at line 176 of file shmem.h.

177 {__VA_ARGS__})

Typedef Documentation

◆ ShmemAttachCallback

typedef void(* ShmemAttachCallback) (void *opaque_arg)

Definition at line 114 of file shmem.h.

◆ ShmemCallbacks

◆ ShmemHashOpts

◆ ShmemInitCallback

typedef void(* ShmemInitCallback) (void *opaque_arg)

Definition at line 113 of file shmem.h.

◆ ShmemRequestCallback

typedef void(* ShmemRequestCallback) (void *opaque_arg)

Definition at line 112 of file shmem.h.

◆ ShmemStructOpts

Function Documentation

◆ pg_get_shmem_pagesize()

PGDLLIMPORT Size pg_get_shmem_pagesize ( void  )
extern

Definition at line 1273 of file shmem.c.

1274{
1276#ifdef WIN32
1278
1280 os_page_size = sysinfo.dwPageSize;
1281#else
1283#endif
1284
1287
1290
1291 return os_page_size;
1292}
#define Assert(condition)
Definition c.h:943
size_t Size
Definition c.h:689
bool IsUnderPostmaster
Definition globals.c:122
int huge_pages_status
Definition guc_tables.c:610
@ HUGE_PAGES_UNKNOWN
Definition pg_shmem.h:56
@ HUGE_PAGES_ON
Definition pg_shmem.h:54
void GetHugePageSize(Size *hugepagesize, int *mmap_flags)
Definition sysv_shmem.c:480

◆ RegisterShmemCallbacks()

void RegisterShmemCallbacks ( const ShmemCallbacks callbacks)
extern

Definition at line 873 of file shmem.c.

874{
876 {
877 /*
878 * After-startup initialization or attachment. Call the appropriate
879 * callbacks immediately.
880 */
881 if ((callbacks->flags & SHMEM_CALLBACKS_ALLOW_AFTER_STARTUP) == 0)
882 elog(ERROR, "cannot request shared memory at this time");
883
885 }
886 else
887 {
888 /* Remember the callbacks for later */
890 (void *) callbacks);
891 }
892}
#define ERROR
Definition elog.h:40
#define elog(elevel,...)
Definition elog.h:228
List * lappend(List *list, void *datum)
Definition list.c:339
static List * registered_shmem_callbacks
Definition shmem.c:157
static void CallShmemCallbacksAfterStartup(const ShmemCallbacks *callbacks)
Definition shmem.c:898
shmem_request_state
Definition shmem.c:185
@ SRS_DONE
Definition shmem.c:212
#define SHMEM_CALLBACKS_ALLOW_AFTER_STARTUP
Definition shmem.h:167

References CallShmemCallbacksAfterStartup(), elog, ERROR, ShmemCallbacks::flags, IsUnderPostmaster, lappend(), registered_shmem_callbacks, SHMEM_CALLBACKS_ALLOW_AFTER_STARTUP, and SRS_DONE.

Referenced by _PG_init().

◆ RequestAddinShmemSpace()

void RequestAddinShmemSpace ( Size  size)
extern

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
static Size total_addin_request
Definition ipci.c:33
Size add_size(Size s1, Size s2)
Definition mcxt.c:1733
bool process_shmem_requests_in_progress
Definition miscinit.c:1792

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

◆ ShmemAddrIsValid()

bool ShmemAddrIsValid ( const void addr)
extern

Definition at line 849 of file shmem.c.

850{
851 return (addr >= ShmemBase) && (addr < ShmemEnd);
852}
static void * ShmemBase
Definition shmem.c:243
static void * ShmemEnd
Definition shmem.c:244

References ShmemBase, and ShmemEnd.

Referenced by ReleasePredXact().

◆ ShmemAlloc()

void * ShmemAlloc ( Size  size)
extern

Definition at line 763 of file shmem.c.

764{
765 void *newSpace;
766 Size allocated_size;
767
768 newSpace = ShmemAllocRaw(size, 0, &allocated_size);
769 if (!newSpace)
772 errmsg("out of shared memory (%zu bytes requested)",
773 size)));
774 return newSpace;
775}
int errcode(int sqlerrcode)
Definition elog.c:875
#define ereport(elevel,...)
Definition elog.h:152
static char * errmsg
static void * ShmemAllocRaw(Size size, Size alignment, Size *allocated_size)
Definition shmem.c:797

References ereport, errcode(), errmsg, ERROR, fb(), and ShmemAllocRaw().

Referenced by InitShmemAllocator().

◆ ShmemAllocNoError()

void * ShmemAllocNoError ( Size  size)
extern

Definition at line 783 of file shmem.c.

784{
785 Size allocated_size;
786
787 return ShmemAllocRaw(size, 0, &allocated_size);
788}

References ShmemAllocRaw().

◆ ShmemInitHash()

HTAB * ShmemInitHash ( const char name,
int64  nelems,
HASHCTL infoP,
int  hash_flags 
)
extern

Definition at line 117 of file shmem_hash.c.

121{
122 bool found;
123 size_t size;
124 void *location;
125
126 size = hash_estimate_size(nelems, infoP->entrysize);
127
128 /*
129 * Look it up in the shmem index or allocate.
130 *
131 * NOTE: The area is requested internally as SHMEM_KIND_STRUCT instead of
132 * SHMEM_KIND_HASH. That's correct because we do the hash table
133 * initialization by calling shmem_hash_create() ourselves. (We don't
134 * expose the request kind to users; if we did, that would be confusing.)
135 */
136 location = ShmemInitStruct(name, size, &found);
137
138 return shmem_hash_create(location, size, found,
139 name, nelems, infoP, hash_flags);
140}
Size hash_estimate_size(int64 num_entries, Size entrysize)
Definition dynahash.c:763
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition shmem.c:1010
HTAB * shmem_hash_create(void *location, size_t size, bool found, const char *name, int64 nelems, HASHCTL *infoP, int hash_flags)
Definition shmem_hash.c:149
const char * name

References fb(), hash_estimate_size(), name, shmem_hash_create(), and ShmemInitStruct().

◆ ShmemInitStruct()

void * ShmemInitStruct ( const char name,
Size  size,
bool foundPtr 
)
extern

Definition at line 1010 of file shmem.c.

1011{
1012 void *ptr = NULL;
1014 .name = name,
1015 .size = size,
1016 .ptr = &ptr,
1017 };
1019
1023
1025
1026 /*
1027 * During postmaster startup, look up the existing entry if any.
1028 */
1029 *foundPtr = false;
1032
1033 /* Initialize it if not found */
1034 if (!*foundPtr)
1036
1038
1039 Assert(ptr != NULL);
1040 return ptr;
1041}
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition lwlock.c:1150
void LWLockRelease(LWLock *lock)
Definition lwlock.c:1767
@ LW_EXCLUSIVE
Definition lwlock.h:104
static void InitShmemIndexEntry(ShmemRequest *request)
Definition shmem.c:511
@ SRS_INITIALIZING
Definition shmem.c:200
@ SRS_REQUESTING
Definition shmem.c:194
#define ShmemIndexLock
Definition shmem.c:236
static bool AttachShmemIndexEntry(ShmemRequest *request, bool missing_ok)
Definition shmem.c:580
@ SHMEM_KIND_STRUCT

References Assert, AttachShmemIndexEntry(), fb(), InitShmemIndexEntry(), IsUnderPostmaster, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), name, SHMEM_KIND_STRUCT, ShmemIndexLock, SRS_DONE, SRS_INITIALIZING, and SRS_REQUESTING.

Referenced by ShmemInitHash().

◆ ShmemRequestHashWithOpts()

void ShmemRequestHashWithOpts ( const ShmemHashOpts options)
extern

Definition at line 44 of file shmem_hash.c.

45{
47
48 Assert(options->name != NULL);
49
51 sizeof(ShmemHashOpts));
53
54 /* Set options for the fixed-size area holding the hash table */
55 options_copy->base.name = options->name;
56 options_copy->base.size = hash_estimate_size(options_copy->nelems,
57 options_copy->hash_info.entrysize);
58
60}
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition mcxt.c:1235
MemoryContext TopMemoryContext
Definition mcxt.c:167
void ShmemRequestInternal(ShmemStructOpts *options, ShmemRequestKind kind)
Definition shmem.c:336
@ SHMEM_KIND_HASH

References Assert, fb(), hash_estimate_size(), memcpy(), MemoryContextAlloc(), SHMEM_KIND_HASH, ShmemRequestInternal(), and TopMemoryContext.

◆ ShmemRequestStructWithOpts()