PostgreSQL Source Code  git master
memutils.h File Reference
#include "nodes/memnodes.h"
Include dependency graph for memutils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MaxAllocSize   ((Size) 0x3fffffff) /* 1 gigabyte - 1 */
 
#define AllocSizeIsValid(size)   ((Size) (size) <= MaxAllocSize)
 
#define MaxAllocHugeSize   (SIZE_MAX / 2)
 
#define AllocHugeSizeIsValid(size)   ((Size) (size) <= MaxAllocHugeSize)
 
#define MemoryContextResetAndDeleteChildren(ctx)   MemoryContextReset(ctx)
 
#define ALLOCSET_DEFAULT_MINSIZE   0
 
#define ALLOCSET_DEFAULT_INITSIZE   (8 * 1024)
 
#define ALLOCSET_DEFAULT_MAXSIZE   (8 * 1024 * 1024)
 
#define ALLOCSET_DEFAULT_SIZES   ALLOCSET_DEFAULT_MINSIZE, ALLOCSET_DEFAULT_INITSIZE, ALLOCSET_DEFAULT_MAXSIZE
 
#define ALLOCSET_SMALL_MINSIZE   0
 
#define ALLOCSET_SMALL_INITSIZE   (1 * 1024)
 
#define ALLOCSET_SMALL_MAXSIZE   (8 * 1024)
 
#define ALLOCSET_SMALL_SIZES   ALLOCSET_SMALL_MINSIZE, ALLOCSET_SMALL_INITSIZE, ALLOCSET_SMALL_MAXSIZE
 
#define ALLOCSET_START_SMALL_SIZES   ALLOCSET_SMALL_MINSIZE, ALLOCSET_SMALL_INITSIZE, ALLOCSET_DEFAULT_MAXSIZE
 
#define ALLOCSET_SEPARATE_THRESHOLD   8192
 
#define SLAB_DEFAULT_BLOCK_SIZE   (8 * 1024)
 
#define SLAB_LARGE_BLOCK_SIZE   (8 * 1024 * 1024)
 

Functions

void MemoryContextInit (void)
 
void MemoryContextReset (MemoryContext context)
 
void MemoryContextDelete (MemoryContext context)
 
void MemoryContextResetOnly (MemoryContext context)
 
void MemoryContextResetChildren (MemoryContext context)
 
void MemoryContextDeleteChildren (MemoryContext context)
 
void MemoryContextSetParent (MemoryContext context, MemoryContext new_parent)
 
Size GetMemoryChunkSpace (void *pointer)
 
MemoryContext MemoryContextGetParent (MemoryContext context)
 
bool MemoryContextIsEmpty (MemoryContext context)
 
void MemoryContextStats (MemoryContext context)
 
void MemoryContextStatsDetail (MemoryContext context, int max_children)
 
void MemoryContextAllowInCriticalSection (MemoryContext context, bool allow)
 
bool MemoryContextContains (MemoryContext context, void *pointer)
 
static MemoryContext GetMemoryChunkContext (void *pointer)
 
MemoryContext MemoryContextCreate (NodeTag tag, Size size, MemoryContextMethods *methods, MemoryContext parent, const char *name)
 
MemoryContext AllocSetContextCreate (MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
 
MemoryContext SlabContextCreate (MemoryContext parent, const char *name, Size blockSize, Size chunkSize)
 

Variables

PGDLLIMPORT MemoryContext TopMemoryContext
 
PGDLLIMPORT MemoryContext ErrorContext
 
PGDLLIMPORT MemoryContext PostmasterContext
 
PGDLLIMPORT MemoryContext CacheMemoryContext
 
PGDLLIMPORT MemoryContext MessageContext
 
PGDLLIMPORT MemoryContext TopTransactionContext
 
PGDLLIMPORT MemoryContext CurTransactionContext
 
PGDLLIMPORT MemoryContext PortalContext
 

Macro Definition Documentation

◆ AllocHugeSizeIsValid

#define AllocHugeSizeIsValid (   size)    ((Size) (size) <= MaxAllocHugeSize)

◆ ALLOCSET_DEFAULT_INITSIZE

#define ALLOCSET_DEFAULT_INITSIZE   (8 * 1024)

◆ ALLOCSET_DEFAULT_MAXSIZE

#define ALLOCSET_DEFAULT_MAXSIZE   (8 * 1024 * 1024)

◆ ALLOCSET_DEFAULT_MINSIZE

#define ALLOCSET_DEFAULT_MINSIZE   0

◆ ALLOCSET_DEFAULT_SIZES

Definition at line 165 of file memutils.h.

Referenced by afterTriggerAddEvent(), afterTriggerInvokeEvents(), AllocateSnapshotBuilder(), ApplyWorkerMain(), AtStart_Memory(), AtSubStart_Memory(), AutoVacLauncherMain(), BackgroundWriterMain(), begin_heap_rewrite(), BeginCopy(), blbuild(), blinsert(), brin_new_memtuple(), bringetbitmap(), brininsert(), btvacuumscan(), BuildEventTriggerCache(), BuildRelationExtStatistics(), CheckpointerMain(), cluster(), compute_index_stats(), CopyTo(), CreateCacheMemoryContext(), CreateExecutorState(), CreateExprContext(), CreateStandaloneExprContext(), createTempGistContext(), createTrgmNFA(), do_analyze_rel(), do_autovacuum(), do_compile(), do_start_worker(), each_worker(), each_worker_jsonb(), elements_worker(), elements_worker_jsonb(), EnablePortalManager(), EventTriggerBeginCompleteQuery(), EventTriggerInvoke(), exec_parse_message(), exec_replication_command(), ExecHashTableCreate(), ExecInitFunctionScan(), ExecInitProjectSet(), ExecInitRecursiveUnion(), ExecInitSetOp(), ExecInitSubPlan(), ExecInitTableFuncScan(), ExecInitUnique(), ExecInitWindowAgg(), file_acquire_sample_rows(), geqo_eval(), get_stmt_mcontext(), GetLocalBufferStorage(), gin_xlog_startup(), ginbeginscan(), ginbuild(), ginbulkdelete(), gininsert(), ginInsertCleanup(), ginPlaceToPage(), gistrescan(), HandleParallelMessages(), hash_create(), index_register(), init_sql_fcache(), initArrayResult(), initArrayResultArr(), initGISTstate(), initialize_peragg(), InitXLogInsert(), inline_function(), inline_set_returning_function(), libpqrcv_processTuples(), logicalrep_relmap_init(), LogicalRepApplyLoop(), materializeQueryResult(), mdinit(), MemoryContextInit(), NIStartBuild(), ParallelWorkerMain(), PerformAuthentication(), pg_decode_startup(), plperl_return_next_internal(), plperl_spi_prepare(), plpgsql_compile_inline(), plpgsql_estate_setup(), plpython_inline_handler(), PLy_cursor_plan(), PLy_cursor_query(), PLy_get_scratch_context(), PLy_procedure_create(), PLy_spi_execute_fetch_result(), PLy_spi_prepare(), PortalCreateHoldStore(), postgresBeginForeignScan(), PostgresMain(), PostmasterMain(), printtup_startup(), rebuild_database_list(), RelationBuildPartitionDesc(), ReorderBufferAllocate(), ResetUnloggedRelations(), sepgsql_avc_init(), spg_xlog_startup(), spgbeginscan(), spgbuild(), spginsert(), SPI_connect(), spi_dest_startup(), StartupDecodingContext(), strlist_to_textarray(), tuplesort_begin_common(), union_tuples(), vacuum(), WalWriterMain(), XLOGShmemInit(), and xml_is_document().

◆ ALLOCSET_SEPARATE_THRESHOLD

#define ALLOCSET_SEPARATE_THRESHOLD   8192

◆ ALLOCSET_SMALL_INITSIZE

#define ALLOCSET_SMALL_INITSIZE   (1 * 1024)

Definition at line 173 of file memutils.h.

Referenced by DiscreteKnapsack(), and get_agg_clause_costs_walker().

◆ ALLOCSET_SMALL_MAXSIZE

#define ALLOCSET_SMALL_MAXSIZE   (8 * 1024)

Definition at line 174 of file memutils.h.

Referenced by DiscreteKnapsack().

◆ ALLOCSET_SMALL_MINSIZE

#define ALLOCSET_SMALL_MINSIZE   0

Definition at line 172 of file memutils.h.

Referenced by DiscreteKnapsack().

◆ ALLOCSET_SMALL_SIZES

◆ ALLOCSET_START_SMALL_SIZES

◆ AllocSizeIsValid

◆ MaxAllocHugeSize

#define MaxAllocHugeSize   (SIZE_MAX / 2)

Definition at line 44 of file memutils.h.

Referenced by grow_memtuples(), and qtext_load_file().

◆ MaxAllocSize

◆ MemoryContextResetAndDeleteChildren

◆ SLAB_DEFAULT_BLOCK_SIZE

#define SLAB_DEFAULT_BLOCK_SIZE   (8 * 1024)

Definition at line 194 of file memutils.h.

Referenced by ReorderBufferAllocate().

◆ SLAB_LARGE_BLOCK_SIZE

#define SLAB_LARGE_BLOCK_SIZE   (8 * 1024 * 1024)

Definition at line 195 of file memutils.h.

Function Documentation

◆ AllocSetContextCreate()

MemoryContext AllocSetContextCreate ( MemoryContext  parent,
const char *  name,
Size  minContextSize,
Size  initBlockSize,
Size  maxBlockSize 
)

Definition at line 322 of file aset.c.

References ALLOC_BLOCKHDRSZ, ALLOC_CHUNK_FRACTION, ALLOC_CHUNK_LIMIT, ALLOC_CHUNKHDRSZ, AllocHugeSizeIsValid, ALLOCSET_SEPARATE_THRESHOLD, AllocSetMethods, AllocBlockData::aset, elog, AllocBlockData::endptr, ereport, errcode(), errdetail(), errmsg(), ERROR, AllocBlockData::freeptr, AllocSetContext::initBlockSize, malloc, MAXALIGN, AllocSetContext::maxBlockSize, MemoryContextCreate(), MemoryContextStats(), name, AllocBlockData::next, offsetof, AllocBlockData::prev, StaticAssertStmt, T_AllocSetContext, TopMemoryContext, and VALGRIND_MAKE_MEM_NOACCESS.

Referenced by _bt_preprocess_array_keys(), _SPI_make_plan_non_temp(), _SPI_save_plan(), afterTriggerAddEvent(), afterTriggerInvokeEvents(), AllocateSnapshotBuilder(), ApplyLauncherMain(), ApplyWorkerMain(), AtStart_Memory(), AtSubStart_Memory(), AutoVacLauncherMain(), BackgroundWriterMain(), begin_heap_rewrite(), BeginCopy(), blbuild(), blinsert(), brin_build_desc(), brin_new_memtuple(), bringetbitmap(), brininsert(), bt_check_every_level(), btvacuumscan(), BuildCachedPlan(), BuildEventTriggerCache(), BuildRelationExtStatistics(), CheckpointerMain(), cluster(), compile_plperl_function(), compile_pltcl_function(), CompleteCachedPlan(), compute_index_stats(), CopyCachedPlan(), CopyTo(), CreateCachedPlan(), CreateCacheMemoryContext(), CreateExecutorState(), CreateExprContext(), CreatePortal(), CreateStandaloneExprContext(), createTempGistContext(), createTrgmNFA(), DiscreteKnapsack(), do_analyze_rel(), do_autovacuum(), do_compile(), do_start_worker(), each_worker(), each_worker_jsonb(), elements_worker(), elements_worker_jsonb(), EnablePortalManager(), EventTriggerBeginCompleteQuery(), EventTriggerInvoke(), exec_parse_message(), exec_replication_command(), ExecHashTableCreate(), ExecInitFunctionScan(), ExecInitProjectSet(), ExecInitRecursiveUnion(), ExecInitSetOp(), ExecInitSubPlan(), ExecInitTableFuncScan(), ExecInitUnique(), ExecInitWindowAgg(), expand_array(), file_acquire_sample_rows(), fill_hba_view(), geqo_eval(), get_stmt_mcontext(), GetLocalBufferStorage(), GetMemoryChunkContext(), gin_xlog_startup(), ginbeginscan(), ginbuild(), ginbulkdelete(), gininsert(), ginInsertCleanup(), ginPlaceToPage(), gistrescan(), HandleParallelMessages(), hash_create(), index_register(), init_MultiFuncCall(), init_sql_fcache(), initArrayResult(), initArrayResultArr(), initGISTstate(), initialize_peragg(), InitXLogInsert(), inline_function(), inline_set_returning_function(), libpqrcv_processTuples(), load_domaintype_info(), load_hba(), load_ident(), load_relcache_init_file(), load_tzoffsets(), logicalrep_relmap_init(), LogicalRepApplyLoop(), lookup_ts_dictionary_cache(), materializeQueryResult(), mdinit(), MemoryContextInit(), mXactCachePut(), NIStartBuild(), ParallelWorkerMain(), PerformAuthentication(), pg_decode_startup(), pgoutput_startup(), pgstat_setup_memcxt(), plperl_return_next_internal(), plperl_spi_prepare(), plpgsql_compile_inline(), plpgsql_estate_setup(), plpython_inline_handler(), pltcl_SPI_prepare(), PLy_cursor_plan(), PLy_cursor_query(), PLy_get_scratch_context(), PLy_procedure_create(), PLy_spi_execute_fetch_result(), PLy_spi_prepare(), PortalCreateHoldStore(), postgresAcquireSampleRowsFunc(), postgresBeginDirectModify(), postgresBeginForeignModify(), postgresBeginForeignScan(), PostgresMain(), PostmasterMain(), printtup_startup(), publicationListToArray(), rebuild_database_list(), ReindexMultipleTables(), RelationBuildPartitionDesc(), RelationBuildPartitionKey(), RelationBuildRowSecurity(), RelationBuildRuleLock(), RelationInitIndexAccessInfo(), ReorderBufferAllocate(), ResetUnloggedRelations(), RevalidateCachedQuery(), sepgsql_avc_init(), spg_xlog_startup(), spgbeginscan(), spgbuild(), spginsert(), SPI_connect(), spi_dest_startup(), StartupDecodingContext(), strlist_to_textarray(), tokenize_file(), tuplesort_begin_common(), union_tuples(), vacuum(), WalWriterMain(), XLOGShmemInit(), and xml_is_document().

327 {
328  AllocSet set;
329 
331  MAXALIGN(sizeof(AllocChunkData)),
332  "padding calculation in AllocChunkData is wrong");
333 
334  /*
335  * First, validate allocation parameters. (If we're going to throw an
336  * error, we should do so before the context is created, not after.) We
337  * somewhat arbitrarily enforce a minimum 1K block size.
338  */
339  if (initBlockSize != MAXALIGN(initBlockSize) ||
340  initBlockSize < 1024)
341  elog(ERROR, "invalid initBlockSize for memory context: %zu",
342  initBlockSize);
343  if (maxBlockSize != MAXALIGN(maxBlockSize) ||
344  maxBlockSize < initBlockSize ||
345  !AllocHugeSizeIsValid(maxBlockSize)) /* must be safe to double */
346  elog(ERROR, "invalid maxBlockSize for memory context: %zu",
347  maxBlockSize);
348  if (minContextSize != 0 &&
349  (minContextSize != MAXALIGN(minContextSize) ||
350  minContextSize <= ALLOC_BLOCKHDRSZ + ALLOC_CHUNKHDRSZ))
351  elog(ERROR, "invalid minContextSize for memory context: %zu",
352  minContextSize);
353 
354  /* Do the type-independent part of context creation */
356  sizeof(AllocSetContext),
358  parent,
359  name);
360 
361  /* Save allocation parameters */
362  set->initBlockSize = initBlockSize;
363  set->maxBlockSize = maxBlockSize;
364  set->nextBlockSize = initBlockSize;
365 
366  /*
367  * Compute the allocation chunk size limit for this context. It can't be
368  * more than ALLOC_CHUNK_LIMIT because of the fixed number of freelists.
369  * If maxBlockSize is small then requests exceeding the maxBlockSize, or
370  * even a significant fraction of it, should be treated as large chunks
371  * too. For the typical case of maxBlockSize a power of 2, the chunk size
372  * limit will be at most 1/8th maxBlockSize, so that given a stream of
373  * requests that are all the maximum chunk size we will waste at most
374  * 1/8th of the allocated space.
375  *
376  * We have to have allocChunkLimit a power of two, because the requested
377  * and actually-allocated sizes of any chunk must be on the same side of
378  * the limit, else we get confused about whether the chunk is "big".
379  *
380  * Also, allocChunkLimit must not exceed ALLOCSET_SEPARATE_THRESHOLD.
381  */
383  "ALLOC_CHUNK_LIMIT != ALLOCSET_SEPARATE_THRESHOLD");
384 
385  set->allocChunkLimit = ALLOC_CHUNK_LIMIT;
386  while ((Size) (set->allocChunkLimit + ALLOC_CHUNKHDRSZ) >
387  (Size) ((maxBlockSize - ALLOC_BLOCKHDRSZ) / ALLOC_CHUNK_FRACTION))
388  set->allocChunkLimit >>= 1;
389 
390  /*
391  * Grab always-allocated space, if requested
392  */
393  if (minContextSize > 0)
394  {
395  Size blksize = minContextSize;
396  AllocBlock block;
397 
398  block = (AllocBlock) malloc(blksize);
399  if (block == NULL)
400  {
402  ereport(ERROR,
403  (errcode(ERRCODE_OUT_OF_MEMORY),
404  errmsg("out of memory"),
405  errdetail("Failed while creating memory context \"%s\".",
406  name)));
407  }
408  block->aset = set;
409  block->freeptr = ((char *) block) + ALLOC_BLOCKHDRSZ;
410  block->endptr = ((char *) block) + blksize;
411  block->prev = NULL;
412  block->next = set->blocks;
413  if (block->next)
414  block->next->prev = block;
415  set->blocks = block;
416  /* Mark block as not to be released at reset time */
417  set->keeper = block;
418 
419  /* Mark unallocated space NOACCESS; leave the block header alone. */
421  blksize - ALLOC_BLOCKHDRSZ);
422  }
423 
424  return (MemoryContext) set;
425 }
#define VALGRIND_MAKE_MEM_NOACCESS(addr, size)
Definition: memdebug.h:27
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ALLOC_BLOCKHDRSZ
Definition: aset.c:99
AllocSet aset
Definition: aset.c:150
char * freeptr
Definition: aset.c:153
#define malloc(a)
Definition: header.h:50
#define StaticAssertStmt(condition, errmessage)
Definition: c.h:753
#define ERROR
Definition: elog.h:43
#define ALLOC_CHUNK_LIMIT
Definition: aset.c:83
void MemoryContextStats(MemoryContext context)
Definition: mcxt.c:437
char * endptr
Definition: aset.c:154
#define ALLOCSET_SEPARATE_THRESHOLD
Definition: memutils.h:192
int errdetail(const char *fmt,...)
Definition: elog.c:873
MemoryContext MemoryContextCreate(NodeTag tag, Size size, MemoryContextMethods *methods, MemoryContext parent, const char *name)
Definition: mcxt.c:639
#define ALLOC_CHUNKHDRSZ
Definition: aset.c:100
static MemoryContextMethods AllocSetMethods
Definition: aset.c:219
AllocBlock next
Definition: aset.c:152
#define ereport(elevel, rest)
Definition: elog.h:122
MemoryContext TopMemoryContext
Definition: mcxt.c:43
#define ALLOC_CHUNK_FRACTION
Definition: aset.c:85
struct AllocBlockData * AllocBlock
Definition: aset.c:102
AllocBlock prev
Definition: aset.c:151
size_t Size
Definition: c.h:404
#define MAXALIGN(LEN)
Definition: c.h:623
const char * name
Definition: encode.c:521
#define AllocHugeSizeIsValid(size)
Definition: memutils.h:46
int errmsg(const char *fmt,...)
Definition: elog.c:797
AllocSetContext * AllocSet
Definition: aset.c:134
#define elog
Definition: elog.h:219
#define offsetof(type, field)
Definition: c.h:593

◆ GetMemoryChunkContext()

static MemoryContext GetMemoryChunkContext ( void *  pointer)
inlinestatic

Definition at line 107 of file memutils.h.

References AllocSetContextCreate(), Assert, AssertArg, MAXALIGN, MemoryContextCreate(), MemoryContextIsValid, name, and SlabContextCreate().

Referenced by GetMemoryChunkSpace(), mark_dummy_rel(), pfree(), repalloc(), repalloc_huge(), and reparameterize_path_by_child().

108 {
109  MemoryContext context;
110 
111  /*
112  * Try to detect bogus pointers handed to us, poorly though we can.
113  * Presumably, a pointer that isn't MAXALIGNED isn't pointing at an
114  * allocated chunk.
115  */
116  Assert(pointer != NULL);
117  Assert(pointer == (void *) MAXALIGN(pointer));
118 
119  /*
120  * OK, it's probably safe to look at the context.
121  */
122  context = *(MemoryContext *) (((char *) pointer) - sizeof(void *));
123 
125 
126  return context;
127 }
#define AssertArg(condition)
Definition: c.h:672
#define MemoryContextIsValid(context)
Definition: memnodes.h:97
#define Assert(condition)
Definition: c.h:670
#define MAXALIGN(LEN)
Definition: c.h:623

◆ GetMemoryChunkSpace()

◆ MemoryContextAllowInCriticalSection()

void MemoryContextAllowInCriticalSection ( MemoryContext  context,
bool  allow 
)

Definition at line 374 of file mcxt.c.

References MemoryContextData::allowInCritSection, AssertArg, and MemoryContextIsValid.

Referenced by mdinit(), MemoryContextInit(), and XLOGShmemInit().

375 {
377 
378  context->allowInCritSection = allow;
379 }
bool allowInCritSection
Definition: memnodes.h:78
#define AssertArg(condition)
Definition: c.h:672
#define MemoryContextIsValid(context)
Definition: memnodes.h:97

◆ MemoryContextContains()

bool MemoryContextContains ( MemoryContext  context,
void *  pointer 
)

Definition at line 566 of file mcxt.c.

References MAXALIGN.

Referenced by eval_windowfunction(), finalize_aggregate(), finalize_partialaggregate(), and finalize_windowaggregate().

567 {
568  MemoryContext ptr_context;
569 
570  /*
571  * NB: Can't use GetMemoryChunkContext() here - that performs assertions
572  * that aren't acceptable here since we might be passed memory not
573  * allocated by any memory context.
574  *
575  * Try to detect bogus pointers handed to us, poorly though we can.
576  * Presumably, a pointer that isn't MAXALIGNED isn't pointing at an
577  * allocated chunk.
578  */
579  if (pointer == NULL || pointer != (void *) MAXALIGN(pointer))
580  return false;
581 
582  /*
583  * OK, it's probably safe to look at the context.
584  */
585  ptr_context = *(MemoryContext *) (((char *) pointer) - sizeof(void *));
586 
587  return ptr_context == context;
588 }
#define MAXALIGN(LEN)
Definition: c.h:623

◆ MemoryContextCreate()

MemoryContext MemoryContextCreate ( NodeTag  tag,
Size  size,
MemoryContextMethods methods,
MemoryContext  parent,
const char *  name 
)

Definition at line 639 of file mcxt.c.

References MemoryContextData::allowInCritSection, Assert, CritSectionCount, MemoryContextData::firstchild, MemoryContextMethods::init, MemoryContextData::isReset, malloc, MemoryContextAlloc(), MemSet, MemoryContextData::methods, MemoryContextData::name, MemoryContextData::nextchild, MemoryContextData::parent, MemoryContextData::prevchild, MemoryContextData::type, and VALGRIND_CREATE_MEMPOOL.

Referenced by AllocSetContextCreate(), GetMemoryChunkContext(), and SlabContextCreate().

643 {
644  MemoryContext node;
645  Size needed = size + strlen(name) + 1;
646 
647  /* creating new memory contexts is not allowed in a critical section */
648  Assert(CritSectionCount == 0);
649 
650  /* Get space for node and name */
651  if (TopMemoryContext != NULL)
652  {
653  /* Normal case: allocate the node in TopMemoryContext */
655  needed);
656  }
657  else
658  {
659  /* Special case for startup: use good ol' malloc */
660  node = (MemoryContext) malloc(needed);
661  Assert(node != NULL);
662  }
663 
664  /* Initialize the node as best we can */
665  MemSet(node, 0, size);
666  node->type = tag;
667  node->methods = methods;
668  node->parent = NULL; /* for the moment */
669  node->firstchild = NULL;
670  node->prevchild = NULL;
671  node->nextchild = NULL;
672  node->isReset = true;
673  node->name = ((char *) node) + size;
674  strcpy(node->name, name);
675 
676  /* Type-specific routine finishes any other essential initialization */
677  node->methods->init(node);
678 
679  /* OK to link node to parent (if any) */
680  /* Could use MemoryContextSetParent here, but doesn't seem worthwhile */
681  if (parent)
682  {
683  node->parent = parent;
684  node->nextchild = parent->firstchild;
685  if (parent->firstchild != NULL)
686  parent->firstchild->prevchild = node;
687  parent->firstchild = node;
688  /* inherit allowInCritSection flag from parent */
689  node->allowInCritSection = parent->allowInCritSection;
690  }
691 
692  VALGRIND_CREATE_MEMPOOL(node, 0, false);
693 
694  /* Return to type-specific creation routine to finish up */
695  return node;
696 }
MemoryContextMethods * methods
Definition: memnodes.h:79
bool allowInCritSection
Definition: memnodes.h:78
#define MemSet(start, val, len)
Definition: c.h:853
void(* init)(MemoryContext context)
Definition: memnodes.h:60
#define malloc(a)
Definition: header.h:50
MemoryContext firstchild
Definition: memnodes.h:81
MemoryContext prevchild
Definition: memnodes.h:82
volatile uint32 CritSectionCount
Definition: globals.c:37
MemoryContext TopMemoryContext
Definition: mcxt.c:43
struct MemoryContextData * MemoryContext
Definition: palloc.h:36
#define VALGRIND_CREATE_MEMPOOL(context, redzones, zeroed)
Definition: memdebug.h:24
#define Assert(condition)
Definition: c.h:670
size_t Size
Definition: c.h:404
const char * name
Definition: encode.c:521
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:706
MemoryContext parent
Definition: memnodes.h:80
MemoryContext nextchild
Definition: memnodes.h:83
NodeTag type
Definition: memnodes.h:75

◆ MemoryContextDelete()

void MemoryContextDelete ( MemoryContext  context)

Definition at line 200 of file mcxt.c.

References Assert, AssertArg, MemoryContextMethods::delete_context, MemoryContextCallResetCallbacks(), MemoryContextDeleteChildren(), MemoryContextIsValid, MemoryContextSetParent(), MemoryContextData::methods, pfree(), and VALGRIND_DESTROY_MEMPOOL.

Referenced by AfterTriggerEndXact(), afterTriggerInvokeEvents(), ApplyLauncherMain(), AtCleanup_Memory(), AtCommit_Memory(), AtEOSubXact_SPI(), AtEOXact_LargeObject(), AtSubCleanup_Memory(), AtSubCommit_Memory(), blbuild(), blinsert(), brin_free_desc(), bringetbitmap(), brininsert(), bt_check_every_level(), btendscan(), btvacuumscan(), BuildRelationExtStatistics(), cluster(), compile_plperl_function(), compile_pltcl_function(), compute_index_stats(), CopyTo(), createTrgmNFA(), decr_dcc_refcount(), DeleteExpandedObject(), DiscreteKnapsack(), do_analyze_rel(), do_start_bgworker(), do_start_worker(), DropCachedPlan(), each_worker(), each_worker_jsonb(), elements_worker(), elements_worker_jsonb(), end_heap_rewrite(), EndCopy(), EventTriggerEndCompleteQuery(), EventTriggerInvoke(), exec_replication_command(), ExecEndRecursiveUnion(), ExecEndSetOp(), ExecEndUnique(), ExecEndWindowAgg(), ExecHashTableDestroy(), file_acquire_sample_rows(), fill_hba_view(), fmgr_sql(), free_plperl_function(), FreeDecodingContext(), FreeExecutorState(), FreeExprContext(), freeGISTstate(), FreeSnapshotBuilder(), geqo_eval(), gin_xlog_cleanup(), ginbuild(), ginbulkdelete(), ginendscan(), gininsert(), ginInsertCleanup(), ginPlaceToPage(), gist_xlog_cleanup(), gistbuild(), hash_destroy(), inline_function(), inline_set_returning_function(), libpqrcv_processTuples(), load_hba(), load_ident(), load_tzoffsets(), makeArrayResultArr(), makeMdArrayResult(), materializeQueryResult(), MemoryContextDeleteChildren(), mergeruns(), NIFinishBuild(), pg_decode_shutdown(), pgstat_clear_snapshot(), plperl_spi_freeplan(), plperl_spi_prepare(), plpgsql_free_function_memory(), pltcl_handler(), pltcl_SPI_prepare(), PLy_cursor_dealloc(), PLy_plan_dealloc(), PLy_pop_execution_context(), PLy_procedure_delete(), PLy_spi_execute_fetch_result(), PortalDrop(), PostgresMain(), printtup_shutdown(), publicationListToArray(), rebuild_database_list(), ReindexMultipleTables(), RelationBuildRowSecurity(), RelationBuildRuleLock(), RelationDestroyRelation(), ReleaseCachedPlan(), ReorderBufferFree(), ResetUnloggedRelations(), RevalidateCachedQuery(), shutdown_MultiFuncCall(), spg_xlog_cleanup(), spgbuild(), spgendscan(), spginsert(), SPI_finish(), SPI_freeplan(), SPI_freetuptable(), StartChildProcess(), strlist_to_textarray(), tokenize_inc_file(), tuplesort_end(), union_tuples(), and vacuum().

201 {
203  /* We had better not be deleting TopMemoryContext ... */
204  Assert(context != TopMemoryContext);
205  /* And not CurrentMemoryContext, either */
206  Assert(context != CurrentMemoryContext);
207 
209 
210  /*
211  * It's not entirely clear whether 'tis better to do this before or after
212  * delinking the context; but an error in a callback will likely result in
213  * leaking the whole context (if it's not a root context) if we do it
214  * after, so let's do it before.
215  */
217 
218  /*
219  * We delink the context from its parent before deleting it, so that if
220  * there's an error we won't have deleted/busted contexts still attached
221  * to the context tree. Better a leak than a crash.
222  */
223  MemoryContextSetParent(context, NULL);
224 
225  context->methods->delete_context(context);
226  VALGRIND_DESTROY_MEMPOOL(context);
227  pfree(context);
228 }
static void MemoryContextCallResetCallbacks(MemoryContext context)
Definition: mcxt.c:282
void MemoryContextSetParent(MemoryContext context, MemoryContext new_parent)
Definition: mcxt.c:317
MemoryContextMethods * methods
Definition: memnodes.h:79
void pfree(void *pointer)
Definition: mcxt.c:949
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
#define AssertArg(condition)
Definition: c.h:672
MemoryContext TopMemoryContext
Definition: mcxt.c:43
void MemoryContextDeleteChildren(MemoryContext context)
Definition: mcxt.c:236
#define VALGRIND_DESTROY_MEMPOOL(context)
Definition: memdebug.h:25
#define MemoryContextIsValid(context)
Definition: memnodes.h:97
#define Assert(condition)
Definition: c.h:670
void(* delete_context)(MemoryContext context)
Definition: memnodes.h:62

◆ MemoryContextDeleteChildren()

void MemoryContextDeleteChildren ( MemoryContext  context)

Definition at line 236 of file mcxt.c.

References AssertArg, MemoryContextData::firstchild, MemoryContextDelete(), and MemoryContextIsValid.

Referenced by AtAbort_Portals(), AtSubAbort_Portals(), exec_stmt_block(), MemoryContextDelete(), MemoryContextReset(), PersistHoldablePortal(), and PortalRunMulti().

237 {
239 
240  /*
241  * MemoryContextDelete will delink the child from me, so just iterate as
242  * long as there is a child.
243  */
244  while (context->firstchild != NULL)
246 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:200
MemoryContext firstchild
Definition: memnodes.h:81
#define AssertArg(condition)
Definition: c.h:672
#define MemoryContextIsValid(context)
Definition: memnodes.h:97

◆ MemoryContextGetParent()

MemoryContext MemoryContextGetParent ( MemoryContext  context)

Definition at line 402 of file mcxt.c.

References AssertArg, MemoryContextIsValid, and MemoryContextData::parent.

Referenced by advance_combine_function(), advance_transition_function(), advance_windowaggregate(), advance_windowaggregate_base(), GetCachedPlan(), pop_stmt_mcontext(), and push_stmt_mcontext().

403 {
405 
406  return context->parent;
407 }
#define AssertArg(condition)
Definition: c.h:672
#define MemoryContextIsValid(context)
Definition: memnodes.h:97
MemoryContext parent
Definition: memnodes.h:80

◆ MemoryContextInit()

void MemoryContextInit ( void  )

Definition at line 89 of file mcxt.c.

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate(), AssertState, MemoryContextAllowInCriticalSection(), and TopMemoryContext.

Referenced by main().

90 {
92 
93  /*
94  * First, initialize TopMemoryContext, which will hold the MemoryContext
95  * nodes for all other contexts. (There is special-case code in
96  * MemoryContextCreate() to handle this call.)
97  */
99  "TopMemoryContext",
101 
102  /*
103  * Not having any other place to point CurrentMemoryContext, make it point
104  * to TopMemoryContext. Caller should change this soon!
105  */
107 
108  /*
109  * Initialize ErrorContext as an AllocSetContext with slow growth rate ---
110  * we don't really expect much to be allocated in it. More to the point,
111  * require it to contain at least 8K at all times. This is the only case
112  * where retained memory in a context is *essential* --- we want to be
113  * sure ErrorContext still has some memory even if we've run out
114  * elsewhere! Also, allow allocations in ErrorContext within a critical
115  * section. Otherwise a PANIC will cause an assertion failure in the error
116  * reporting code, before printing out the real cause of the failure.
117  *
118  * This should be the last step in this function, as elog.c assumes memory
119  * management works once ErrorContext is non-null.
120  */
122  "ErrorContext",
123  8 * 1024,
124  8 * 1024,
125  8 * 1024);
127 }
#define AssertState(condition)
Definition: c.h:673
void MemoryContextAllowInCriticalSection(MemoryContext context, bool allow)
Definition: mcxt.c:374
MemoryContext ErrorContext
Definition: mcxt.c:44
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:165
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
MemoryContext TopMemoryContext
Definition: mcxt.c:43
MemoryContext AllocSetContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: aset.c:322

◆ MemoryContextIsEmpty()

bool MemoryContextIsEmpty ( MemoryContext  context)

Definition at line 414 of file mcxt.c.

References AssertArg, MemoryContextData::firstchild, MemoryContextMethods::is_empty, MemoryContextIsValid, and MemoryContextData::methods.

Referenced by AtSubCommit_Memory().

415 {
417 
418  /*
419  * For now, we consider a memory context nonempty if it has any children;
420  * perhaps this should be changed later.
421  */
422  if (context->firstchild != NULL)
423  return false;
424  /* Otherwise use the type-specific inquiry */
425  return context->methods->is_empty(context);
426 }
MemoryContextMethods * methods
Definition: memnodes.h:79
MemoryContext firstchild
Definition: memnodes.h:81
bool(* is_empty)(MemoryContext context)
Definition: memnodes.h:64
#define AssertArg(condition)
Definition: c.h:672
#define MemoryContextIsValid(context)
Definition: memnodes.h:97

◆ MemoryContextReset()

void MemoryContextReset ( MemoryContext  context)

Definition at line 135 of file mcxt.c.

References AssertArg, MemoryContextData::firstchild, MemoryContextData::isReset, MemoryContextDeleteChildren(), MemoryContextIsValid, and MemoryContextResetOnly().

Referenced by _bt_preprocess_array_keys(), AfterTriggerExecute(), bloomBuildCallback(), brin_memtuple_initialize(), bt_check_level_from_leftmost(), btvacuumpage(), buildSubPlanHash(), CopyOneRowTo(), dumptuples(), each_object_field_end(), each_worker_jsonb(), elements_array_element_end(), elements_worker_jsonb(), errstart(), EventTriggerInvoke(), exec_dynquery_with_params(), exec_stmt_block(), exec_stmt_dynexecute(), exec_stmt_forc(), exec_stmt_foreach_a(), exec_stmt_open(), exec_stmt_raise(), ExecHashTableReset(), ExecMakeTableFunctionResult(), ExecProjectSet(), ExecRecursiveUnion(), execTuplesMatch(), execTuplesUnequal(), fetch_more_data(), file_acquire_sample_rows(), gin_redo(), ginBuildCallback(), ginHeapTupleBulkInsert(), ginInsertCleanup(), ginVacuumPostingTreeLeaves(), gist_redo(), gistBuildCallback(), gistgetbitmap(), gistgettuple(), gistinsert(), gistProcessEmptyingQueue(), gistrescan(), gistScanPage(), HandleParallelMessages(), IndexBuildHeapRangeScan(), IndexCheckExclusion(), keyGetItem(), libpqrcv_processTuples(), LogicalRepApplyLoop(), make_tuple_from_result_row(), pg_decode_change(), pgoutput_change(), plperl_return_next_internal(), PLy_input_convert(), PLy_input_from_tuple(), postgresExecForeignDelete(), postgresExecForeignInsert(), postgresExecForeignUpdate(), printtup(), printtup_20(), printtup_internal_20(), process_ordered_aggregate_multi(), process_ordered_aggregate_single(), ReScanExprContext(), scanPendingInsert(), sepgsql_avc_reset(), setop_fill_hash_table(), spg_redo(), spginsert(), spgistBuildCallback(), spgWalk(), startScanKey(), storeRow(), tfuncLoadRows(), and validate_index_heapscan().

136 {
138 
139  /* save a function call in common case where there are no children */
140  if (context->firstchild != NULL)
142 
143  /* save a function call if no pallocs since startup or last reset */
144  if (!context->isReset)
145  MemoryContextResetOnly(context);
146 }
void MemoryContextResetOnly(MemoryContext context)
Definition: mcxt.c:154
MemoryContext firstchild
Definition: memnodes.h:81
#define AssertArg(condition)
Definition: c.h:672
void MemoryContextDeleteChildren(MemoryContext context)
Definition: mcxt.c:236
#define MemoryContextIsValid(context)
Definition: memnodes.h:97

◆ MemoryContextResetChildren()

void MemoryContextResetChildren ( MemoryContext  context)

Definition at line 176 of file mcxt.c.

References AssertArg, MemoryContextData::firstchild, MemoryContextIsValid, MemoryContextResetChildren(), MemoryContextResetOnly(), and MemoryContextData::nextchild.

Referenced by MemoryContextResetChildren().

177 {
178  MemoryContext child;
179 
181 
182  for (child = context->firstchild; child != NULL; child = child->nextchild)
183  {
185  MemoryContextResetOnly(child);
186  }
187 }
void MemoryContextResetOnly(MemoryContext context)
Definition: mcxt.c:154
MemoryContext firstchild
Definition: memnodes.h:81
#define AssertArg(condition)
Definition: c.h:672
#define MemoryContextIsValid(context)
Definition: memnodes.h:97
void MemoryContextResetChildren(MemoryContext context)
Definition: mcxt.c:176
MemoryContext nextchild
Definition: memnodes.h:83

◆ MemoryContextResetOnly()

void MemoryContextResetOnly ( MemoryContext  context)

Definition at line 154 of file mcxt.c.

References AssertArg, MemoryContextData::isReset, MemoryContextCallResetCallbacks(), MemoryContextIsValid, MemoryContextData::methods, MemoryContextMethods::reset, VALGRIND_CREATE_MEMPOOL, and VALGRIND_DESTROY_MEMPOOL.

Referenced by MemoryContextReset(), and MemoryContextResetChildren().

155 {
157 
158  /* Nothing to do if no pallocs since startup or last reset */
159  if (!context->isReset)
160  {
162  context->methods->reset(context);
163  context->isReset = true;
164  VALGRIND_DESTROY_MEMPOOL(context);
165  VALGRIND_CREATE_MEMPOOL(context, 0, false);
166  }
167 }
static void MemoryContextCallResetCallbacks(MemoryContext context)
Definition: mcxt.c:282
void(* reset)(MemoryContext context)
Definition: memnodes.h:61
MemoryContextMethods * methods
Definition: memnodes.h:79
#define AssertArg(condition)
Definition: c.h:672
#define VALGRIND_DESTROY_MEMPOOL(context)
Definition: memdebug.h:25
#define VALGRIND_CREATE_MEMPOOL(context, redzones, zeroed)
Definition: memdebug.h:24
#define MemoryContextIsValid(context)
Definition: memnodes.h:97

◆ MemoryContextSetParent()

void MemoryContextSetParent ( MemoryContext  context,
MemoryContext  new_parent 
)

Definition at line 317 of file mcxt.c.

References Assert, AssertArg, MemoryContextData::firstchild, MemoryContextIsValid, MemoryContextData::nextchild, MemoryContextData::parent, and MemoryContextData::prevchild.

Referenced by _SPI_save_plan(), CachedPlanSetParentContext(), CompleteCachedPlan(), exec_parse_message(), GetCachedPlan(), load_domaintype_info(), MemoryContextDelete(), RevalidateCachedQuery(), SaveCachedPlan(), SPI_keepplan(), and TransferExpandedObject().

318 {
320  AssertArg(context != new_parent);
321 
322  /* Fast path if it's got correct parent already */
323  if (new_parent == context->parent)
324  return;
325 
326  /* Delink from existing parent, if any */
327  if (context->parent)
328  {
329  MemoryContext parent = context->parent;
330 
331  if (context->prevchild != NULL)
332  context->prevchild->nextchild = context->nextchild;
333  else
334  {
335  Assert(parent->firstchild == context);
336  parent->firstchild = context->nextchild;
337  }
338 
339  if (context->nextchild != NULL)
340  context->nextchild->prevchild = context->prevchild;
341  }
342 
343  /* And relink */
344  if (new_parent)
345  {
346  AssertArg(MemoryContextIsValid(new_parent));
347  context->parent = new_parent;
348  context->prevchild = NULL;
349  context->nextchild = new_parent->firstchild;
350  if (new_parent->firstchild != NULL)
351  new_parent->firstchild->prevchild = context;
352  new_parent->firstchild = context;
353  }
354  else
355  {
356  context->parent = NULL;
357  context->prevchild = NULL;
358  context->nextchild = NULL;
359  }
360 }
MemoryContext firstchild
Definition: memnodes.h:81
MemoryContext prevchild
Definition: memnodes.h:82
#define AssertArg(condition)
Definition: c.h:672
#define MemoryContextIsValid(context)
Definition: memnodes.h:97
#define Assert(condition)
Definition: c.h:670
MemoryContext parent
Definition: memnodes.h:80
MemoryContext nextchild
Definition: memnodes.h:83

◆ MemoryContextStats()

void MemoryContextStats ( MemoryContext  context)

Definition at line 437 of file mcxt.c.

References MemoryContextStatsDetail().

Referenced by AllocSetContextCreate(), finish_xact_command(), MemoryContextAlloc(), MemoryContextAllocExtended(), MemoryContextAllocHuge(), MemoryContextAllocZero(), MemoryContextAllocZeroAligned(), palloc(), palloc0(), palloc_extended(), repalloc(), and repalloc_huge().

438 {
439  /* A hard-wired limit on the number of children is usually good enough */
440  MemoryContextStatsDetail(context, 100);
441 }
void MemoryContextStatsDetail(MemoryContext context, int max_children)
Definition: mcxt.c:449

◆ MemoryContextStatsDetail()

void MemoryContextStatsDetail ( MemoryContext  context,
int  max_children 
)

Definition at line 449 of file mcxt.c.

References MemoryContextCounters::freechunks, MemoryContextCounters::freespace, MemoryContextStatsInternal(), MemoryContextCounters::nblocks, and MemoryContextCounters::totalspace.

Referenced by MemoryContextStats().

450 {
451  MemoryContextCounters grand_totals;
452 
453  memset(&grand_totals, 0, sizeof(grand_totals));
454 
455  MemoryContextStatsInternal(context, 0, true, max_children, &grand_totals);
456 
457  fprintf(stderr,
458  "Grand total: %zu bytes in %zd blocks; %zu free (%zd chunks); %zu used\n",
459  grand_totals.totalspace, grand_totals.nblocks,
460  grand_totals.freespace, grand_totals.freechunks,
461  grand_totals.totalspace - grand_totals.freespace);
462 }
static void MemoryContextStatsInternal(MemoryContext context, int level, bool print, int max_children, MemoryContextCounters *totals)
Definition: mcxt.c:472

◆ SlabContextCreate()

MemoryContext SlabContextCreate ( MemoryContext  parent,
const char *  name,
Size  blockSize,
Size  chunkSize 
)

Definition at line 183 of file slab.c.

References Assert, SlabContext::blockSize, SlabContext::chunkSize, SlabContext::chunksPerBlock, elog, ERROR, SlabContext::freelist, SlabContext::fullChunkSize, MAXALIGN, MemoryContextCreate(), SlabContext::minFreeChunks, name, SlabContext::nblocks, offsetof, SlabMethods, StaticAssertStmt, and T_SlabContext.

Referenced by GetMemoryChunkContext(), and ReorderBufferAllocate().

187 {
188  int chunksPerBlock;
189  Size fullChunkSize;
190  Size freelistSize;
191  SlabContext *slab;
192 
194  MAXALIGN(sizeof(SlabChunk)),
195  "padding calculation in SlabChunk is wrong");
196 
197  /* Make sure the linked list node fits inside a freed chunk */
198  if (chunkSize < sizeof(int))
199  chunkSize = sizeof(int);
200 
201  /* chunk, including SLAB header (both addresses nicely aligned) */
202  fullChunkSize = MAXALIGN(sizeof(SlabChunk) + MAXALIGN(chunkSize));
203 
204  /* Make sure the block can store at least one chunk. */
205  if (blockSize - sizeof(SlabBlock) < fullChunkSize)
206  elog(ERROR, "block size %zu for slab is too small for %zu chunks",
207  blockSize, chunkSize);
208 
209  /* Compute maximum number of chunks per block */
210  chunksPerBlock = (blockSize - sizeof(SlabBlock)) / fullChunkSize;
211 
212  /* The freelist starts with 0, ends with chunksPerBlock. */
213  freelistSize = sizeof(dlist_head) * (chunksPerBlock + 1);
214 
215  /* if we can't fit at least one chunk into the block, we're hosed */
216  Assert(chunksPerBlock > 0);
217 
218  /* make sure the chunks actually fit on the block */
219  Assert((fullChunkSize * chunksPerBlock) + sizeof(SlabBlock) <= blockSize);
220 
221  /* Do the type-independent part of context creation */
222  slab = (SlabContext *)
224  (offsetof(SlabContext, freelist) + freelistSize),
225  &SlabMethods,
226  parent,
227  name);
228 
229  slab->blockSize = blockSize;
230  slab->chunkSize = chunkSize;
231  slab->fullChunkSize = fullChunkSize;
232  slab->chunksPerBlock = chunksPerBlock;
233  slab->nblocks = 0;
234  slab->minFreeChunks = 0;
235 
236  return (MemoryContext) slab;
237 }
int nblocks
Definition: slab.c:72
Size blockSize
Definition: slab.c:69
struct dlist_head dlist_head
static MemoryContextMethods SlabMethods
Definition: slab.c:137
Size chunkSize
Definition: slab.c:67
#define StaticAssertStmt(condition, errmessage)
Definition: c.h:753
#define ERROR
Definition: elog.h:43
int chunksPerBlock
Definition: slab.c:70
Size fullChunkSize
Definition: slab.c:68
MemoryContext MemoryContextCreate(NodeTag tag, Size size, MemoryContextMethods *methods, MemoryContext parent, const char *name)
Definition: mcxt.c:639
#define Assert(condition)
Definition: c.h:670
struct SlabBlock SlabBlock
size_t Size
Definition: c.h:404
#define MAXALIGN(LEN)
Definition: c.h:623
const char * name
Definition: encode.c:521
Definition: slab.c:85
int minFreeChunks
Definition: slab.c:71
#define elog
Definition: elog.h:219
#define offsetof(type, field)
Definition: c.h:593
Definition: slab.c:96

Variable Documentation

◆ CacheMemoryContext

PGDLLIMPORT MemoryContext CacheMemoryContext

Definition at line 46 of file mcxt.c.

Referenced by _SPI_save_plan(), AllocateRelationDesc(), assign_record_type_typmod(), AttrDefaultFetch(), BuildEventTriggerCache(), BuildHardcodedDescriptor(), CatalogCacheCreateEntry(), CatalogCacheInitializeCache(), CheckConstraintFetch(), CreateCacheMemoryContext(), ensure_record_cache_typmod_slot_exists(), generate_partition_qual(), get_attribute_options(), get_rel_sync_entry(), get_tablespace(), GetCachedPlan(), GetConnection(), GetFdwRoutineForRelation(), GetRelationPublicationActions(), init_ts_config_cache(), InitCatCache(), InitializeAttoptCache(), InitializeRelfilenodeMap(), InitializeTableSpaceCache(), load_domaintype_info(), load_enum_cache_data(), load_rangetype_info(), load_relcache_init_file(), logicalrep_relmap_init(), lookup_ts_config_cache(), lookup_ts_dictionary_cache(), lookup_ts_parser_cache(), lookup_type_cache(), LookupOpclassInfo(), pgoutput_startup(), process_syncing_tables_for_apply(), register_on_commit_action(), RehashCatCache(), RelationBuildLocalRelation(), RelationBuildPartitionDesc(), RelationBuildPartitionKey(), RelationBuildRowSecurity(), RelationBuildRuleLock(), RelationBuildTriggers(), RelationBuildTupleDesc(), RelationCacheInitialize(), RelationCacheInitializePhase2(), RelationCacheInitializePhase3(), RelationGetFKeyList(), RelationGetIndexAttrBitmap(), RelationGetIndexList(), RelationGetStatExtList(), RelationInitIndexAccessInfo(), RelationParseRelOptions(), RelationSetIndexList(), RememberToFreeTupleDescAtEOX(), SaveCachedPlan(), SearchCatCacheList(), and SPI_keepplan().

◆ CurTransactionContext

◆ ErrorContext

◆ MessageContext

◆ PortalContext

◆ PostmasterContext

◆ TopMemoryContext

PGDLLIMPORT MemoryContext TopMemoryContext

Definition at line 43 of file mcxt.c.

Referenced by _PG_init(), add_reloption(), add_string_reloption(), allocate_reloption(), AllocateAttribute(), AllocSetContextCreate(), ApplyLauncherMain(), ApplyWorkerMain(), AtAbort_Memory(), AtCleanup_Memory(), AtCommit_Memory(), AtStart_Memory(), AttachSession(), AutoVacLauncherMain(), BackendRun(), BackgroundWriterMain(), be_tls_open_server(), cache_single_time(), CheckpointerMain(), compile_plperl_function(), compile_pltcl_function(), ConditionVariablePrepareToSleep(), ConvertTriggerToFK(), CreateCacheMemoryContext(), dblink_connect(), dblink_init(), do_autovacuum(), do_compile(), do_start_bgworker(), dsm_create_descriptor(), dsm_impl_sysv(), EnablePortalManager(), EventTriggerBeginCompleteQuery(), Exec_ListenCommit(), finish_xact_command(), get_tabstat_entry(), GetLocalBufferStorage(), GetLockConflicts(), GetSessionDsmHandle(), HandleParallelMessages(), hash_create(), InitDeadLockChecking(), initialize_reloptions(), InitializeParallelDSM(), InitializeSearchPath(), InitializeSession(), InitXLogInsert(), LockAcquireExtended(), LogicalRepApplyLoop(), mdinit(), MemoryContextInit(), mxid_to_string(), on_dsm_detach(), PageSetChecksumCopy(), ParallelWorkerMain(), PerformAuthentication(), pg_newlocale_from_collation(), pg_start_backup(), pgstat_setup_memcxt(), plperl_spi_prepare(), plpgsql_estate_setup(), plpython_inline_handler(), pltcl_SPI_prepare(), PLy_cursor_plan(), PLy_cursor_query(), PLy_procedure_create(), PLy_spi_execute_fetch_result(), PLy_spi_prepare(), PostgresMain(), PostmasterMain(), pq_init(), PrepareClientEncoding(), ProcessStartupPacket(), PushOverrideSearchPath(), px_find_cipher(), px_find_digest(), recomputeNamespacePath(), register_label_provider(), RegisterLWLockTranches(), RegisterResourceReleaseCallback(), RegisterSubXactCallback(), RegisterXactCallback(), regress_putenv(), RelationCreateStorage(), RelationDropStorage(), RequestNamedLWLockTranche(), ResourceArrayEnlarge(), ResourceOwnerCreate(), ri_HashCompareOp(), roles_has_privs_of(), roles_is_member_of(), sepgsql_avc_init(), sepgsql_xact_callback(), SetDatabasePath(), SharedRecordTypmodRegistryAttach(), SharedRecordTypmodRegistryInit(), StartChildProcess(), WalWriterMain(), XLOGShmemInit(), and xml_is_document().

◆ TopTransactionContext