PostgreSQL Source Code git master
Loading...
Searching...
No Matches
shmem.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * shmem.c
4 * create shared memory and initialize shared memory data structures.
5 *
6 * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 *
10 * IDENTIFICATION
11 * src/backend/storage/ipc/shmem.c
12 *
13 *-------------------------------------------------------------------------
14 */
15/*
16 * POSTGRES processes share one or more regions of shared memory.
17 * The shared memory is created by a postmaster and is inherited
18 * by each backend via fork() (or, in some ports, via other OS-specific
19 * methods). The routines in this file are used for allocating and
20 * binding to shared memory data structures.
21 *
22 * NOTES:
23 * (a) There are three kinds of shared memory data structures
24 * available to POSTGRES: fixed-size structures, queues and hash
25 * tables. Fixed-size structures contain things like global variables
26 * for a module and should never be allocated after the shared memory
27 * initialization phase. Hash tables have a fixed maximum size, but
28 * their actual size can vary dynamically. When entries are added
29 * to the table, more space is allocated. Queues link data structures
30 * that have been allocated either within fixed-size structures or as hash
31 * buckets. Each shared data structure has a string name to identify
32 * it (assigned in the module that declares it).
33 *
34 * (b) During initialization, each module looks for its
35 * shared data structures in a hash table called the "Shmem Index".
36 * If the data structure is not present, the caller can allocate
37 * a new one and initialize it. If the data structure is present,
38 * the caller "attaches" to the structure by initializing a pointer
39 * in the local address space.
40 * The shmem index has two purposes: first, it gives us
41 * a simple model of how the world looks when a backend process
42 * initializes. If something is present in the shmem index,
43 * it is initialized. If it is not, it is uninitialized. Second,
44 * the shmem index allows us to allocate shared memory on demand
45 * instead of trying to preallocate structures and hard-wire the
46 * sizes and locations in header files. If you are using a lot
47 * of shared memory in a lot of different places (and changing
48 * things during development), this is important.
49 *
50 * (c) In standard Unix-ish environments, individual backends do not
51 * need to re-establish their local pointers into shared memory, because
52 * they inherit correct values of those variables via fork() from the
53 * postmaster. However, this does not work in the EXEC_BACKEND case.
54 * In ports using EXEC_BACKEND, new backends have to set up their local
55 * pointers using the method described in (b) above.
56 *
57 * (d) memory allocation model: shared memory can never be
58 * freed, once allocated. Each hash table has its own free list,
59 * so hash buckets can be reused when an item is deleted. However,
60 * if one hash table grows very large and then shrinks, its space
61 * cannot be redistributed to other tables. We could build a simple
62 * hash bucket garbage collector if need be. Right now, it seems
63 * unnecessary.
64 */
65
66#include "postgres.h"
67
68#include "common/int.h"
69#include "fmgr.h"
70#include "funcapi.h"
71#include "miscadmin.h"
72#include "port/pg_numa.h"
73#include "storage/lwlock.h"
74#include "storage/pg_shmem.h"
75#include "storage/shmem.h"
76#include "storage/spin.h"
77#include "utils/builtins.h"
78
79/*
80 * This is the first data structure stored in the shared memory segment, at
81 * the offset that PGShmemHeader->content_offset points to. Allocations by
82 * ShmemAlloc() are carved out of the space after this.
83 *
84 * For the base pointer and the total size of the shmem segment, we rely on
85 * the PGShmemHeader.
86 */
87typedef struct ShmemAllocatorData
88{
89 Size free_offset; /* offset to first free space from ShmemBase */
90 HTAB *index; /* copy of ShmemIndex */
91
92 /* protects shared memory and LWLock allocation */
95
96static void *ShmemAllocRaw(Size size, Size *allocated_size);
97
98/* shared memory global variables */
99
100static PGShmemHeader *ShmemSegHdr; /* shared mem segment header */
101static void *ShmemBase; /* start address of shared memory */
102static void *ShmemEnd; /* end+1 address of shared memory */
103
105slock_t *ShmemLock; /* points to ShmemAllocator->shmem_lock */
106static HTAB *ShmemIndex = NULL; /* primary index hashtable for shmem */
107
108/* To get reliable results for NUMA inquiry we need to "touch pages" once */
109static bool firstNumaTouch = true;
110
112
113/*
114 * InitShmemAllocator() --- set up basic pointers to shared memory.
115 *
116 * Called at postmaster or stand-alone backend startup, to initialize the
117 * allocator's data structure in the shared memory segment. In EXEC_BACKEND,
118 * this is also called at backend startup, to set up pointers to the shared
119 * memory areas.
120 */
121void
123{
124 Assert(seghdr != NULL);
125
126 /*
127 * We assume the pointer and offset are MAXALIGN. Not a hard requirement,
128 * but it's true today and keeps the math below simpler.
129 */
130 Assert(seghdr == (void *) MAXALIGN(seghdr));
131 Assert(seghdr->content_offset == MAXALIGN(seghdr->content_offset));
132
135 ShmemEnd = (char *) ShmemBase + seghdr->totalsize;
136
137#ifndef EXEC_BACKEND
139#endif
141 {
143
144 ShmemAllocator = (ShmemAllocatorData *) ((char *) shmhdr + shmhdr->content_offset);
146 }
147 else
148 {
149 Size offset;
150
151 /*
152 * Allocations after this point should go through ShmemAlloc, which
153 * expects to allocate everything on cache line boundaries. Make sure
154 * the first allocation begins on a cache line boundary.
155 */
156 offset = CACHELINEALIGN(seghdr->content_offset + sizeof(ShmemAllocatorData));
157 if (offset > seghdr->totalsize)
160 errmsg("out of shared memory (%zu bytes requested)",
161 offset)));
162
163 ShmemAllocator = (ShmemAllocatorData *) ((char *) seghdr + seghdr->content_offset);
164
167 ShmemAllocator->free_offset = offset;
168 /* ShmemIndex can't be set up yet (need LWLocks first) */
170 ShmemIndex = (HTAB *) NULL;
171 }
172}
173
174/*
175 * ShmemAlloc -- allocate max-aligned chunk from shared memory
176 *
177 * Throws error if request cannot be satisfied.
178 *
179 * Assumes ShmemLock and ShmemSegHdr are initialized.
180 */
181void *
183{
184 void *newSpace;
185 Size allocated_size;
186
187 newSpace = ShmemAllocRaw(size, &allocated_size);
188 if (!newSpace)
191 errmsg("out of shared memory (%zu bytes requested)",
192 size)));
193 return newSpace;
194}
195
196/*
197 * ShmemAllocNoError -- allocate max-aligned chunk from shared memory
198 *
199 * As ShmemAlloc, but returns NULL if out of space, rather than erroring.
200 */
201void *
203{
204 Size allocated_size;
205
206 return ShmemAllocRaw(size, &allocated_size);
207}
208
209/*
210 * ShmemAllocRaw -- allocate align chunk and return allocated size
211 *
212 * Also sets *allocated_size to the number of bytes allocated, which will
213 * be equal to the number requested plus any padding we choose to add.
214 */
215static void *
216ShmemAllocRaw(Size size, Size *allocated_size)
217{
220 void *newSpace;
221
222 /*
223 * Ensure all space is adequately aligned. We used to only MAXALIGN this
224 * space but experience has proved that on modern systems that is not good
225 * enough. Many parts of the system are very sensitive to critical data
226 * structures getting split across cache line boundaries. To avoid that,
227 * attempt to align the beginning of the allocation to a cache line
228 * boundary. The calling code will still need to be careful about how it
229 * uses the allocated space - e.g. by padding each element in an array of
230 * structures out to a power-of-two size - but without this, even that
231 * won't be sufficient.
232 */
233 size = CACHELINEALIGN(size);
234 *allocated_size = size;
235
237
239
241
242 newFree = newStart + size;
243 if (newFree <= ShmemSegHdr->totalsize)
244 {
245 newSpace = (char *) ShmemBase + newStart;
247 }
248 else
249 newSpace = NULL;
250
252
253 /* note this assert is okay with newSpace == NULL */
255
256 return newSpace;
257}
258
259/*
260 * ShmemAddrIsValid -- test if an address refers to shared memory
261 *
262 * Returns true if the pointer points within the shared memory segment.
263 */
264bool
265ShmemAddrIsValid(const void *addr)
266{
267 return (addr >= ShmemBase) && (addr < ShmemEnd);
268}
269
270/*
271 * InitShmemIndex() --- set up or attach to shmem index table.
272 */
273void
275{
276 HASHCTL info;
277
278 /*
279 * Create the shared memory shmem index.
280 *
281 * Since ShmemInitHash calls ShmemInitStruct, which expects the ShmemIndex
282 * hashtable to exist already, we have a bit of a circularity problem in
283 * initializing the ShmemIndex itself. The special "ShmemIndex" hash
284 * table name will tell ShmemInitStruct to fake it.
285 */
287 info.entrysize = sizeof(ShmemIndexEnt);
288
289 ShmemIndex = ShmemInitHash("ShmemIndex",
291 &info,
293}
294
295/*
296 * ShmemInitHash -- Create and initialize, or attach to, a
297 * shared memory hash table.
298 *
299 * We assume caller is doing some kind of synchronization
300 * so that two processes don't try to create/initialize the same
301 * table at once. (In practice, all creations are done in the postmaster
302 * process; child processes should always be attaching to existing tables.)
303 *
304 * max_size is the estimated maximum number of hashtable entries. This is
305 * not a hard limit, but the access efficiency will degrade if it is
306 * exceeded substantially (since it's used to compute directory size and
307 * the hash table buckets will get overfull).
308 *
309 * init_size is the number of hashtable entries to preallocate. For a table
310 * whose maximum size is certain, this should be equal to max_size; that
311 * ensures that no run-time out-of-shared-memory failures can occur.
312 *
313 * *infoP and hash_flags must specify at least the entry sizes and key
314 * comparison semantics (see hash_create()). Flag bits and values specific
315 * to shared-memory hash tables are added here, except that callers may
316 * choose to specify HASH_PARTITION and/or HASH_FIXED_SIZE.
317 *
318 * Note: before Postgres 9.0, this function returned NULL for some failure
319 * cases. Now, it always throws error instead, so callers need not check
320 * for NULL.
321 */
322HTAB *
323ShmemInitHash(const char *name, /* table string name for shmem index */
324 int64 init_size, /* initial table size */
325 int64 max_size, /* max size of the table */
326 HASHCTL *infoP, /* info about key and bucket size */
327 int hash_flags) /* info about infoP */
328{
329 bool found;
330 void *location;
331
332 /*
333 * Hash tables allocated in shared memory have a fixed directory; it can't
334 * grow or other backends wouldn't be able to find it. So, make sure we
335 * make it big enough to start with.
336 *
337 * The shared memory allocator must be specified too.
338 */
339 infoP->dsize = infoP->max_dsize = hash_select_dirsize(max_size);
340 infoP->alloc = ShmemAllocNoError;
342
343 /* look it up in the shmem index */
344 location = ShmemInitStruct(name,
346 &found);
347
348 /*
349 * if it already exists, attach to it rather than allocate and initialize
350 * new space
351 */
352 if (found)
354
355 /* Pass location of hashtable header to hash_create */
356 infoP->hctl = (HASHHDR *) location;
357
359}
360
361/*
362 * ShmemInitStruct -- Create/attach to a structure in shared memory.
363 *
364 * This is called during initialization to find or allocate
365 * a data structure in shared memory. If no other process
366 * has created the structure, this routine allocates space
367 * for it. If it exists already, a pointer to the existing
368 * structure is returned.
369 *
370 * Returns: pointer to the object. *foundPtr is set true if the object was
371 * already in the shmem index (hence, already initialized).
372 *
373 * Note: before Postgres 9.0, this function returned NULL for some failure
374 * cases. Now, it always throws error instead, so callers need not check
375 * for NULL.
376 */
377void *
378ShmemInitStruct(const char *name, Size size, bool *foundPtr)
379{
380 ShmemIndexEnt *result;
381 void *structPtr;
382
384
385 if (!ShmemIndex)
386 {
387 /* Must be trying to create/attach to ShmemIndex itself */
388 Assert(strcmp(name, "ShmemIndex") == 0);
389
391 {
392 /* Must be initializing a (non-standalone) backend */
395 *foundPtr = true;
396 }
397 else
398 {
399 /*
400 * If the shmem index doesn't exist, we are bootstrapping: we must
401 * be trying to init the shmem index itself.
402 *
403 * Notice that the ShmemIndexLock is released before the shmem
404 * index has been initialized. This should be OK because no other
405 * process can be accessing shared memory yet.
406 */
408 structPtr = ShmemAlloc(size);
410 *foundPtr = false;
411 }
413 return structPtr;
414 }
415
416 /* look it up in the shmem index */
417 result = (ShmemIndexEnt *)
419
420 if (!result)
421 {
425 errmsg("could not create ShmemIndex entry for data structure \"%s\"",
426 name)));
427 }
428
429 if (*foundPtr)
430 {
431 /*
432 * Structure is in the shmem index so someone else has allocated it
433 * already. The size better be the same as the size we are trying to
434 * initialize to, or there is a name conflict (or worse).
435 */
436 if (result->size != size)
437 {
440 (errmsg("ShmemIndex entry size is wrong for data structure"
441 " \"%s\": expected %zu, actual %zu",
442 name, size, result->size)));
443 }
444 structPtr = result->location;
445 }
446 else
447 {
448 Size allocated_size;
449
450 /* It isn't in the table yet. allocate and initialize it */
451 structPtr = ShmemAllocRaw(size, &allocated_size);
452 if (structPtr == NULL)
453 {
454 /* out of memory; remove the failed ShmemIndex entry */
459 errmsg("not enough shared memory for data structure"
460 " \"%s\" (%zu bytes requested)",
461 name, size)));
462 }
463 result->size = size;
464 result->allocated_size = allocated_size;
465 result->location = structPtr;
466 }
467
469
471
473
474 return structPtr;
475}
476
477
478/*
479 * Add two Size values, checking for overflow
480 */
481Size
483{
484 Size result;
485
486 if (pg_add_size_overflow(s1, s2, &result))
489 errmsg("requested shared memory size overflows size_t")));
490 return result;
491}
492
493/*
494 * Multiply two Size values, checking for overflow
495 */
496Size
498{
499 Size result;
500
501 if (pg_mul_size_overflow(s1, s2, &result))
504 errmsg("requested shared memory size overflows size_t")));
505 return result;
506}
507
508/* SQL SRF showing allocated shared memory */
509Datum
511{
512#define PG_GET_SHMEM_SIZES_COLS 4
513 ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
518 bool nulls[PG_GET_SHMEM_SIZES_COLS];
519
520 InitMaterializedSRF(fcinfo, 0);
521
523
525
526 /* output all allocated entries */
527 memset(nulls, 0, sizeof(nulls));
528 while ((ent = (ShmemIndexEnt *) hash_seq_search(&hstat)) != NULL)
529 {
530 values[0] = CStringGetTextDatum(ent->key);
531 values[1] = Int64GetDatum((char *) ent->location - (char *) ShmemSegHdr);
532 values[2] = Int64GetDatum(ent->size);
533 values[3] = Int64GetDatum(ent->allocated_size);
534 named_allocated += ent->allocated_size;
535
536 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc,
537 values, nulls);
538 }
539
540 /* output shared memory allocated but not counted via the shmem index */
541 values[0] = CStringGetTextDatum("<anonymous>");
542 nulls[1] = true;
544 values[3] = values[2];
545 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
546
547 /* output as-of-yet unused shared memory */
548 nulls[0] = true;
550 nulls[1] = false;
552 values[3] = values[2];
553 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
554
556
557 return (Datum) 0;
558}
559
560/*
561 * SQL SRF showing NUMA memory nodes for allocated shared memory
562 *
563 * Compared to pg_get_shmem_allocations(), this function does not return
564 * information about shared anonymous allocations and unused shared memory.
565 */
566Datum
568{
569#define PG_GET_SHMEM_NUMA_SIZES_COLS 3
570 ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
576 void **page_ptrs;
577 int *pages_status;
580 max_nodes;
581 Size *nodes;
582
583 if (pg_numa_init() == -1)
584 elog(ERROR, "libnuma initialization failed or NUMA is not supported on this platform");
585
586 InitMaterializedSRF(fcinfo, 0);
587
590
591 /*
592 * Shared memory allocations can vary in size and may not align with OS
593 * memory page boundaries, while NUMA queries work on pages.
594 *
595 * To correctly map each allocation to NUMA nodes, we need to: 1.
596 * Determine the OS memory page size. 2. Align each allocation's start/end
597 * addresses to page boundaries. 3. Query NUMA node information for all
598 * pages spanning the allocation.
599 */
601
602 /*
603 * Allocate memory for page pointers and status based on total shared
604 * memory size. This simplified approach allocates enough space for all
605 * pages in shared memory rather than calculating the exact requirements
606 * for each segment.
607 *
608 * Add 1, because we don't know how exactly the segments align to OS
609 * pages, so the allocation might use one more memory page. In practice
610 * this is not very likely, and moreover we have more entries, each of
611 * them using only fraction of the total pages.
612 */
616
617 if (firstNumaTouch)
618 elog(DEBUG1, "NUMA: page-faulting shared memory segments for proper NUMA readouts");
619
621
623
624 /* output all allocated entries */
625 while ((ent = (ShmemIndexEnt *) hash_seq_search(&hstat)) != NULL)
626 {
627 int i;
628 char *startptr,
629 *endptr;
630 Size total_len;
631
632 /*
633 * Calculate the range of OS pages used by this segment. The segment
634 * may start / end half-way through a page, we want to count these
635 * pages too. So we align the start/end pointers down/up, and then
636 * calculate the number of pages from that.
637 */
638 startptr = (char *) TYPEALIGN_DOWN(os_page_size, ent->location);
639 endptr = (char *) TYPEALIGN(os_page_size,
640 (char *) ent->location + ent->allocated_size);
641 total_len = (endptr - startptr);
642
643 shm_ent_page_count = total_len / os_page_size;
644
645 /*
646 * If we ever get 0xff (-1) back from kernel inquiry, then we probably
647 * have a bug in mapping buffers to OS pages.
648 */
649 memset(pages_status, 0xff, sizeof(int) * shm_ent_page_count);
650
651 /*
652 * Setup page_ptrs[] with pointers to all OS pages for this segment,
653 * and get the NUMA status using pg_numa_query_pages.
654 *
655 * In order to get reliable results we also need to touch memory
656 * pages, so that inquiry about NUMA memory node doesn't return -2
657 * (ENOENT, which indicates unmapped/unallocated pages).
658 */
659 for (i = 0; i < shm_ent_page_count; i++)
660 {
661 page_ptrs[i] = startptr + (i * os_page_size);
662
663 if (firstNumaTouch)
665
667 }
668
670 elog(ERROR, "failed NUMA pages inquiry status: %m");
671
672 /* Count number of NUMA nodes used for this shared memory entry */
673 memset(nodes, 0, sizeof(Size) * (max_nodes + 2));
674
675 for (i = 0; i < shm_ent_page_count; i++)
676 {
677 int s = pages_status[i];
678
679 /* Ensure we are adding only valid index to the array */
680 if (s >= 0 && s <= max_nodes)
681 {
682 /* valid NUMA node */
683 nodes[s]++;
684 continue;
685 }
686 else if (s == -2)
687 {
688 /* -2 means ENOENT (e.g. page was moved to swap) */
689 nodes[max_nodes + 1]++;
690 continue;
691 }
692
693 elog(ERROR, "invalid NUMA node id outside of allowed range "
694 "[0, " UINT64_FORMAT "]: %d", max_nodes, s);
695 }
696
697 /* no NULLs for regular nodes */
698 memset(nulls, 0, sizeof(nulls));
699
700 /*
701 * Add one entry for each NUMA node, including those without allocated
702 * memory for this segment.
703 */
704 for (i = 0; i <= max_nodes; i++)
705 {
706 values[0] = CStringGetTextDatum(ent->key);
707 values[1] = Int32GetDatum(i);
709
710 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc,
711 values, nulls);
712 }
713
714 /* The last entry is used for pages without a NUMA node. */
715 nulls[1] = true;
716 values[0] = CStringGetTextDatum(ent->key);
718
719 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc,
720 values, nulls);
721 }
722
724 firstNumaTouch = false;
725
726 return (Datum) 0;
727}
728
729/*
730 * Determine the memory page size used for the shared memory segment.
731 *
732 * If the shared segment was allocated using huge pages, returns the size of
733 * a huge page. Otherwise returns the size of regular memory page.
734 *
735 * This should be used only after the server is started.
736 */
737Size
739{
741#ifdef WIN32
743
745 os_page_size = sysinfo.dwPageSize;
746#else
748#endif
749
752
755
756 return os_page_size;
757}
758
759Datum
static Datum values[MAXATTR]
Definition bootstrap.c:155
#define CStringGetTextDatum(s)
Definition builtins.h:97
#define CACHELINEALIGN(LEN)
Definition c.h:829
#define MAXALIGN(LEN)
Definition c.h:826
#define TYPEALIGN(ALIGNVAL, LEN)
Definition c.h:819
#define Assert(condition)
Definition c.h:873
int64_t int64
Definition c.h:543
#define UINT64_FORMAT
Definition c.h:565
uint64_t uint64
Definition c.h:547
size_t Size
Definition c.h:619
#define TYPEALIGN_DOWN(ALIGNVAL, LEN)
Definition c.h:831
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition dynahash.c:952
HTAB * hash_create(const char *tabname, int64 nelem, const HASHCTL *info, int flags)
Definition dynahash.c:358
Size hash_get_shared_size(HASHCTL *info, int flags)
Definition dynahash.c:854
int64 hash_select_dirsize(int64 num_entries)
Definition dynahash.c:830
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition dynahash.c:1415
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition dynahash.c:1380
int errcode(int sqlerrcode)
Definition elog.c:863
int errmsg(const char *fmt,...)
Definition elog.c:1080
#define DEBUG1
Definition elog.h:30
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
#define ereport(elevel,...)
Definition elog.h:150
#define palloc_array(type, count)
Definition fe_memutils.h:76
#define palloc0_array(type, count)
Definition fe_memutils.h:77
#define PG_FUNCTION_ARGS
Definition fmgr.h:193
#define PG_RETURN_BOOL(x)
Definition fmgr.h:360
void InitMaterializedSRF(FunctionCallInfo fcinfo, bits32 flags)
Definition funcapi.c:76
bool IsUnderPostmaster
Definition globals.c:120
int huge_pages_status
Definition guc_tables.c:591
#define HASH_STRINGS
Definition hsearch.h:96
@ HASH_REMOVE
Definition hsearch.h:115
@ HASH_ENTER_NULL
Definition hsearch.h:116
#define HASH_ELEM
Definition hsearch.h:95
#define HASH_ALLOC
Definition hsearch.h:101
#define HASH_DIRSIZE
Definition hsearch.h:94
#define HASH_ATTACH
Definition hsearch.h:104
#define HASH_SHARED_MEM
Definition hsearch.h:103
static bool pg_mul_size_overflow(size_t a, size_t b, size_t *result)
Definition int.h:642
static bool pg_add_size_overflow(size_t a, size_t b, size_t *result)
Definition int.h:608
int i
Definition isn.c:77
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition lwlock.c:1176
void LWLockRelease(LWLock *lock)
Definition lwlock.c:1793
@ LW_SHARED
Definition lwlock.h:113
@ LW_EXCLUSIVE
Definition lwlock.h:112
#define CHECK_FOR_INTERRUPTS()
Definition miscadmin.h:123
PGDLLIMPORT int pg_numa_get_max_node(void)
Definition pg_numa.c:136
#define pg_numa_touch_mem_if_required(ptr)
Definition pg_numa.h:37
PGDLLIMPORT int pg_numa_query_pages(int pid, unsigned long count, void **pages, int *status)
Definition pg_numa.c:130
PGDLLIMPORT int pg_numa_init(void)
Definition pg_numa.c:123
@ HUGE_PAGES_UNKNOWN
Definition pg_shmem.h:56
@ HUGE_PAGES_ON
Definition pg_shmem.h:54
static Datum Int64GetDatum(int64 X)
Definition postgres.h:423
uint64_t Datum
Definition postgres.h:70
static Datum Int32GetDatum(int32 X)
Definition postgres.h:222
static int fb(int x)
char * s1
char * s2
bool ShmemAddrIsValid(const void *addr)
Definition shmem.c:265
Datum pg_get_shmem_allocations_numa(PG_FUNCTION_ARGS)
Definition shmem.c:567
Datum pg_numa_available(PG_FUNCTION_ARGS)
Definition shmem.c:760
void InitShmemAllocator(PGShmemHeader *seghdr)
Definition shmem.c:122
static void * ShmemBase
Definition shmem.c:101
Datum pg_get_shmem_allocations(PG_FUNCTION_ARGS)
Definition shmem.c:510
void InitShmemIndex(void)
Definition shmem.c:274
static void * ShmemEnd
Definition shmem.c:102
Size add_size(Size s1, Size s2)
Definition shmem.c:482
Size pg_get_shmem_pagesize(void)
Definition shmem.c:738
#define PG_GET_SHMEM_NUMA_SIZES_COLS
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
slock_t * ShmemLock
Definition shmem.c:105
HTAB * ShmemInitHash(const char *name, int64 init_size, int64 max_size, HASHCTL *infoP, int hash_flags)
Definition shmem.c:323
#define PG_GET_SHMEM_SIZES_COLS
static PGShmemHeader * ShmemSegHdr
Definition shmem.c:100
static void * ShmemAllocRaw(Size size, Size *allocated_size)
Definition shmem.c:216
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition shmem.c:378
static HTAB * ShmemIndex
Definition shmem.c:106
static ShmemAllocatorData * ShmemAllocator
Definition shmem.c:104
static bool firstNumaTouch
Definition shmem.c:109
#define SHMEM_INDEX_SIZE
Definition shmem.h:52
#define SHMEM_INDEX_KEYSIZE
Definition shmem.h:50
#define SpinLockInit(lock)
Definition spin.h:57
#define SpinLockRelease(lock)
Definition spin.h:61
#define SpinLockAcquire(lock)
Definition spin.h:59
Size keysize
Definition hsearch.h:75
Size entrysize
Definition hsearch.h:76
Size totalsize
Definition pg_shmem.h:34
slock_t shmem_lock
Definition shmem.c:93
void * location
Definition shmem.h:58
Size size
Definition shmem.h:59
Size allocated_size
Definition shmem.h:60
void GetHugePageSize(Size *hugepagesize, int *mmap_flags)
Definition sysv_shmem.c:480
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, const Datum *values, const bool *isnull)
Definition tuplestore.c:784
const char * name