57 bool print,
int max_children,
60 const char *stats_string);
67 #define AssertNotInCriticalSection(context) \ 68 Assert(CritSectionCount == 0 || (context)->allowInCritSection) 216 Assert(context != TopMemoryContext);
218 Assert(context != CurrentMemoryContext);
244 context->
ident = NULL;
312 while ((cb = context->
reset_cbs) != NULL)
361 if (new_parent == context->
parent)
385 context->
parent = new_parent;
515 memset(&grand_totals, 0,
sizeof(grand_totals));
520 "Grand total: %zu bytes in %zd blocks; %zu free (%zd chunks); %zu used\n",
535 bool print,
int max_children,
554 memset(&local_totals, 0,
sizeof(local_totals));
560 if (ichild < max_children)
571 if (ichild > max_children)
577 for (i = 0; i <= level; i++)
580 "%d more child contexts containing %zu total in %zd blocks; %zu free (%zd chunks); %zu used\n",
581 ichild - max_children,
608 const char *stats_string)
610 int level = *(
int *) passthru;
612 const char *ident = context->
ident;
620 if (ident && strcmp(name,
"dynahash") == 0)
626 for (i = 0; i < level; i++)
628 fprintf(stderr,
"%s: %s", name, stats_string);
637 int idlen = strlen(ident);
638 bool truncated =
false;
648 unsigned char c = *ident++;
666 #ifdef MEMORY_CONTEXT_CHECKING 674 context->
methods->check(context);
676 MemoryContextCheck(child);
705 if (pointer == NULL || pointer != (
void *)
MAXALIGN(pointer))
711 ptr_context = *(
MemoryContext *) (((
char *) pointer) -
sizeof(
void *));
713 return ptr_context == context;
805 elog(
ERROR,
"invalid memory alloc request size %zu", size);
821 (
errcode(ERRCODE_OUT_OF_MEMORY),
823 errdetail(
"Failed on request of size %zu in memory context \"%s\".",
824 size, context->
name)));
848 elog(
ERROR,
"invalid memory alloc request size %zu", size);
857 (
errcode(ERRCODE_OUT_OF_MEMORY),
859 errdetail(
"Failed on request of size %zu in memory context \"%s\".",
860 size, context->
name)));
886 elog(
ERROR,
"invalid memory alloc request size %zu", size);
895 (
errcode(ERRCODE_OUT_OF_MEMORY),
897 errdetail(
"Failed on request of size %zu in memory context \"%s\".",
898 size, context->
name)));
922 elog(
ERROR,
"invalid memory alloc request size %zu", size);
933 (
errcode(ERRCODE_OUT_OF_MEMORY),
935 errdetail(
"Failed on request of size %zu in memory context \"%s\".",
936 size, context->
name)));
960 elog(
ERROR,
"invalid memory alloc request size %zu", size);
969 (
errcode(ERRCODE_OUT_OF_MEMORY),
971 errdetail(
"Failed on request of size %zu in memory context \"%s\".",
972 size, context->
name)));
991 elog(
ERROR,
"invalid memory alloc request size %zu", size);
1000 (
errcode(ERRCODE_OUT_OF_MEMORY),
1002 errdetail(
"Failed on request of size %zu in memory context \"%s\".",
1003 size, context->
name)));
1025 elog(
ERROR,
"invalid memory alloc request size %zu", size);
1036 (
errcode(ERRCODE_OUT_OF_MEMORY),
1038 errdetail(
"Failed on request of size %zu in memory context \"%s\".",
1039 size, context->
name)));
1076 elog(
ERROR,
"invalid memory alloc request size %zu", size);
1088 (
errcode(ERRCODE_OUT_OF_MEMORY),
1090 errdetail(
"Failed on request of size %zu in memory context \"%s\".",
1091 size, context->
name)));
1114 elog(
ERROR,
"invalid memory alloc request size %zu", size);
1123 (
errcode(ERRCODE_OUT_OF_MEMORY),
1125 errdetail(
"Failed on request of size %zu in memory context \"%s\".",
1126 size, context->
name)));
1146 elog(
ERROR,
"invalid memory alloc request size %zu", size);
1158 (
errcode(ERRCODE_OUT_OF_MEMORY),
1160 errdetail(
"Failed on request of size %zu in memory context \"%s\".",
1161 size, context->
name)));
1177 Size len = strlen(
string) + 1;
1181 memcpy(nstr,
string, len);
1205 memcpy(out, in, len);
1220 while (n > 0 && in[n - 1] ==
'\n')
#define MemSetAligned(start, val, len)
MemoryContextCallbackFunction func
Size(* get_chunk_space)(MemoryContext context, void *pointer)
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
char * pnstrdup(const char *in, Size len)
static void MemoryContextCallResetCallbacks(MemoryContext context)
#define AssertState(condition)
MemoryContext TopTransactionContext
MemoryContextCallback * reset_cbs
void print(const void *obj)
void MemoryContextAllowInCriticalSection(MemoryContext context, bool allow)
void MemoryContextInit(void)
const MemoryContextMethods * methods
MemoryContext MemoryContextGetParent(MemoryContext context)
MemoryContext ErrorContext
void(* reset)(MemoryContext context)
void * MemoryContextAllocExtended(MemoryContext context, Size size, int flags)
void MemoryContextSetParent(MemoryContext context, MemoryContext new_parent)
char * pstrdup(const char *in)
static void MemoryContextStatsInternal(MemoryContext context, int level, bool print, int max_children, MemoryContextCounters *totals)
MemoryContext CurTransactionContext
void * palloc_extended(Size size, int flags)
#define MCXT_ALLOC_NO_OOM
int errcode(int sqlerrcode)
Size GetMemoryChunkSpace(void *pointer)
void MemoryContextReset(MemoryContext context)
#define AssertNotInCriticalSection(context)
void MemoryContextResetOnly(MemoryContext context)
void(* stats)(MemoryContext context, MemoryStatsPrintFunc printfunc, void *passthru, MemoryContextCounters *totals)
void *(* realloc)(MemoryContext context, void *pointer, Size size)
MemoryContext PortalContext
char * pchomp(const char *in)
void pfree(void *pointer)
void(* free_p)(MemoryContext context, void *pointer)
bool MemoryContextIsEmpty(MemoryContext context)
bool(* is_empty)(MemoryContext context)
#define VALGRIND_MEMPOOL_CHANGE(context, optr, nptr, size)
void MemoryContextStats(MemoryContext context)
#define MemSetLoop(start, val, len)
int pg_mbcliplen(const char *mbstr, int len, int limit)
#define ALLOCSET_DEFAULT_SIZES
void * MemoryContextAllocHuge(MemoryContext context, Size size)
#define VALGRIND_MEMPOOL_FREE(context, addr)
int errdetail(const char *fmt,...)
MemoryContext CurrentMemoryContext
void *(* alloc)(MemoryContext context, Size size)
volatile uint32 CritSectionCount
void MemoryContextCreate(MemoryContext node, NodeTag tag, const MemoryContextMethods *methods, MemoryContext parent, const char *name)
#define AssertArg(condition)
void * MemoryContextAllocZeroAligned(MemoryContext context, Size size)
MemoryContext TopMemoryContext
#define AllocSizeIsValid(size)
void MemoryContextDeleteChildren(MemoryContext context)
#define VALGRIND_DESTROY_MEMPOOL(context)
void * palloc0(Size size)
void * MemoryContextAllocZero(MemoryContext context, Size size)
#define VALGRIND_CREATE_MEMPOOL(context, redzones, zeroed)
#define ereport(elevel,...)
Size MemoryContextMemAllocated(MemoryContext context, bool recurse)
#define MemoryContextIsValid(context)
#define VALGRIND_MEMPOOL_ALLOC(context, addr, size)
#define Assert(condition)
void MemoryContextResetChildren(MemoryContext context)
bool MemoryContextContains(MemoryContext context, void *pointer)
void MemoryContextSetIdentifier(MemoryContext context, const char *id)
static void MemoryContextStatsPrint(MemoryContext context, void *passthru, const char *stats_string)
size_t strnlen(const char *str, size_t maxlen)
MemoryContext MessageContext
void * repalloc(void *pointer, Size size)
#define AllocHugeSizeIsValid(size)
void * repalloc_huge(void *pointer, Size size)
int errmsg(const char *fmt,...)
char * MemoryContextStrdup(MemoryContext context, const char *string)
void * MemoryContextAlloc(MemoryContext context, Size size)
struct MemoryContextCallback * next
void MemoryContextRegisterResetCallback(MemoryContext context, MemoryContextCallback *cb)
void(* delete_context)(MemoryContext context)
MemoryContext PostmasterContext
void MemoryContextStatsDetail(MemoryContext context, int max_children)
static MemoryContext GetMemoryChunkContext(void *pointer)
MemoryContext CacheMemoryContext