57#define BOGUS_MCTX(id) \
58 [id].free_p = BogusFree, \
59 [id].realloc = BogusRealloc, \
60 [id].get_chunk_context = BogusGetChunkContext, \
61 [id].get_chunk_space = BogusGetChunkSpace
74#ifdef MEMORY_CONTEXT_CHECKING
88#ifdef MEMORY_CONTEXT_CHECKING
102#ifdef MEMORY_CONTEXT_CHECKING
116#ifdef MEMORY_CONTEXT_CHECKING
130#ifdef MEMORY_CONTEXT_CHECKING
195#define AssertNotInCriticalSection(context) \
196 Assert(CritSectionCount == 0 || (context)->allowInCritSection)
202#define MCXT_METHOD(pointer, method) \
203 mcxt_methods[GetMemoryChunkMethodID(pointer)].method
225 header = *((
const uint64 *) ((
const char *) pointer -
sizeof(
uint64)));
247 header = *((
const uint64 *) ((
const char *) pointer -
sizeof(
uint64)));
308 elog(
ERROR,
"pfree called with invalid pointer %p (header 0x%016" PRIx64 ")",
315 elog(
ERROR,
"repalloc called with invalid pointer %p (header 0x%016" PRIx64 ")",
323 elog(
ERROR,
"GetMemoryChunkContext called with invalid pointer %p (header 0x%016" PRIx64 ")",
331 elog(
ERROR,
"GetMemoryChunkSpace called with invalid pointer %p (header 0x%016" PRIx64 ")",
758 return MCXT_METHOD(pointer, get_chunk_context) (pointer);
772 return MCXT_METHOD(pointer, get_chunk_space) (pointer);
823 total +=
curr->mem_allocated;
891 "Grand total: %zu bytes in %zu blocks; %zu free (%zu chunks); %zu used\n",
910 errmsg_internal(
"Grand total: %zu bytes in %zu blocks; %zu free (%zu chunks); %zu used",
971 while (child !=
NULL)
980 for (
int i = 0;
i < level;
i++)
983 "%d more child contexts containing %zu total in %zu blocks; %zu free (%zu chunks); %zu used\n",
995 errmsg_internal(
"level: %d; %d more child contexts containing %zu total in %zu blocks; %zu free (%zu chunks); %zu used",
1054 bool truncated =
false;
1067 unsigned char c = *
ident++;
1081 for (
i = 1;
i < level;
i++)
1099#ifdef MEMORY_CONTEXT_CHECKING
1104 context->
methods->check(context);
1207 errdetail(
"Failed on request of size %zu in memory context \"%s\".",
1208 size, context->
name)));
1221 elog(
ERROR,
"invalid memory alloc request size %zu", size);
1298 elog(
ERROR,
"invalid memory alloc request size %zu", size);
1528#ifdef MEMORY_CONTEXT_CHECKING
1563#ifdef MEMORY_CONTEXT_CHECKING
1634#if defined(USE_ASSERT_CHECKING) || defined(USE_VALGRIND)
1669#if defined(USE_ASSERT_CHECKING) || defined(USE_VALGRIND)
1710 elog(
ERROR,
"invalid repalloc0 call: oldsize %zu, new size %zu",
1814 while (n > 0 && in[n - 1] ==
'\n')
MemoryContext AlignedAllocGetChunkContext(void *pointer)
void * AlignedAllocRealloc(void *pointer, Size size, int flags)
Size AlignedAllocGetChunkSpace(void *pointer)
void AlignedAllocFree(void *pointer)
void AllocSetReset(MemoryContext context)
void * AllocSetRealloc(void *pointer, Size size, int flags)
Size AllocSetGetChunkSpace(void *pointer)
MemoryContext AllocSetGetChunkContext(void *pointer)
void AllocSetStats(MemoryContext context, MemoryStatsPrintFunc printfunc, void *passthru, MemoryContextCounters *totals, bool print_to_stderr)
bool AllocSetIsEmpty(MemoryContext context)
void * AllocSetAlloc(MemoryContext context, Size size, int flags)
void AllocSetFree(void *pointer)
void AllocSetDelete(MemoryContext context)
void BumpFree(void *pointer)
void BumpDelete(MemoryContext context)
Size BumpGetChunkSpace(void *pointer)
void BumpStats(MemoryContext context, MemoryStatsPrintFunc printfunc, void *passthru, MemoryContextCounters *totals, bool print_to_stderr)
MemoryContext BumpGetChunkContext(void *pointer)
void BumpReset(MemoryContext context)
bool BumpIsEmpty(MemoryContext context)
void * BumpRealloc(void *pointer, Size size, int flags)
void * BumpAlloc(MemoryContext context, Size size, int flags)
#define TYPEALIGN(ALIGNVAL, LEN)
#define Assert(condition)
#define MemSetAligned(start, val, len)
#define fprintf(file, fmt, msg)
int errmsg_internal(const char *fmt,...)
int errhidestmt(bool hide_stmt)
int errdetail(const char *fmt,...)
int errhidecontext(bool hide_ctx)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define MCXT_ALLOC_NO_OOM
void * GenerationRealloc(void *pointer, Size size, int flags)
void GenerationReset(MemoryContext context)
void GenerationFree(void *pointer)
MemoryContext GenerationGetChunkContext(void *pointer)
Size GenerationGetChunkSpace(void *pointer)
bool GenerationIsEmpty(MemoryContext context)
void GenerationStats(MemoryContext context, MemoryStatsPrintFunc printfunc, void *passthru, MemoryContextCounters *totals, bool print_to_stderr)
void GenerationDelete(MemoryContext context)
void * GenerationAlloc(MemoryContext context, Size size, int flags)
volatile sig_atomic_t LogMemoryContextPending
volatile sig_atomic_t InterruptPending
volatile uint32 CritSectionCount
int pg_mbcliplen(const char *mbstr, int len, int limit)
static void MemoryContextStatsInternal(MemoryContext context, int level, int max_level, int max_children, MemoryContextCounters *totals, bool print_to_stderr)
void MemoryContextUnregisterResetCallback(MemoryContext context, MemoryContextCallback *cb)
void * repalloc0(void *pointer, Size oldsize, Size size)
static void MemoryContextCallResetCallbacks(MemoryContext context)
char * MemoryContextStrdup(MemoryContext context, const char *string)
void * MemoryContextAlloc(MemoryContext context, Size size)
MemoryContext MessageContext
bool MemoryContextIsEmpty(MemoryContext context)
void MemoryContextMemConsumed(MemoryContext context, MemoryContextCounters *consumed)
void MemoryContextReset(MemoryContext context)
void MemoryContextCreate(MemoryContext node, NodeTag tag, MemoryContextMethodID method_id, MemoryContext parent, const char *name)
void * MemoryContextAllocZero(MemoryContext context, Size size)
MemoryContext TopTransactionContext
char * pstrdup(const char *in)
void HandleLogMemoryContextInterrupt(void)
void MemoryContextRegisterResetCallback(MemoryContext context, MemoryContextCallback *cb)
static MemoryContextMethodID GetMemoryChunkMethodID(const void *pointer)
void MemoryContextSetParent(MemoryContext context, MemoryContext new_parent)
static void * BogusRealloc(void *pointer, Size size, int flags)
void * repalloc(void *pointer, Size size)
void pfree(void *pointer)
Size GetMemoryChunkSpace(void *pointer)
void * palloc0(Size size)
static Size BogusGetChunkSpace(void *pointer)
void * MemoryContextAllocAligned(MemoryContext context, Size size, Size alignto, int flags)
void MemoryContextDeleteChildren(MemoryContext context)
MemoryContext TopMemoryContext
char * pchomp(const char *in)
#define AssertNotInCriticalSection(context)
MemoryContext CurTransactionContext
MemoryContext CurrentMemoryContext
static MemoryContext MemoryContextTraverseNext(MemoryContext curr, MemoryContext top)
static bool LogMemoryContextInProgress
MemoryContext GetMemoryChunkContext(void *pointer)
void * MemoryContextAllocExtended(MemoryContext context, Size size, int flags)
void MemoryContextStatsDetail(MemoryContext context, int max_level, int max_children, bool print_to_stderr)
Size MemoryContextMemAllocated(MemoryContext context, bool recurse)
char * pnstrdup(const char *in, Size len)
void MemoryContextStats(MemoryContext context)
void MemoryContextInit(void)
static void BogusFree(void *pointer)
void * palloc_extended(Size size, int flags)
MemoryContext PostmasterContext
void * MemoryContextAllocationFailure(MemoryContext context, Size size, int flags)
static const MemoryContextMethods mcxt_methods[]
void * repalloc_extended(void *pointer, Size size, int flags)
MemoryContext MemoryContextGetParent(MemoryContext context)
void ProcessLogMemoryContextInterrupt(void)
MemoryContext ErrorContext
static MemoryContext BogusGetChunkContext(void *pointer)
MemoryContext CacheMemoryContext
void MemoryContextSizeFailure(MemoryContext context, Size size, int flags)
void * MemoryContextAllocHuge(MemoryContext context, Size size)
void MemoryContextDelete(MemoryContext context)
void MemoryContextAllowInCriticalSection(MemoryContext context, bool allow)
static void MemoryContextDeleteOnly(MemoryContext context)
void MemoryContextResetChildren(MemoryContext context)
static void MemoryContextStatsPrint(MemoryContext context, void *passthru, const char *stats_string, bool print_to_stderr)
void * repalloc_huge(void *pointer, Size size)
void MemoryContextSetIdentifier(MemoryContext context, const char *id)
void MemoryContextResetOnly(MemoryContext context)
static uint64 GetMemoryChunkHeader(const void *pointer)
MemoryContext PortalContext
void * palloc_aligned(Size size, Size alignto, int flags)
#define MCXT_METHOD(pointer, method)
#define VALGRIND_MAKE_MEM_DEFINED(addr, size)
#define VALGRIND_MEMPOOL_CHANGE(context, optr, nptr, size)
#define VALGRIND_MEMPOOL_ALLOC(context, addr, size)
#define VALGRIND_MEMPOOL_FREE(context, addr)
#define VALGRIND_MAKE_MEM_NOACCESS(addr, size)
#define MemoryContextIsValid(context)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define AllocHugeSizeIsValid(size)
#define AllocSizeIsValid(size)
#define MEMORY_CONTEXT_METHODID_MASK
#define PallocAlignedExtraBytes(alignto)
@ MCTX_15_RESERVED_WIPEDMEM_ID
@ MCTX_1_RESERVED_GLIBC_ID
@ MCTX_0_RESERVED_UNUSEDMEM_ID
@ MCTX_2_RESERVED_GLIBC_ID
@ MCTX_ALIGNED_REDIRECT_ID
#define PointerGetMemoryChunk(p)
static void MemoryChunkSetHdrMask(MemoryChunk *chunk, void *block, Size value, MemoryContextMethodID methodid)
void * SlabAlloc(MemoryContext context, Size size, int flags)
void SlabFree(void *pointer)
void SlabReset(MemoryContext context)
Size SlabGetChunkSpace(void *pointer)
bool SlabIsEmpty(MemoryContext context)
MemoryContext SlabGetChunkContext(void *pointer)
void * SlabRealloc(void *pointer, Size size, int flags)
void SlabStats(MemoryContext context, MemoryStatsPrintFunc printfunc, void *passthru, MemoryContextCounters *totals, bool print_to_stderr)
void SlabDelete(MemoryContext context)
bool stack_is_too_deep(void)
struct MemoryContextCallback * next
MemoryContextCallbackFunction func
MemoryContextCallback * reset_cbs
const MemoryContextMethods * methods
void(* delete_context)(MemoryContext context)
void(* stats)(MemoryContext context, MemoryStatsPrintFunc printfunc, void *passthru, MemoryContextCounters *totals, bool print_to_stderr)
bool(* is_empty)(MemoryContext context)
void *(* alloc)(MemoryContext context, Size size, int flags)
void(* reset)(MemoryContext context)