PostgreSQL Source Code
git master
|
#include "utils/memutils.h"
Go to the source code of this file.
Macros | |
#define | PallocAlignedExtraBytes(alignto) ((alignto) + (sizeof(MemoryChunk) - MAXIMUM_ALIGNOF)) |
#define | MEMORY_CONTEXT_METHODID_BITS 4 |
#define | MEMORY_CONTEXT_METHODID_MASK ((((uint64) 1) << MEMORY_CONTEXT_METHODID_BITS) - 1) |
Typedefs | |
typedef enum MemoryContextMethodID | MemoryContextMethodID |
#define MEMORY_CONTEXT_METHODID_BITS 4 |
Definition at line 145 of file memutils_internal.h.
#define MEMORY_CONTEXT_METHODID_MASK ((((uint64) 1) << MEMORY_CONTEXT_METHODID_BITS) - 1) |
Definition at line 146 of file memutils_internal.h.
#define PallocAlignedExtraBytes | ( | alignto | ) | ((alignto) + (sizeof(MemoryChunk) - MAXIMUM_ALIGNOF)) |
Definition at line 104 of file memutils_internal.h.
typedef enum MemoryContextMethodID MemoryContextMethodID |
Definition at line 121 of file memutils_internal.h.
void AlignedAllocFree | ( | void * | pointer | ) |
Definition at line 29 of file alignedalloc.c.
References Assert, chunk, elog, GetMemoryChunkContext(), MemoryChunkGetBlock(), MemoryChunkIsExternal(), name, pfree(), PointerGetMemoryChunk, VALGRIND_MAKE_MEM_DEFINED, and WARNING.
MemoryContext AlignedAllocGetChunkContext | ( | void * | pointer | ) |
Definition at line 121 of file alignedalloc.c.
References Assert, GetMemoryChunkContext(), MemoryChunkGetBlock(), MemoryChunkIsExternal(), PointerGetMemoryChunk, VALGRIND_MAKE_MEM_DEFINED, and VALGRIND_MAKE_MEM_NOACCESS.
Size AlignedAllocGetChunkSpace | ( | void * | pointer | ) |
Definition at line 143 of file alignedalloc.c.
References GetMemoryChunkSpace(), MemoryChunkGetBlock(), PointerGetMemoryChunk, VALGRIND_MAKE_MEM_DEFINED, and VALGRIND_MAKE_MEM_NOACCESS.
void* AlignedAllocRealloc | ( | void * | pointer, |
Size | size, | ||
int | flags | ||
) |
Definition at line 60 of file alignedalloc.c.
References Assert, GetMemoryChunkContext(), GetMemoryChunkSpace(), likely, MemoryChunkGetBlock(), MemoryChunkGetValue(), MemoryContextAllocAligned(), Min, PallocAlignedExtraBytes, pfree(), PointerGetMemoryChunk, size, and VALGRIND_MAKE_MEM_DEFINED.
void* AllocSetAlloc | ( | MemoryContext | context, |
Size | size, | ||
int | flags | ||
) |
Definition at line 967 of file aset.c.
References ALLOC_CHUNKHDRSZ, AllocSetContext::allocChunkLimit, AllocSetAllocChunkFromBlock(), AllocSetAllocFromNewBlock(), AllocSetAllocLarge(), AllocSetFreeIndex(), AllocSetIsValid, Assert, AllocSetContext::blocks, chunk, context, AllocBlockData::endptr, AllocSetContext::freelist, AllocBlockData::freeptr, GetChunkSizeFromFreeListIdx, GetFreeListLink, MemoryChunkGetPointer, MemoryChunkGetValue(), size, unlikely, VALGRIND_MAKE_MEM_DEFINED, and VALGRIND_MAKE_MEM_NOACCESS.
Referenced by AllocSetRealloc().
void AllocSetDelete | ( | MemoryContext | context | ) |
Definition at line 607 of file aset.c.
References AllocSetIsValid, Assert, AllocSetContext::blocks, context, context_freelists, AllocBlockData::endptr, AllocSetFreeList::first_free, free, AllocSetContext::freeListIndex, AllocBlockData::freeptr, AllocSetContext::header, IsKeeperBlock, KeeperBlock, MAX_FREE_CONTEXTS, MemoryContextResetOnly(), next, AllocBlockData::next, MemoryContextData::nextchild, AllocSetFreeList::num_free, and PG_USED_FOR_ASSERTS_ONLY.
void AllocSetFree | ( | void * | pointer | ) |
Definition at line 1062 of file aset.c.
References ALLOC_CHUNKHDRSZ, AllocBlockIsValid, AllocBlockData::aset, Assert, AllocSetContext::blocks, chunk, elog, AllocBlockData::endptr, ERROR, ExternalChunkGetBlock, free, AllocSetContext::freelist, FreeListIdxIsValid, AllocBlockData::freeptr, GetChunkSizeFromFreeListIdx, GetFreeListLink, AllocSetContext::header, InvalidAllocSize, link(), MemoryContextData::mem_allocated, MemoryChunkGetBlock(), MemoryChunkGetValue(), MemoryChunkIsExternal(), MemoryContextData::name, AllocBlockData::next, PointerGetMemoryChunk, AllocBlockData::prev, VALGRIND_MAKE_MEM_DEFINED, VALGRIND_MAKE_MEM_NOACCESS, and WARNING.
Referenced by AllocSetRealloc().
MemoryContext AllocSetGetChunkContext | ( | void * | pointer | ) |
Definition at line 1433 of file aset.c.
References ALLOC_CHUNKHDRSZ, AllocBlockIsValid, AllocBlockData::aset, Assert, chunk, ExternalChunkGetBlock, AllocSetContext::header, MemoryChunkGetBlock(), MemoryChunkIsExternal(), PointerGetMemoryChunk, VALGRIND_MAKE_MEM_DEFINED, and VALGRIND_MAKE_MEM_NOACCESS.
Size AllocSetGetChunkSpace | ( | void * | pointer | ) |
Definition at line 1462 of file aset.c.
References ALLOC_CHUNKHDRSZ, AllocBlockIsValid, Assert, chunk, AllocBlockData::endptr, ExternalChunkGetBlock, FreeListIdxIsValid, GetChunkSizeFromFreeListIdx, MemoryChunkGetValue(), MemoryChunkIsExternal(), PointerGetMemoryChunk, VALGRIND_MAKE_MEM_DEFINED, and VALGRIND_MAKE_MEM_NOACCESS.
bool AllocSetIsEmpty | ( | MemoryContext | context | ) |
void* AllocSetRealloc | ( | void * | pointer, |
Size | size, | ||
int | flags | ||
) |
Definition at line 1169 of file aset.c.
References ALLOC_BLOCKHDRSZ, ALLOC_CHUNKHDRSZ, AllocBlockIsValid, AllocSetAlloc(), AllocSetFree(), AllocBlockData::aset, Assert, chunk, elog, AllocBlockData::endptr, ERROR, ExternalChunkGetBlock, FreeListIdxIsValid, AllocBlockData::freeptr, GetChunkSizeFromFreeListIdx, AllocSetContext::header, MAXALIGN, MemoryContextData::mem_allocated, MemoryChunkGetBlock(), MemoryChunkGetPointer, MemoryChunkGetValue(), MemoryChunkIsExternal(), MemoryContextAllocationFailure(), MemoryContextCheckSize(), Min, MemoryContextData::name, AllocBlockData::next, PointerGetMemoryChunk, AllocBlockData::prev, realloc, size, VALGRIND_MAKE_MEM_DEFINED, VALGRIND_MAKE_MEM_NOACCESS, VALGRIND_MAKE_MEM_UNDEFINED, and WARNING.
void AllocSetReset | ( | MemoryContext | context | ) |
Definition at line 537 of file aset.c.
References ALLOC_BLOCKHDRSZ, AllocSetIsValid, Assert, AllocSetContext::blocks, context, AllocBlockData::endptr, free, AllocSetContext::freelist, AllocBlockData::freeptr, AllocSetContext::initBlockSize, IsKeeperBlock, KeeperBlock, MemSetAligned, next, AllocBlockData::next, AllocSetContext::nextBlockSize, PG_USED_FOR_ASSERTS_ONLY, AllocBlockData::prev, and VALGRIND_MAKE_MEM_NOACCESS.
void AllocSetStats | ( | MemoryContext | context, |
MemoryStatsPrintFunc | printfunc, | ||
void * | passthru, | ||
MemoryContextCounters * | totals, | ||
bool | print_to_stderr | ||
) |
Definition at line 1521 of file aset.c.
References ALLOC_CHUNKHDRSZ, ALLOCSET_NUM_FREELISTS, AllocSetIsValid, Assert, AllocSetContext::blocks, chunk, context, AllocBlockData::endptr, MemoryContextCounters::freechunks, AllocSetContext::freelist, AllocBlockData::freeptr, MemoryContextCounters::freespace, GetChunkSizeFromFreeListIdx, GetFreeListLink, MAXALIGN, MemoryChunkGetValue(), MemoryContextCounters::nblocks, AllocBlockData::next, snprintf, MemoryContextCounters::totalspace, VALGRIND_MAKE_MEM_DEFINED, and VALGRIND_MAKE_MEM_NOACCESS.
void* BumpAlloc | ( | MemoryContext | context, |
Size | size, | ||
int | flags | ||
) |
Definition at line 491 of file bump.c.
References BumpContext::allocChunkLimit, Assert, BumpContext::blocks, Bump_CHUNKHDRSZ, BumpAllocChunkFromBlock(), BumpAllocFromNewBlock(), BumpAllocLarge(), BumpBlockFreeBytes(), BumpIsValid, context, dlist_container, dlist_head_node(), MAXALIGN, and size.
void BumpDelete | ( | MemoryContext | context | ) |
void BumpFree | ( | void * | pointer | ) |
MemoryContext BumpGetChunkContext | ( | void * | pointer | ) |
Size BumpGetChunkSpace | ( | void * | pointer | ) |
bool BumpIsEmpty | ( | MemoryContext | context | ) |
Definition at line 660 of file bump.c.
References Assert, BumpContext::blocks, BumpBlockIsEmpty(), BumpIsValid, context, dlist_iter::cur, dlist_container, and dlist_foreach.
void* BumpRealloc | ( | void * | pointer, |
Size | size, | ||
int | flags | ||
) |
void BumpReset | ( | MemoryContext | context | ) |
Definition at line 243 of file bump.c.
References Assert, BumpContext::blocks, BumpBlockFree(), BumpBlockMarkEmpty(), BumpIsValid, context, dlist_mutable_iter::cur, dlist_container, dlist_foreach_modify, dlist_has_next(), dlist_head_node(), dlist_is_empty(), BumpContext::initBlockSize, IsKeeperBlock, and BumpContext::nextBlockSize.
Referenced by BumpDelete().
void BumpStats | ( | MemoryContext | context, |
MemoryStatsPrintFunc | printfunc, | ||
void * | passthru, | ||
MemoryContextCounters * | totals, | ||
bool | print_to_stderr | ||
) |
Definition at line 688 of file bump.c.
References Assert, BumpContext::blocks, BumpIsValid, context, dlist_iter::cur, dlist_container, dlist_foreach, BumpBlock::endptr, BumpBlock::freeptr, MemoryContextCounters::freespace, MemoryContextCounters::nblocks, snprintf, and MemoryContextCounters::totalspace.
void* GenerationAlloc | ( | MemoryContext | context, |
Size | size, | ||
int | flags | ||
) |
Definition at line 527 of file generation.c.
References GenerationContext::allocChunkLimit, Assert, GenerationContext::block, context, GenerationContext::freeblock, Generation_CHUNKHDRSZ, GenerationAllocChunkFromBlock(), GenerationAllocFromNewBlock(), GenerationAllocLarge(), GenerationBlockFreeBytes(), GenerationBlockIsEmpty, GenerationIsValid, MAXALIGN, size, and unlikely.
Referenced by GenerationRealloc().
void GenerationDelete | ( | MemoryContext | context | ) |
void GenerationFree | ( | void * | pointer | ) |
Definition at line 689 of file generation.c.
References Assert, GenerationContext::block, chunk, GenerationBlock::context, elog, GenerationBlock::endptr, ERROR, ExternalChunkGetBlock, GenerationContext::freeblock, Generation_CHUNKHDRSZ, GenerationBlockFree(), GenerationBlockIsValid, GenerationBlockMarkEmpty(), InvalidAllocSize, IsKeeperBlock, likely, MemoryChunkGetBlock(), MemoryChunkGetValue(), MemoryChunkIsExternal(), GenerationBlock::nchunks, GenerationBlock::nfree, PointerGetMemoryChunk, VALGRIND_MAKE_MEM_DEFINED, and WARNING.
Referenced by GenerationRealloc().
MemoryContext GenerationGetChunkContext | ( | void * | pointer | ) |
Definition at line 947 of file generation.c.
References Assert, chunk, GenerationBlock::context, ExternalChunkGetBlock, Generation_CHUNKHDRSZ, GenerationBlockIsValid, GenerationContext::header, MemoryChunkGetBlock(), MemoryChunkIsExternal(), PointerGetMemoryChunk, VALGRIND_MAKE_MEM_DEFINED, and VALGRIND_MAKE_MEM_NOACCESS.
Size GenerationGetChunkSpace | ( | void * | pointer | ) |
Definition at line 973 of file generation.c.
References Assert, chunk, GenerationBlock::endptr, ExternalChunkGetBlock, Generation_CHUNKHDRSZ, GenerationBlockIsValid, MemoryChunkGetValue(), MemoryChunkIsExternal(), PointerGetMemoryChunk, VALGRIND_MAKE_MEM_DEFINED, and VALGRIND_MAKE_MEM_NOACCESS.
bool GenerationIsEmpty | ( | MemoryContext | context | ) |
Definition at line 1002 of file generation.c.
References Assert, GenerationContext::blocks, context, dlist_iter::cur, dlist_container, dlist_foreach, GenerationIsValid, and GenerationBlock::nchunks.
void* GenerationRealloc | ( | void * | pointer, |
Size | size, | ||
int | flags | ||
) |
Definition at line 800 of file generation.c.
References Assert, chunk, GenerationBlock::context, elog, GenerationBlock::endptr, ERROR, ExternalChunkGetBlock, Generation_CHUNKHDRSZ, GenerationAlloc(), GenerationBlockIsValid, GenerationFree(), MemoryChunkGetBlock(), MemoryChunkGetValue(), MemoryChunkIsExternal(), MemoryContextAllocationFailure(), name, PointerGetMemoryChunk, size, VALGRIND_MAKE_MEM_DEFINED, VALGRIND_MAKE_MEM_NOACCESS, VALGRIND_MAKE_MEM_UNDEFINED, and WARNING.
void GenerationReset | ( | MemoryContext | context | ) |
Definition at line 283 of file generation.c.
References Assert, GenerationContext::block, GenerationContext::blocks, context, dlist_mutable_iter::cur, dlist_container, dlist_foreach_modify, dlist_has_next(), dlist_head_node(), dlist_is_empty(), GenerationContext::freeblock, GenerationBlockFree(), GenerationBlockMarkEmpty(), GenerationIsValid, GenerationContext::initBlockSize, IsKeeperBlock, KeeperBlock, and GenerationContext::nextBlockSize.
Referenced by GenerationDelete().
void GenerationStats | ( | MemoryContext | context, |
MemoryStatsPrintFunc | printfunc, | ||
void * | passthru, | ||
MemoryContextCounters * | totals, | ||
bool | print_to_stderr | ||
) |
Definition at line 1033 of file generation.c.
References Assert, GenerationBlock::blksize, GenerationContext::blocks, context, dlist_iter::cur, dlist_container, dlist_foreach, GenerationBlock::endptr, MemoryContextCounters::freechunks, GenerationBlock::freeptr, MemoryContextCounters::freespace, GenerationIsValid, MAXALIGN, MemoryContextCounters::nblocks, GenerationBlock::nchunks, GenerationBlock::nfree, snprintf, and MemoryContextCounters::totalspace.
void* MemoryContextAllocationFailure | ( | MemoryContext | context, |
Size | size, | ||
int | flags | ||
) |
Definition at line 1147 of file mcxt.c.
References context, ereport, errcode(), errdetail(), errmsg(), ERROR, MCXT_ALLOC_NO_OOM, MemoryContextStats(), size, and TopMemoryContext.
Referenced by AllocSetAllocFromNewBlock(), AllocSetAllocLarge(), AllocSetRealloc(), BumpAllocFromNewBlock(), GenerationAllocFromNewBlock(), GenerationAllocLarge(), GenerationRealloc(), and SlabAllocFromNewBlock().
|
inlinestatic |
Definition at line 167 of file memutils_internal.h.
References AllocHugeSizeIsValid, AllocSizeIsValid, context, MCXT_ALLOC_HUGE, MemoryContextSizeFailure(), size, and unlikely.
Referenced by AllocSetAllocLarge(), AllocSetRealloc(), BumpAllocLarge(), and GenerationAllocLarge().
void MemoryContextCreate | ( | MemoryContext | node, |
NodeTag | tag, | ||
MemoryContextMethodID | method_id, | ||
MemoryContext | parent, | ||
const char * | name | ||
) |
Definition at line 1100 of file mcxt.c.
References MemoryContextData::allowInCritSection, Assert, CritSectionCount, MemoryContextData::firstchild, MemoryContextData::ident, MemoryContextData::isReset, mcxt_methods, MemoryContextData::mem_allocated, MemoryContextData::methods, name, MemoryContextData::name, MemoryContextData::nextchild, MemoryContextData::parent, MemoryContextData::prevchild, MemoryContextData::reset_cbs, and VALGRIND_CREATE_MEMPOOL.
Referenced by AllocSetContextCreateInternal(), BumpContextCreate(), GenerationContextCreate(), and SlabContextCreate().
void MemoryContextSizeFailure | ( | MemoryContext | context, |
Size | size, | ||
int | flags | ||
) |
void* SlabAlloc | ( | MemoryContext | context, |
Size | size, | ||
int | flags | ||
) |
Definition at line 630 of file slab.c.
References Assert, SlabContext::blocklist, chunk, SlabContext::chunkSize, SlabContext::chunksPerBlock, context, SlabContext::curBlocklistIndex, dlist_delete_from(), dlist_head_element, dlist_is_empty(), dlist_push_head(), SlabBlock::nfree, SlabBlock::node, size, SlabAllocFromNewBlock(), SlabAllocSetupNewChunk(), SlabBlocklistIndex(), SlabFindNextBlockListIndex(), SlabGetNextFreeChunk(), SlabIsValid, and unlikely.
void SlabDelete | ( | MemoryContext | context | ) |
void SlabFree | ( | void * | pointer | ) |
Definition at line 701 of file slab.c.
References Assert, SlabContext::blocklist, SlabContext::blockSize, chunk, SlabContext::chunkSize, SlabContext::chunksPerBlock, SlabContext::curBlocklistIndex, dclist_count(), dclist_push_head(), dlist_delete_from(), dlist_is_empty(), dlist_push_head(), elog(), SlabContext::emptyblocks, free, SlabBlock::freehead, SlabContext::fullChunkSize, SlabContext::header, MemoryContextData::mem_allocated, MemoryChunkGetBlock(), MemoryContextData::name, SlabBlock::nfree, SlabBlock::node, PointerGetMemoryChunk, SlabBlock::slab, Slab_CHUNKHDRSZ, SLAB_MAXIMUM_EMPTY_BLOCKS, SlabBlockIsValid, SlabBlocklistIndex(), SlabFindNextBlockListIndex(), unlikely, VALGRIND_MAKE_MEM_DEFINED, and WARNING.
MemoryContext SlabGetChunkContext | ( | void * | pointer | ) |
Definition at line 863 of file slab.c.
References Assert, chunk, SlabContext::header, MemoryChunkGetBlock(), PointerGetMemoryChunk, SlabBlock::slab, Slab_CHUNKHDRSZ, SlabBlockIsValid, VALGRIND_MAKE_MEM_DEFINED, and VALGRIND_MAKE_MEM_NOACCESS.
Size SlabGetChunkSpace | ( | void * | pointer | ) |
Definition at line 887 of file slab.c.
References Assert, chunk, SlabContext::fullChunkSize, MemoryChunkGetBlock(), PointerGetMemoryChunk, SlabBlock::slab, Slab_CHUNKHDRSZ, SlabBlockIsValid, VALGRIND_MAKE_MEM_DEFINED, and VALGRIND_MAKE_MEM_NOACCESS.
bool SlabIsEmpty | ( | MemoryContext | context | ) |
void* SlabRealloc | ( | void * | pointer, |
Size | size, | ||
int | flags | ||
) |
Definition at line 826 of file slab.c.
References chunk, SlabContext::chunkSize, elog(), ERROR, MemoryChunkGetBlock(), PointerGetMemoryChunk, size, SlabBlock::slab, Slab_CHUNKHDRSZ, SlabBlockIsValid, VALGRIND_MAKE_MEM_DEFINED, and VALGRIND_MAKE_MEM_NOACCESS.
void SlabReset | ( | MemoryContext | context | ) |
Definition at line 431 of file slab.c.
References Assert, SlabContext::blocklist, SlabContext::blockSize, context, dlist_mutable_iter::cur, SlabContext::curBlocklistIndex, dclist_delete_from(), dclist_foreach_modify, dlist_container, dlist_delete(), dlist_foreach_modify, SlabContext::emptyblocks, free, i, SLAB_BLOCKLIST_COUNT, and SlabIsValid.
Referenced by SlabDelete().
void SlabStats | ( | MemoryContext | context, |
MemoryStatsPrintFunc | printfunc, | ||
void * | passthru, | ||
MemoryContextCounters * | totals, | ||
bool | print_to_stderr | ||
) |
Definition at line 929 of file slab.c.
References Assert, SlabContext::blocklist, SlabContext::blockSize, SlabContext::chunksPerBlock, context, dlist_iter::cur, dclist_count(), dlist_container, dlist_foreach, SlabContext::emptyblocks, MemoryContextCounters::freechunks, MemoryContextCounters::freespace, SlabContext::fullChunkSize, i, MemoryContextCounters::nblocks, SlabBlock::nfree, SLAB_BLOCKLIST_COUNT, Slab_CONTEXT_HDRSZ, SlabIsValid, snprintf, and MemoryContextCounters::totalspace.