138 shmhdr->
freeoffset = aligned - (
char *) shmhdr;
141 shmhdr->
index = NULL;
161 (
errcode(ERRCODE_OUT_OF_MEMORY),
162 errmsg(
"out of shared memory (%zu bytes requested)",
205 *allocated_size = size;
213 newFree = newStart + size;
214 if (newFree <= ShmemSegHdr->totalsize)
216 newSpace = (
char *)
ShmemBase + newStart;
254 newFree = newStart + size;
257 (
errcode(ERRCODE_OUT_OF_MEMORY),
258 errmsg(
"out of shared memory (%zu bytes requested)",
262 newSpace = (
char *)
ShmemBase + newStart;
406 structPtr = shmemseghdr->
index;
421 shmemseghdr->
index = structPtr;
436 (
errcode(ERRCODE_OUT_OF_MEMORY),
437 errmsg(
"could not create ShmemIndex entry for data structure \"%s\"",
448 if (result->
size != size)
452 (
errmsg(
"ShmemIndex entry size is wrong for data structure"
453 " \"%s\": expected %zu, actual %zu",
464 if (structPtr == NULL)
470 (
errcode(ERRCODE_OUT_OF_MEMORY),
471 errmsg(
"not enough shared memory for data structure"
472 " \"%s\" (%zu bytes requested)",
500 if (result <
s1 || result <
s2)
502 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
503 errmsg(
"requested shared memory size overflows size_t")));
515 if (
s1 == 0 ||
s2 == 0)
519 if (result /
s2 !=
s1)
521 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
522 errmsg(
"requested shared memory size overflows size_t")));
530#define PG_GET_SHMEM_SIZES_COLS 4
534 Size named_allocated = 0;
545 memset(nulls, 0,
sizeof(nulls));
552 named_allocated += ent->allocated_size;
587#define PG_GET_SHMEM_NUMA_SIZES_COLS 3
596 uint64 shm_total_page_count,
602 elog(
ERROR,
"libnuma initialization failed or NUMA is not supported on this platform");
607 nodes =
palloc(
sizeof(
Size) * (max_nodes + 1));
632 page_ptrs =
palloc0(
sizeof(
void *) * shm_total_page_count);
633 pages_status =
palloc(
sizeof(
int) * shm_total_page_count);
636 elog(
DEBUG1,
"NUMA: page-faulting shared memory segments for proper NUMA readouts");
643 memset(nulls, 0,
sizeof(nulls));
658 endptr = (
char *)
TYPEALIGN(os_page_size,
659 (
char *) ent->location + ent->allocated_size);
660 total_len = (endptr - startptr);
662 shm_ent_page_count = total_len / os_page_size;
668 memset(pages_status, 0xff,
sizeof(
int) * shm_ent_page_count);
678 for (
i = 0;
i < shm_ent_page_count;
i++)
680 page_ptrs[
i] = startptr + (
i * os_page_size);
689 elog(
ERROR,
"failed NUMA pages inquiry status: %m");
692 memset(nodes, 0,
sizeof(
Size) * (max_nodes + 1));
694 for (
i = 0;
i < shm_ent_page_count;
i++)
696 int s = pages_status[
i];
699 if (s < 0 || s > max_nodes)
701 elog(
ERROR,
"invalid NUMA node id outside of allowed range "
712 for (
i = 0;
i <= max_nodes;
i++)
744 GetSystemInfo(&sysinfo);
745 os_page_size = sysinfo.dwPageSize;
747 os_page_size = sysconf(_SC_PAGESIZE);
static Datum values[MAXATTR]
#define CStringGetTextDatum(s)
#define CACHELINEALIGN(LEN)
#define TYPEALIGN(ALIGNVAL, LEN)
#define TYPEALIGN_DOWN(ALIGNVAL, LEN)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
HTAB * hash_create(const char *tabname, int64 nelem, const HASHCTL *info, int flags)
Size hash_get_shared_size(HASHCTL *info, int flags)
int64 hash_select_dirsize(int64 num_entries)
void * hash_seq_search(HASH_SEQ_STATUS *status)
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define PG_RETURN_BOOL(x)
void InitMaterializedSRF(FunctionCallInfo fcinfo, bits32 flags)
Assert(PointerIsAligned(start, uint64))
if(TABLE==NULL||TABLE_index==NULL)
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
void LWLockRelease(LWLock *lock)
void * palloc0(Size size)
#define CHECK_FOR_INTERRUPTS()
PGDLLIMPORT int pg_numa_get_max_node(void)
#define pg_numa_touch_mem_if_required(ptr)
PGDLLIMPORT int pg_numa_query_pages(int pid, unsigned long count, void **pages, int *status)
PGDLLIMPORT int pg_numa_init(void)
static Datum Int64GetDatum(int64 X)
static Datum Int32GetDatum(int32 X)
bool ShmemAddrIsValid(const void *addr)
Datum pg_get_shmem_allocations_numa(PG_FUNCTION_ARGS)
Datum pg_numa_available(PG_FUNCTION_ARGS)
Datum pg_get_shmem_allocations(PG_FUNCTION_ARGS)
void InitShmemIndex(void)
void InitShmemAccess(PGShmemHeader *seghdr)
Size add_size(Size s1, Size s2)
Size pg_get_shmem_pagesize(void)
#define PG_GET_SHMEM_NUMA_SIZES_COLS
void * ShmemAllocNoError(Size size)
Size mul_size(Size s1, Size s2)
void * ShmemAlloc(Size size)
HTAB * ShmemInitHash(const char *name, int64 init_size, int64 max_size, HASHCTL *infoP, int hash_flags)
#define PG_GET_SHMEM_SIZES_COLS
void InitShmemAllocation(void)
static PGShmemHeader * ShmemSegHdr
static void * ShmemAllocRaw(Size size, Size *allocated_size)
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
static void * ShmemAllocUnlocked(Size size)
static bool firstNumaTouch
#define SHMEM_INDEX_KEYSIZE
#define SpinLockInit(lock)
#define SpinLockRelease(lock)
#define SpinLockAcquire(lock)
Tuplestorestate * setResult
void GetHugePageSize(Size *hugepagesize, int *mmap_flags)
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, const Datum *values, const bool *isnull)