Header And Logo

PostgreSQL
| The world's most advanced open source database.

Data Structures | Defines | Typedefs | Functions | Variables

memutils.h File Reference

#include "nodes/memnodes.h"
Include dependency graph for memutils.h:

Go to the source code of this file.

Data Structures

struct  StandardChunkHeader

Defines

#define MaxAllocSize   ((Size) 0x3fffffff)
#define AllocSizeIsValid(size)   ((Size) (size) <= MaxAllocSize)
#define STANDARDCHUNKHEADERSIZE   MAXALIGN(sizeof(StandardChunkHeader))
#define ALLOCSET_DEFAULT_MINSIZE   0
#define ALLOCSET_DEFAULT_INITSIZE   (8 * 1024)
#define ALLOCSET_DEFAULT_MAXSIZE   (8 * 1024 * 1024)
#define ALLOCSET_SMALL_MINSIZE   0
#define ALLOCSET_SMALL_INITSIZE   (1 * 1024)
#define ALLOCSET_SMALL_MAXSIZE   (8 * 1024)

Typedefs

typedef struct StandardChunkHeader StandardChunkHeader

Functions

void MemoryContextInit (void)
void MemoryContextReset (MemoryContext context)
void MemoryContextDelete (MemoryContext context)
void MemoryContextResetChildren (MemoryContext context)
void MemoryContextDeleteChildren (MemoryContext context)
void MemoryContextResetAndDeleteChildren (MemoryContext context)
void MemoryContextSetParent (MemoryContext context, MemoryContext new_parent)
Size GetMemoryChunkSpace (void *pointer)
MemoryContext GetMemoryChunkContext (void *pointer)
MemoryContext MemoryContextGetParent (MemoryContext context)
bool MemoryContextIsEmpty (MemoryContext context)
void MemoryContextStats (MemoryContext context)
bool MemoryContextContains (MemoryContext context, 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)

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

Define Documentation

#define ALLOCSET_DEFAULT_INITSIZE   (8 * 1024)

Definition at line 133 of file memutils.h.

Referenced by accumArrayResult(), afterTriggerAddEvent(), afterTriggerInvokeEvents(), AtStart_Memory(), AtSubStart_Memory(), AutoVacLauncherMain(), BackgroundWriterMain(), begin_heap_rewrite(), BeginCopy(), btvacuumscan(), BuildEventTriggerCache(), CheckpointerMain(), cluster(), compute_index_stats(), CopyTo(), CreateCacheMemoryContext(), CreateExecutorState(), CreateExprContext(), CreateStandaloneExprContext(), createTempGistContext(), createTrgmNFA(), do_analyze_rel(), do_autovacuum(), do_compile(), do_start_worker(), each_worker(), EnablePortalManager(), EventTriggerBeginCompleteQuery(), EventTriggerInvoke(), exec_parse_message(), exec_replication_command(), ExecHashTableCreate(), ExecInitAgg(), ExecInitRecursiveUnion(), ExecInitSetOp(), ExecInitSubPlan(), ExecInitUnique(), ExecInitWindowAgg(), file_acquire_sample_rows(), geqo_eval(), GetLocalBufferStorage(), gin_xlog_startup(), ginbeginscan(), ginbuild(), gininsert(), ginInsertCleanup(), gistrescan(), hash_create(), index_register(), init_sql_fcache(), initGISTstate(), inline_function(), inline_set_returning_function(), json_array_elements(), mdinit(), NIStartBuild(), plperl_return_next(), plperl_spi_prepare(), plpgsql_compile_inline(), PLy_push_execution_context(), PortalCreateHoldStore(), postgresBeginForeignScan(), PostgresMain(), PostmasterMain(), rebuild_database_list(), ReindexDatabase(), ResetUnloggedRelations(), sepgsql_avc_init(), spg_xlog_startup(), spgbeginscan(), spgbuild(), spginsert(), SPI_connect(), spi_dest_startup(), storeRow(), tokenize_file(), tuplesort_begin_common(), vacuum(), and WalWriterMain().

#define ALLOCSET_DEFAULT_MAXSIZE   (8 * 1024 * 1024)

Definition at line 134 of file memutils.h.

Referenced by accumArrayResult(), afterTriggerAddEvent(), afterTriggerInvokeEvents(), AtStart_Memory(), AtSubStart_Memory(), AutoVacLauncherMain(), BackgroundWriterMain(), begin_heap_rewrite(), BeginCopy(), btvacuumscan(), BuildCachedPlan(), BuildEventTriggerCache(), CheckpointerMain(), cluster(), CompleteCachedPlan(), compute_index_stats(), CopyCachedPlan(), CopyTo(), CreateCachedPlan(), CreateCacheMemoryContext(), CreateExecutorState(), CreateExprContext(), CreateStandaloneExprContext(), createTempGistContext(), createTrgmNFA(), do_analyze_rel(), do_autovacuum(), do_compile(), do_start_worker(), each_worker(), EnablePortalManager(), EventTriggerBeginCompleteQuery(), EventTriggerInvoke(), exec_parse_message(), exec_replication_command(), ExecHashTableCreate(), ExecInitAgg(), ExecInitRecursiveUnion(), ExecInitSetOp(), ExecInitSubPlan(), ExecInitUnique(), ExecInitWindowAgg(), file_acquire_sample_rows(), geqo_eval(), GetLocalBufferStorage(), gin_xlog_startup(), ginbeginscan(), ginbuild(), gininsert(), ginInsertCleanup(), gistrescan(), hash_create(), index_register(), init_sql_fcache(), initGISTstate(), inline_function(), inline_set_returning_function(), json_array_elements(), load_hba(), load_ident(), mdinit(), NIStartBuild(), plperl_return_next(), plperl_spi_prepare(), plpgsql_compile_inline(), PLy_push_execution_context(), PortalCreateHoldStore(), postgresBeginForeignScan(), PostgresMain(), PostmasterMain(), rebuild_database_list(), ReindexDatabase(), ResetUnloggedRelations(), RevalidateCachedQuery(), sepgsql_avc_init(), spg_xlog_startup(), spgbeginscan(), spgbuild(), spginsert(), SPI_connect(), spi_dest_startup(), storeRow(), tokenize_file(), tuplesort_begin_common(), vacuum(), and WalWriterMain().

#define ALLOCSET_DEFAULT_MINSIZE   0

Definition at line 132 of file memutils.h.

Referenced by accumArrayResult(), afterTriggerAddEvent(), afterTriggerInvokeEvents(), AtStart_Memory(), AtSubStart_Memory(), AutoVacLauncherMain(), BackgroundWriterMain(), begin_heap_rewrite(), BeginCopy(), btvacuumscan(), BuildEventTriggerCache(), CheckpointerMain(), cluster(), compute_index_stats(), CopyTo(), CreateCacheMemoryContext(), CreateExecutorState(), CreateExprContext(), CreateStandaloneExprContext(), createTempGistContext(), createTrgmNFA(), do_analyze_rel(), do_autovacuum(), do_compile(), do_start_worker(), each_worker(), EnablePortalManager(), EventTriggerBeginCompleteQuery(), EventTriggerInvoke(), exec_parse_message(), exec_replication_command(), ExecHashTableCreate(), ExecInitAgg(), ExecInitRecursiveUnion(), ExecInitSetOp(), ExecInitSubPlan(), ExecInitUnique(), ExecInitWindowAgg(), file_acquire_sample_rows(), geqo_eval(), GetLocalBufferStorage(), gin_xlog_startup(), ginbeginscan(), ginbuild(), gininsert(), ginInsertCleanup(), gistrescan(), hash_create(), index_register(), init_sql_fcache(), initGISTstate(), inline_function(), inline_set_returning_function(), json_array_elements(), load_hba(), load_ident(), mdinit(), NIStartBuild(), plperl_return_next(), plperl_spi_prepare(), plpgsql_compile_inline(), PLy_push_execution_context(), PortalCreateHoldStore(), postgresBeginForeignScan(), PostgresMain(), PostmasterMain(), rebuild_database_list(), ReindexDatabase(), ResetUnloggedRelations(), sepgsql_avc_init(), spg_xlog_startup(), spgbeginscan(), spgbuild(), spginsert(), SPI_connect(), spi_dest_startup(), storeRow(), tokenize_file(), tuplesort_begin_common(), vacuum(), and WalWriterMain().

#define ALLOCSET_SMALL_INITSIZE   (1 * 1024)
#define ALLOCSET_SMALL_MAXSIZE   (8 * 1024)
#define ALLOCSET_SMALL_MINSIZE   0
#define AllocSizeIsValid (   size  )     ((Size) (size) <= MaxAllocSize)
#define MaxAllocSize   ((Size) 0x3fffffff)
#define STANDARDCHUNKHEADERSIZE   MAXALIGN(sizeof(StandardChunkHeader))

Definition at line 63 of file memutils.h.


Typedef Documentation


Function Documentation

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

Definition at line 353 of file aset.c.

References ALLOC_BLOCKHDRSZ, ALLOC_CHUNK_FRACTION, ALLOC_CHUNKHDRSZ, AllocSetContext::allocChunkLimit, AllocBlockData::aset, AllocSetContext::blocks, AllocBlockData::endptr, ereport, errcode(), errdetail(), errmsg(), ERROR, AllocBlockData::freeptr, AllocSetContext::initBlockSize, AllocSetContext::keeper, malloc, MAXALIGN, AllocSetContext::maxBlockSize, MemoryContextCreate(), MemoryContextStats(), AllocBlockData::next, AllocSetContext::nextBlockSize, NULL, T_AllocSetContext, and TopMemoryContext.

Referenced by _bt_preprocess_array_keys(), _SPI_make_plan_non_temp(), _SPI_save_plan(), accumArrayResult(), afterTriggerAddEvent(), afterTriggerInvokeEvents(), AtStart_Memory(), AtSubStart_Memory(), AutoVacLauncherMain(), BackgroundWriterMain(), begin_heap_rewrite(), BeginCopy(), btvacuumscan(), BuildCachedPlan(), BuildEventTriggerCache(), CheckpointerMain(), cluster(), CompleteCachedPlan(), compute_index_stats(), CopyCachedPlan(), CopyTo(), CreateCachedPlan(), CreateCacheMemoryContext(), CreateExecutorState(), CreateExprContext(), CreatePortal(), CreateStandaloneExprContext(), createTempGistContext(), createTrgmNFA(), do_analyze_rel(), do_autovacuum(), do_compile(), do_start_worker(), each_worker(), EnablePortalManager(), EventTriggerBeginCompleteQuery(), EventTriggerInvoke(), exec_parse_message(), exec_replication_command(), ExecHashTableCreate(), ExecInitAgg(), ExecInitRecursiveUnion(), ExecInitSetOp(), ExecInitSubPlan(), ExecInitUnique(), ExecInitWindowAgg(), file_acquire_sample_rows(), geqo_eval(), GetLocalBufferStorage(), gin_xlog_startup(), ginbeginscan(), ginbuild(), gininsert(), ginInsertCleanup(), gistrescan(), hash_create(), index_register(), init_MultiFuncCall(), init_sql_fcache(), initGISTstate(), inline_function(), inline_set_returning_function(), json_array_elements(), load_hba(), load_ident(), load_relcache_init_file(), load_tzoffsets(), lookup_ts_dictionary_cache(), mdinit(), MemoryContextInit(), mXactCachePut(), NIStartBuild(), pgstat_setup_memcxt(), plperl_return_next(), plperl_spi_prepare(), plpgsql_compile_inline(), PLy_push_execution_context(), PortalCreateHoldStore(), postgresAcquireSampleRowsFunc(), postgresBeginForeignModify(), postgresBeginForeignScan(), PostgresMain(), PostmasterMain(), rebuild_database_list(), ReindexDatabase(), RelationBuildRuleLock(), RelationInitIndexAccessInfo(), ResetUnloggedRelations(), RevalidateCachedQuery(), sepgsql_avc_init(), spg_xlog_startup(), spgbeginscan(), spgbuild(), spginsert(), SPI_connect(), spi_dest_startup(), storeRow(), tokenize_file(), tuplesort_begin_common(), vacuum(), and WalWriterMain().

{
    AllocSet    context;

    /* Do the type-independent part of context creation */
    context = (AllocSet) MemoryContextCreate(T_AllocSetContext,
                                             sizeof(AllocSetContext),
                                             &AllocSetMethods,
                                             parent,
                                             name);

    /*
     * Make sure alloc parameters are reasonable, and save them.
     *
     * We somewhat arbitrarily enforce a minimum 1K block size.
     */
    initBlockSize = MAXALIGN(initBlockSize);
    if (initBlockSize < 1024)
        initBlockSize = 1024;
    maxBlockSize = MAXALIGN(maxBlockSize);
    if (maxBlockSize < initBlockSize)
        maxBlockSize = initBlockSize;
    context->initBlockSize = initBlockSize;
    context->maxBlockSize = maxBlockSize;
    context->nextBlockSize = initBlockSize;

    /*
     * Compute the allocation chunk size limit for this context.  It can't be
     * more than ALLOC_CHUNK_LIMIT because of the fixed number of freelists.
     * If maxBlockSize is small then requests exceeding the maxBlockSize, or
     * even a significant fraction of it, should be treated as large chunks
     * too.  For the typical case of maxBlockSize a power of 2, the chunk size
     * limit will be at most 1/8th maxBlockSize, so that given a stream of
     * requests that are all the maximum chunk size we will waste at most
     * 1/8th of the allocated space.
     *
     * We have to have allocChunkLimit a power of two, because the requested
     * and actually-allocated sizes of any chunk must be on the same side of
     * the limit, else we get confused about whether the chunk is "big".
     */
    context->allocChunkLimit = ALLOC_CHUNK_LIMIT;
    while ((Size) (context->allocChunkLimit + ALLOC_CHUNKHDRSZ) >
           (Size) ((maxBlockSize - ALLOC_BLOCKHDRSZ) / ALLOC_CHUNK_FRACTION))
        context->allocChunkLimit >>= 1;

    /*
     * Grab always-allocated space, if requested
     */
    if (minContextSize > ALLOC_BLOCKHDRSZ + ALLOC_CHUNKHDRSZ)
    {
        Size        blksize = MAXALIGN(minContextSize);
        AllocBlock  block;

        block = (AllocBlock) malloc(blksize);
        if (block == NULL)
        {
            MemoryContextStats(TopMemoryContext);
            ereport(ERROR,
                    (errcode(ERRCODE_OUT_OF_MEMORY),
                     errmsg("out of memory"),
                     errdetail("Failed while creating memory context \"%s\".",
                               name)));
        }
        block->aset = context;
        block->freeptr = ((char *) block) + ALLOC_BLOCKHDRSZ;
        block->endptr = ((char *) block) + blksize;
        block->next = context->blocks;
        context->blocks = block;
        /* Mark block as not to be released at reset time */
        context->keeper = block;
    }

    return (MemoryContext) context;
}

MemoryContext GetMemoryChunkContext ( void *  pointer  ) 

Definition at line 325 of file mcxt.c.

References Assert, AssertArg, StandardChunkHeader::context, MAXALIGN, MemoryContextIsValid, and NULL.

Referenced by mark_dummy_rel().

{
    StandardChunkHeader *header;

    /*
     * Try to detect bogus pointers handed to us, poorly though we can.
     * Presumably, a pointer that isn't MAXALIGNED isn't pointing at an
     * allocated chunk.
     */
    Assert(pointer != NULL);
    Assert(pointer == (void *) MAXALIGN(pointer));

    /*
     * OK, it's probably safe to look at the chunk header.
     */
    header = (StandardChunkHeader *)
        ((char *) pointer - STANDARDCHUNKHEADERSIZE);

    AssertArg(MemoryContextIsValid(header->context));

    return header->context;
}

Size GetMemoryChunkSpace ( void *  pointer  ) 

Definition at line 295 of file mcxt.c.

References Assert, AssertArg, StandardChunkHeader::context, MemoryContextMethods::get_chunk_space, MAXALIGN, MemoryContextIsValid, MemoryContextData::methods, and NULL.

Referenced by copytup_cluster(), copytup_heap(), copytup_index(), free_sort_tuple(), getDatumCopy(), ginAllocEntryAccumulator(), ginCombineData(), ginInsertBAEntry(), grow_memtuples(), inittapes(), readtup_cluster(), readtup_datum(), readtup_heap(), readtup_index(), tuplesort_begin_common(), tuplesort_gettuple_common(), tuplesort_putdatum(), tuplestore_begin_common(), tuplestore_clear(), tuplestore_puttupleslot(), tuplestore_putvalues(), tuplestore_trim(), writetup_cluster(), writetup_datum(), writetup_heap(), and writetup_index().

{
    StandardChunkHeader *header;

    /*
     * Try to detect bogus pointers handed to us, poorly though we can.
     * Presumably, a pointer that isn't MAXALIGNED isn't pointing at an
     * allocated chunk.
     */
    Assert(pointer != NULL);
    Assert(pointer == (void *) MAXALIGN(pointer));

    /*
     * OK, it's probably safe to look at the chunk header.
     */
    header = (StandardChunkHeader *)
        ((char *) pointer - STANDARDCHUNKHEADERSIZE);

    AssertArg(MemoryContextIsValid(header->context));

    return (*header->context->methods->get_chunk_space) (header->context,
                                                         pointer);
}

bool MemoryContextContains ( MemoryContext  context,
void *  pointer 
)

Definition at line 436 of file mcxt.c.

References AllocSizeIsValid, StandardChunkHeader::context, MAXALIGN, NULL, and StandardChunkHeader::size.

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

{
    StandardChunkHeader *header;

    /*
     * Try to detect bogus pointers handed to us, poorly though we can.
     * Presumably, a pointer that isn't MAXALIGNED isn't pointing at an
     * allocated chunk.
     */
    if (pointer == NULL || pointer != (void *) MAXALIGN(pointer))
        return false;

    /*
     * OK, it's probably safe to look at the chunk header.
     */
    header = (StandardChunkHeader *)
        ((char *) pointer - STANDARDCHUNKHEADERSIZE);

    /*
     * If the context link doesn't match then we certainly have a non-member
     * chunk.  Also check for a reasonable-looking size as extra guard against
     * being fooled by bogus pointers.
     */
    if (header->context == context && AllocSizeIsValid(header->size))
        return true;
    return false;
}

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

Definition at line 513 of file mcxt.c.

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

Referenced by AllocSetContextCreate().

{
    MemoryContext node;
    Size        needed = size + strlen(name) + 1;

    /* Get space for node and name */
    if (TopMemoryContext != NULL)
    {
        /* Normal case: allocate the node in TopMemoryContext */
        node = (MemoryContext) MemoryContextAlloc(TopMemoryContext,
                                                  needed);
    }
    else
    {
        /* Special case for startup: use good ol' malloc */
        node = (MemoryContext) malloc(needed);
        Assert(node != NULL);
    }

    /* Initialize the node as best we can */
    MemSet(node, 0, size);
    node->type = tag;
    node->methods = methods;
    node->parent = NULL;        /* for the moment */
    node->firstchild = NULL;
    node->nextchild = NULL;
    node->isReset = true;
    node->name = ((char *) node) + size;
    strcpy(node->name, name);

    /* Type-specific routine finishes any other essential initialization */
    (*node->methods->init) (node);

    /* OK to link node to parent (if any) */
    /* Could use MemoryContextSetParent here, but doesn't seem worthwhile */
    if (parent)
    {
        node->parent = parent;
        node->nextchild = parent->firstchild;
        parent->firstchild = node;
    }

    /* Return to type-specific creation routine to finish up */
    return node;
}

void MemoryContextDelete ( MemoryContext  context  ) 

Definition at line 169 of file mcxt.c.

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

Referenced by AfterTriggerEndXact(), afterTriggerInvokeEvents(), AtCleanup_Memory(), AtCommit_Memory(), AtEOSubXact_SPI(), AtEOXact_LargeObject(), AtSubCleanup_Memory(), AtSubCommit_Memory(), btendscan(), btvacuumscan(), cluster(), compute_index_stats(), CopyTo(), createTrgmNFA(), do_analyze_rel(), do_start_worker(), DropCachedPlan(), end_heap_rewrite(), EndCopy(), EventTriggerEndCompleteQuery(), EventTriggerInvoke(), exec_replication_command(), ExecEndAgg(), ExecEndRecursiveUnion(), ExecEndSetOp(), ExecEndUnique(), ExecEndWindowAgg(), ExecHashTableDestroy(), file_acquire_sample_rows(), fmgr_sql(), FreeExecutorState(), FreeExprContext(), freeGISTstate(), geqo_eval(), gin_xlog_cleanup(), ginbuild(), ginendscan(), gininsert(), ginInsertCleanup(), gist_xlog_cleanup(), gistbuild(), hash_destroy(), inline_function(), inline_set_returning_function(), load_hba(), load_ident(), load_tzoffsets(), makeMdArrayResult(), MemoryContextDeleteChildren(), NIFinishBuild(), pgstat_clear_snapshot(), plperl_spi_freeplan(), plperl_spi_prepare(), plpgsql_free_function_memory(), PLy_pop_execution_context(), PortalDrop(), PostgresMain(), rebuild_database_list(), ReindexDatabase(), RelationBuildRuleLock(), RelationDestroyRelation(), ReleaseCachedPlan(), ResetUnloggedRelations(), RevalidateCachedQuery(), shutdown_MultiFuncCall(), spg_xlog_cleanup(), spgbuild(), spgendscan(), spginsert(), SPI_finish(), SPI_freeplan(), SPI_freetuptable(), StartChildProcess(), tokenize_inc_file(), tuplesort_end(), and vacuum().

{
    AssertArg(MemoryContextIsValid(context));
    /* We had better not be deleting TopMemoryContext ... */
    Assert(context != TopMemoryContext);
    /* And not CurrentMemoryContext, either */
    Assert(context != CurrentMemoryContext);

    MemoryContextDeleteChildren(context);

    /*
     * We delink the context from its parent before deleting it, so that if
     * there's an error we won't have deleted/busted contexts still attached
     * to the context tree.  Better a leak than a crash.
     */
    MemoryContextSetParent(context, NULL);

    (*context->methods->delete_context) (context);
    pfree(context);
}

void MemoryContextDeleteChildren ( MemoryContext  context  ) 

Definition at line 196 of file mcxt.c.

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

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

{
    AssertArg(MemoryContextIsValid(context));

    /*
     * MemoryContextDelete will delink the child from me, so just iterate as
     * long as there is a child.
     */
    while (context->firstchild != NULL)
        MemoryContextDelete(context->firstchild);
}

MemoryContext MemoryContextGetParent ( MemoryContext  context  ) 

Definition at line 353 of file mcxt.c.

References AssertArg, MemoryContextIsValid, and MemoryContextData::parent.

Referenced by GetCachedPlan().

{
    AssertArg(MemoryContextIsValid(context));

    return context->parent;
}

void MemoryContextInit ( void   ) 

Definition at line 79 of file mcxt.c.

References AllocSetContextCreate(), AssertState, and NULL.

Referenced by AuxiliaryProcessMain(), PostgresMain(), and PostmasterMain().

{
    AssertState(TopMemoryContext == NULL);

    /*
     * Initialize TopMemoryContext as an AllocSetContext with slow growth rate
     * --- we don't really expect much to be allocated in it.
     *
     * (There is special-case code in MemoryContextCreate() for this call.)
     */
    TopMemoryContext = AllocSetContextCreate((MemoryContext) NULL,
                                             "TopMemoryContext",
                                             0,
                                             8 * 1024,
                                             8 * 1024);

    /*
     * Not having any other place to point CurrentMemoryContext, make it point
     * to TopMemoryContext.  Caller should change this soon!
     */
    CurrentMemoryContext = TopMemoryContext;

    /*
     * Initialize ErrorContext as an AllocSetContext with slow growth rate ---
     * we don't really expect much to be allocated in it. More to the point,
     * require it to contain at least 8K at all times. This is the only case
     * where retained memory in a context is *essential* --- we want to be
     * sure ErrorContext still has some memory even if we've run out
     * elsewhere!
     */
    ErrorContext = AllocSetContextCreate(TopMemoryContext,
                                         "ErrorContext",
                                         8 * 1024,
                                         8 * 1024,
                                         8 * 1024);
}

bool MemoryContextIsEmpty ( MemoryContext  context  ) 

Definition at line 365 of file mcxt.c.

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

Referenced by AtSubCommit_Memory().

{
    AssertArg(MemoryContextIsValid(context));

    /*
     * For now, we consider a memory context nonempty if it has any children;
     * perhaps this should be changed later.
     */
    if (context->firstchild != NULL)
        return false;
    /* Otherwise use the type-specific inquiry */
    return (*context->methods->is_empty) (context);
}

void MemoryContextReset ( MemoryContext  context  ) 

Definition at line 125 of file mcxt.c.

References AssertArg, MemoryContextData::firstchild, MemoryContextData::isReset, MemoryContextIsValid, MemoryContextResetChildren(), MemoryContextData::methods, NULL, and MemoryContextMethods::reset.

Referenced by _bt_preprocess_array_keys(), AfterTriggerExecute(), btvacuumpage(), buildSubPlanHash(), CopyOneRowTo(), each_object_field_end(), elements_array_element_end(), errstart(), EventTriggerInvoke(), ExecHashTableReset(), ExecRecursiveUnion(), execTuplesMatch(), execTuplesUnequal(), fetch_more_data(), file_acquire_sample_rows(), gin_redo(), gin_xlog_cleanup(), ginBuildCallback(), ginHeapTupleBulkInsert(), ginInsertCleanup(), gist_redo(), gistBuildCallback(), gistProcessEmptyingQueue(), gistrescan(), gistScanPage(), IndexBuildHeapScan(), IndexCheckExclusion(), keyGetItem(), load_hba(), load_ident(), make_tuple_from_result_row(), MemoryContextResetAndDeleteChildren(), MemoryContextResetChildren(), plperl_return_next(), PLyDict_FromTuple(), postgresExecForeignDelete(), postgresExecForeignInsert(), postgresExecForeignUpdate(), process_ordered_aggregate_multi(), process_ordered_aggregate_single(), ReScanExprContext(), scanPendingInsert(), sepgsql_avc_reset(), setop_fill_hash_table(), spg_redo(), spgistBuildCallback(), spgWalk(), storeRow(), and validate_index_heapscan().

{
    AssertArg(MemoryContextIsValid(context));

    /* save a function call in common case where there are no children */
    if (context->firstchild != NULL)
        MemoryContextResetChildren(context);

    /* Nothing to do if no pallocs since startup or last reset */
    if (!context->isReset)
    {
        (*context->methods->reset) (context);
        context->isReset = true;
    }
}

void MemoryContextResetAndDeleteChildren ( MemoryContext  context  ) 
void MemoryContextResetChildren ( MemoryContext  context  ) 

Definition at line 148 of file mcxt.c.

References AssertArg, MemoryContextData::firstchild, MemoryContextIsValid, MemoryContextReset(), MemoryContextData::nextchild, and NULL.

Referenced by MemoryContextReset().

{
    MemoryContext child;

    AssertArg(MemoryContextIsValid(context));

    for (child = context->firstchild; child != NULL; child = child->nextchild)
        MemoryContextReset(child);
}

void MemoryContextSetParent ( MemoryContext  context,
MemoryContext  new_parent 
)

Definition at line 244 of file mcxt.c.

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

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

{
    AssertArg(MemoryContextIsValid(context));
    AssertArg(context != new_parent);

    /* Delink from existing parent, if any */
    if (context->parent)
    {
        MemoryContext parent = context->parent;

        if (context == parent->firstchild)
            parent->firstchild = context->nextchild;
        else
        {
            MemoryContext child;

            for (child = parent->firstchild; child; child = child->nextchild)
            {
                if (context == child->nextchild)
                {
                    child->nextchild = context->nextchild;
                    break;
                }
            }
        }
    }

    /* And relink */
    if (new_parent)
    {
        AssertArg(MemoryContextIsValid(new_parent));
        context->parent = new_parent;
        context->nextchild = new_parent->firstchild;
        new_parent->firstchild = context;
    }
    else
    {
        context->parent = NULL;
        context->nextchild = NULL;
    }
}

void MemoryContextStats ( MemoryContext  context  ) 

Variable Documentation

Definition at line 46 of file mcxt.c.

Referenced by PostgresMain(), PostmasterMain(), and StartChildProcess().

Definition at line 44 of file mcxt.c.

Referenced by _hash_regscan(), add_reloption(), add_string_reloption(), allocate_reloption(), AllocSetAlloc(), AllocSetContextCreate(), AllocSetRealloc(), AtAbort_Memory(), AtCleanup_Memory(), AtCommit_Memory(), AtStart_Memory(), AutoVacLauncherMain(), BackendRun(), BackgroundWriterMain(), cache_locale_time(), CheckpointerMain(), ConvertTriggerToFK(), CreateCacheMemoryContext(), dblink_connect(), do_autovacuum(), do_compile(), EnablePortalManager(), EventTriggerBeginCompleteQuery(), Exec_ListenCommit(), finish_xact_command(), get_tabstat_entry(), GetLocalBufferStorage(), GetLockConflicts(), hash_create(), InitDeadLockChecking(), initialize_reloptions(), InitializeSearchPath(), load_hba(), load_ident(), LockAcquireExtended(), mdinit(), mxid_to_string(), perm_fmgr_info(), pgstat_setup_memcxt(), plperl_spi_prepare(), PLy_malloc(), PLy_spi_execute_fetch_result(), PostgresMain(), PostmasterMain(), pq_init(), PrepareClientEncoding(), ProcessStartupPacket(), PushOverrideSearchPath(), recomputeNamespacePath(), register_label_provider(), RegisterResourceReleaseCallback(), RegisterSubXactCallback(), RegisterXactCallback(), RelationCreateStorage(), RelationDropStorage(), ResourceOwnerCreate(), ResourceOwnerEnlargeBuffers(), ResourceOwnerEnlargeCatCacheListRefs(), ResourceOwnerEnlargeCatCacheRefs(), ResourceOwnerEnlargeFiles(), ResourceOwnerEnlargePlanCacheRefs(), ResourceOwnerEnlargeRelationRefs(), ResourceOwnerEnlargeSnapshots(), ResourceOwnerEnlargeTupleDescs(), ri_HashCompareOp(), roles_has_privs_of(), roles_is_member_of(), sepgsql_avc_init(), sepgsql_xact_callback(), SetDatabasePath(), StartChildProcess(), tokenize_file(), and WalWriterMain().