43#define MaxAllocSize ((Size) 0x3fffffff)
45#define AllocSizeIsValid(size) ((Size) (size) <= MaxAllocSize)
48#define MaxAllocHugeSize (SIZE_MAX / 2)
50#define InvalidAllocSize SIZE_MAX
52#define AllocHugeSizeIsValid(size) ((Size) (size) <= MaxAllocHugeSize)
59#define MEMORY_CONTEXT_IDENT_SHMEM_SIZE 64
61#define MEMORY_CONTEXT_REPORT_MAX_PER_BACKEND ((size_t) (1 * 1024 * 1024))
69#define MAX_MEMORY_CONTEXT_STATS_SIZE (sizeof(MemoryStatsEntry) + \
70 (100 * sizeof(int)) + (2 * MEMORY_CONTEXT_IDENT_SHMEM_SIZE))
111 int max_level,
int max_children,
112 bool print_to_stderr);
116#ifdef MEMORY_CONTEXT_CHECKING
121#define MemoryContextCopyAndSetIdentifier(cxt, id) \
122 MemoryContextSetIdentifier(cxt, MemoryContextStrdup(cxt, id))
143#ifdef HAVE__BUILTIN_CONSTANT_P
144#define AllocSetContextCreate(parent, name, ...) \
145 (StaticAssertExpr(__builtin_constant_p(name), \
146 "memory context names must be constant strings"), \
147 AllocSetContextCreateInternal(parent, name, __VA_ARGS__))
149#define AllocSetContextCreate \
150 AllocSetContextCreateInternal
177#define ALLOCSET_DEFAULT_MINSIZE 0
178#define ALLOCSET_DEFAULT_INITSIZE (8 * 1024)
179#define ALLOCSET_DEFAULT_MAXSIZE (8 * 1024 * 1024)
180#define ALLOCSET_DEFAULT_SIZES \
181 ALLOCSET_DEFAULT_MINSIZE, ALLOCSET_DEFAULT_INITSIZE, ALLOCSET_DEFAULT_MAXSIZE
187#define ALLOCSET_SMALL_MINSIZE 0
188#define ALLOCSET_SMALL_INITSIZE (1 * 1024)
189#define ALLOCSET_SMALL_MAXSIZE (8 * 1024)
190#define ALLOCSET_SMALL_SIZES \
191 ALLOCSET_SMALL_MINSIZE, ALLOCSET_SMALL_INITSIZE, ALLOCSET_SMALL_MAXSIZE
197#define ALLOCSET_START_SMALL_SIZES \
198 ALLOCSET_SMALL_MINSIZE, ALLOCSET_SMALL_INITSIZE, ALLOCSET_DEFAULT_MAXSIZE
207#define ALLOCSET_SEPARATE_THRESHOLD 8192
209#define SLAB_DEFAULT_BLOCK_SIZE (8 * 1024)
210#define SLAB_LARGE_BLOCK_SIZE (8 * 1024 * 1024)
241 const unsigned char *p = (
const unsigned char *) ptr;
242 const unsigned char *end = &p[
len];
243 const unsigned char *aligned_end = (
const unsigned char *)
244 ((uintptr_t) end & (~(
sizeof(size_t) - 1)));
246 if (
len <
sizeof(
size_t))
257 if (
len <
sizeof(
size_t) * 8)
260 while (((uintptr_t) p & (
sizeof(size_t) - 1)) != 0)
274 for (; p < aligned_end; p +=
sizeof(size_t))
276 if (*(
size_t *) p != 0)
292 while (((uintptr_t) p & (
sizeof(size_t) - 1)) != 0)
311 for (; p < aligned_end - (
sizeof(size_t) * 7); p +=
sizeof(size_t) * 8)
313 if ((((
size_t *) p)[0] != 0) | (((
size_t *) p)[1] != 0) |
314 (((
size_t *) p)[2] != 0) | (((
size_t *) p)[3] != 0) |
315 (((
size_t *) p)[4] != 0) | (((
size_t *) p)[5] != 0) |
316 (((
size_t *) p)[6] != 0) | (((
size_t *) p)[7] != 0))
326 for (; p < aligned_end; p +=
sizeof(size_t))
328 if (*(
size_t *) p != 0)
void HandleGetMemoryContextInterrupt(void)
PGDLLIMPORT MemoryContext CurTransactionContext
bool MemoryContextIsEmpty(MemoryContext context)
void MemoryContextMemConsumed(MemoryContext context, MemoryContextCounters *consumed)
void MemoryContextReset(MemoryContext context)
PGDLLIMPORT MemoryContext MessageContext
struct MemoryStatsBackendState MemoryStatsBackendState
Size MemoryContextReportingShmemSize(void)
PGDLLIMPORT MemoryContext TopMemoryContext
PGDLLIMPORT MemoryContext TopTransactionContext
PGDLLIMPORT dsa_area * MemoryStatsDsaArea
void HandleLogMemoryContextInterrupt(void)
const char * ContextTypeToString(NodeTag type)
void MemoryContextSetParent(MemoryContext context, MemoryContext new_parent)
void AtProcExit_memstats_cleanup(int code, Datum arg)
Size GetMemoryChunkSpace(void *pointer)
void ProcessGetMemoryContextInterrupt(void)
void MemoryContextDeleteChildren(MemoryContext context)
MemoryContext GetMemoryChunkContext(void *pointer)
PGDLLIMPORT MemoryContext PostmasterContext
void MemoryContextStatsDetail(MemoryContext context, int max_level, int max_children, bool print_to_stderr)
Size MemoryContextMemAllocated(MemoryContext context, bool recurse)
void MemoryContextStats(MemoryContext context)
MemoryContext SlabContextCreate(MemoryContext parent, const char *name, Size blockSize, Size chunkSize)
void MemoryContextInit(void)
MemoryContext BumpContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
PGDLLIMPORT MemoryContext CacheMemoryContext
PGDLLIMPORT MemoryStatsBackendState * memCxtState
struct MemoryStatsContextId MemoryStatsContextId
struct MemoryStatsCtl MemoryStatsCtl
MemoryContext MemoryContextGetParent(MemoryContext context)
void ProcessLogMemoryContextInterrupt(void)
void MemoryContextReportingShmemInit(void)
struct MemoryStatsEntry MemoryStatsEntry
PGDLLIMPORT MemoryContext PortalContext
MemoryContext GenerationContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
static bool pg_memory_is_all_zeros(const void *ptr, size_t len)
void MemoryContextDelete(MemoryContext context)
void MemoryContextAllowInCriticalSection(MemoryContext context, bool allow)
PGDLLIMPORT MemoryStatsCtl * memCxtArea
void MemoryContextResetChildren(MemoryContext context)
void MemoryContextSetIdentifier(MemoryContext context, const char *id)
void MemoryContextResetOnly(MemoryContext context)
PGDLLIMPORT MemoryContext ErrorContext
MemoryContext AllocSetContextCreateInternal(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
TimestampTz stats_timestamp
ConditionVariable memcxt_cv
dsa_pointer memstats_dsa_pointer
dsa_handle memstats_dsa_handle