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 3 |
#define | MEMORY_CONTEXT_METHODID_MASK ((((uint64) 1) << MEMORY_CONTEXT_METHODID_BITS) - 1) |
Typedefs | |
typedef enum MemoryContextMethodID | MemoryContextMethodID |
Enumerations | |
enum | MemoryContextMethodID { MCTX_UNUSED1_ID , MCTX_UNUSED2_ID , MCTX_UNUSED3_ID , MCTX_ASET_ID , MCTX_GENERATION_ID , MCTX_SLAB_ID , MCTX_ALIGNED_REDIRECT_ID , MCTX_UNUSED4_ID } |
#define MEMORY_CONTEXT_METHODID_BITS 3 |
Definition at line 121 of file memutils_internal.h.
#define MEMORY_CONTEXT_METHODID_MASK ((((uint64) 1) << MEMORY_CONTEXT_METHODID_BITS) - 1) |
Definition at line 122 of file memutils_internal.h.
#define PallocAlignedExtraBytes | ( | alignto | ) | ((alignto) + (sizeof(MemoryChunk) - MAXIMUM_ALIGNOF)) |
Definition at line 88 of file memutils_internal.h.
typedef enum MemoryContextMethodID MemoryContextMethodID |
Enumerator | |
---|---|
MCTX_UNUSED1_ID | |
MCTX_UNUSED2_ID | |
MCTX_UNUSED3_ID | |
MCTX_ASET_ID | |
MCTX_GENERATION_ID | |
MCTX_SLAB_ID | |
MCTX_ALIGNED_REDIRECT_ID | |
MCTX_UNUSED4_ID |
Definition at line 105 of file memutils_internal.h.
void AlignedAllocFree | ( | void * | pointer | ) |
Definition at line 29 of file alignedalloc.c.
References Assert(), elog(), GetMemoryChunkContext(), MemoryChunkGetBlock(), MemoryChunkIsExternal(), name, pfree(), PointerGetMemoryChunk, VALGRIND_MAKE_MEM_DEFINED, and WARNING.
MemoryContext AlignedAllocGetChunkContext | ( | void * | pointer | ) |
Definition at line 118 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 140 of file alignedalloc.c.
References GetMemoryChunkSpace(), MemoryChunkGetBlock(), PointerGetMemoryChunk, VALGRIND_MAKE_MEM_DEFINED, and VALGRIND_MAKE_MEM_NOACCESS.
void* AlignedAllocRealloc | ( | void * | pointer, |
Size | size | ||
) |
Definition at line 60 of file alignedalloc.c.
References Assert(), GetMemoryChunkContext(), GetMemoryChunkSpace(), MemoryChunkGetBlock(), MemoryChunkGetValue(), MemoryContextAllocAligned(), Min, PallocAlignedExtraBytes, pfree(), PointerGetMemoryChunk, and VALGRIND_MAKE_MEM_DEFINED.
void* AllocSetAlloc | ( | MemoryContext | context, |
Size | size | ||
) |
Definition at line 703 of file aset.c.
References ALLOC_BLOCKHDRSZ, ALLOC_CHUNKHDRSZ, ALLOC_MINBITS, AllocSetContext::allocChunkLimit, AllocSetFreeIndex(), AllocSetIsValid, AllocBlockData::aset, Assert(), AllocSetContext::blocks, AllocBlockData::endptr, AllocSetContext::freelist, AllocBlockData::freeptr, GetChunkSizeFromFreeListIdx, GetFreeListLink, InvalidAllocSize, link(), malloc, MAXALIGN, AllocSetContext::maxBlockSize, MCTX_ASET_ID, MemoryContextData::mem_allocated, MemoryChunkGetPointer, MemoryChunkGetValue(), MemoryChunkSetHdrMask(), MemoryChunkSetHdrMaskExternal(), AllocBlockData::next, AllocSetContext::nextBlockSize, AllocBlockData::prev, VALGRIND_MAKE_MEM_DEFINED, VALGRIND_MAKE_MEM_NOACCESS, and VALGRIND_MAKE_MEM_UNDEFINED.
Referenced by AllocSetRealloc().
void AllocSetDelete | ( | MemoryContext | context | ) |
Definition at line 607 of file aset.c.
References AllocSetIsValid, Assert(), AllocSetContext::blocks, context_freelists, AllocBlockData::endptr, AllocSetFreeList::first_free, free, AllocSetContext::freeListIndex, AllocBlockData::freeptr, AllocSetContext::header, IsKeeperBlock, MemoryContextData::isReset, KeeperBlock, MAX_FREE_CONTEXTS, MemoryContextData::mem_allocated, MemoryContextResetOnly(), next, AllocBlockData::next, MemoryContextData::nextchild, AllocSetFreeList::num_free, and PG_USED_FOR_ASSERTS_ONLY.
void AllocSetFree | ( | void * | pointer | ) |
Definition at line 1002 of file aset.c.
References ALLOC_CHUNKHDRSZ, AllocBlockIsValid, AllocBlockData::aset, Assert(), AllocSetContext::blocks, 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 1370 of file aset.c.
References ALLOC_CHUNKHDRSZ, AllocBlockIsValid, AllocBlockData::aset, Assert(), ExternalChunkGetBlock, AllocSetContext::header, MemoryChunkGetBlock(), MemoryChunkIsExternal(), PointerGetMemoryChunk, VALGRIND_MAKE_MEM_DEFINED, and VALGRIND_MAKE_MEM_NOACCESS.
Size AllocSetGetChunkSpace | ( | void * | pointer | ) |
Definition at line 1399 of file aset.c.
References ALLOC_CHUNKHDRSZ, AllocBlockIsValid, Assert(), AllocBlockData::endptr, ExternalChunkGetBlock, FreeListIdxIsValid, GetChunkSizeFromFreeListIdx, MemoryChunkGetValue(), MemoryChunkIsExternal(), PointerGetMemoryChunk, VALGRIND_MAKE_MEM_DEFINED, and VALGRIND_MAKE_MEM_NOACCESS.
bool AllocSetIsEmpty | ( | MemoryContext | context | ) |
Definition at line 1433 of file aset.c.
References AllocSetIsValid, Assert(), and MemoryContextData::isReset.
void* AllocSetRealloc | ( | void * | pointer, |
Size | size | ||
) |
Definition at line 1109 of file aset.c.
References ALLOC_BLOCKHDRSZ, ALLOC_CHUNKHDRSZ, AllocBlockIsValid, AllocSetAlloc(), AllocSetFree(), AllocBlockData::aset, Assert(), AllocSetContext::blocks, elog(), AllocBlockData::endptr, ERROR, ExternalChunkGetBlock, FreeListIdxIsValid, AllocBlockData::freeptr, GetChunkSizeFromFreeListIdx, AllocSetContext::header, MAXALIGN, MemoryContextData::mem_allocated, MemoryChunkGetBlock(), MemoryChunkGetPointer, MemoryChunkGetValue(), MemoryChunkIsExternal(), Min, MemoryContextData::name, AllocBlockData::next, PointerGetMemoryChunk, AllocBlockData::prev, realloc, 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, AllocBlockData::endptr, free, AllocSetContext::freelist, AllocBlockData::freeptr, AllocSetContext::initBlockSize, IsKeeperBlock, KeeperBlock, MemoryContextData::mem_allocated, 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 1458 of file aset.c.
References ALLOC_CHUNKHDRSZ, ALLOCSET_NUM_FREELISTS, AllocSetIsValid, Assert(), AllocSetContext::blocks, 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* GenerationAlloc | ( | MemoryContext | context, |
Size | size | ||
) |
Definition at line 345 of file generation.c.
References GenerationContext::allocChunkLimit, Assert(), GenerationBlock::blksize, GenerationContext::block, GenerationContext::blocks, GenerationBlock::context, dlist_push_head(), GenerationBlock::endptr, GenerationContext::freeblock, GenerationBlock::freeptr, Generation_BLOCKHDRSZ, Generation_CHUNKHDRSZ, GenerationBlockFreeBytes(), GenerationBlockInit(), GenerationBlockIsEmpty(), GenerationIsValid, KeeperBlock, malloc, MAXALIGN, GenerationContext::maxBlockSize, MCTX_GENERATION_ID, MemoryContextData::mem_allocated, MemoryChunkGetPointer, MemoryChunkSetHdrMask(), MemoryChunkSetHdrMaskExternal(), GenerationBlock::nchunks, GenerationContext::nextBlockSize, GenerationBlock::nfree, GenerationBlock::node, pg_nextpower2_size_t, VALGRIND_MAKE_MEM_NOACCESS, and VALGRIND_MAKE_MEM_UNDEFINED.
Referenced by GenerationRealloc().
void GenerationDelete | ( | MemoryContext | context | ) |
void GenerationFree | ( | void * | pointer | ) |
Definition at line 623 of file generation.c.
References Assert(), GenerationBlock::blksize, GenerationContext::block, GenerationBlock::context, dlist_delete(), elog(), GenerationBlock::endptr, ERROR, ExternalChunkGetBlock, free, GenerationContext::freeblock, Generation_CHUNKHDRSZ, GenerationBlockIsValid, GenerationBlockMarkEmpty(), GenerationContext::header, InvalidAllocSize, IsKeeperBlock, MemoryContextData::mem_allocated, MemoryChunkGetBlock(), MemoryChunkGetValue(), MemoryChunkIsExternal(), GenerationBlock::nchunks, GenerationBlock::nfree, GenerationBlock::node, PointerGetMemoryChunk, VALGRIND_MAKE_MEM_DEFINED, and WARNING.
Referenced by GenerationRealloc().
MemoryContext GenerationGetChunkContext | ( | void * | pointer | ) |
Definition at line 880 of file generation.c.
References Assert(), 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 906 of file generation.c.
References Assert(), 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 935 of file generation.c.
References Assert(), GenerationContext::blocks, dlist_iter::cur, dlist_container, dlist_foreach, GenerationIsValid, and GenerationBlock::nchunks.
void* GenerationRealloc | ( | void * | pointer, |
Size | size | ||
) |
Definition at line 738 of file generation.c.
References Assert(), GenerationBlock::context, elog(), GenerationBlock::endptr, ERROR, ExternalChunkGetBlock, Generation_CHUNKHDRSZ, GenerationAlloc(), GenerationBlockIsValid, GenerationFree(), MemoryChunkGetBlock(), MemoryChunkGetValue(), MemoryChunkIsExternal(), name, PointerGetMemoryChunk, VALGRIND_MAKE_MEM_DEFINED, VALGRIND_MAKE_MEM_NOACCESS, VALGRIND_MAKE_MEM_UNDEFINED, and WARNING.
void GenerationReset | ( | MemoryContext | context | ) |
Definition at line 278 of file generation.c.
References Assert(), GenerationContext::block, GenerationContext::blocks, 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 966 of file generation.c.
References Assert(), GenerationBlock::blksize, GenerationContext::blocks, 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 MemoryContextCreate | ( | MemoryContext | node, |
NodeTag | tag, | ||
MemoryContextMethodID | method_id, | ||
MemoryContext | parent, | ||
const char * | name | ||
) |
Definition at line 973 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(), GenerationContextCreate(), and SlabContextCreate().
void* SlabAlloc | ( | MemoryContext | context, |
Size | size | ||
) |
Definition at line 499 of file slab.c.
References Assert(), SlabContext::blocklist, SlabContext::blockSize, SlabContext::chunkSize, SlabContext::chunksPerBlock, SlabContext::curBlocklistIndex, dclist_count(), dclist_pop_head_node(), dlist_container, dlist_delete_from(), dlist_head_element, dlist_is_empty(), dlist_push_head(), elog(), SlabContext::emptyblocks, ERROR, SlabBlock::freehead, SlabContext::fullChunkSize, malloc, MAXALIGN, MCTX_SLAB_ID, MemoryContextData::mem_allocated, MemoryChunkGetPointer, MemoryChunkSetHdrMask(), SlabBlock::nfree, SlabBlock::node, SlabBlock::nunused, SlabBlock::slab, Slab_CHUNKHDRSZ, SlabBlockGetChunk, SlabBlocklistIndex(), SlabFindNextBlockListIndex(), SlabGetNextFreeChunk(), SlabIsValid, unlikely, SlabBlock::unused, VALGRIND_MAKE_MEM_NOACCESS, and VALGRIND_MAKE_MEM_UNDEFINED.
void SlabDelete | ( | MemoryContext | context | ) |
void SlabFree | ( | void * | pointer | ) |
Definition at line 648 of file slab.c.
References Assert(), SlabContext::blocklist, SlabContext::blockSize, 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 810 of file slab.c.
References Assert(), 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 834 of file slab.c.
References Assert(), SlabContext::fullChunkSize, MemoryChunkGetBlock(), PointerGetMemoryChunk, SlabBlock::slab, Slab_CHUNKHDRSZ, SlabBlockIsValid, VALGRIND_MAKE_MEM_DEFINED, and VALGRIND_MAKE_MEM_NOACCESS.
bool SlabIsEmpty | ( | MemoryContext | context | ) |
Definition at line 859 of file slab.c.
References Assert(), MemoryContextData::mem_allocated, and SlabIsValid.
void* SlabRealloc | ( | void * | pointer, |
Size | size | ||
) |
Definition at line 773 of file slab.c.
References SlabContext::chunkSize, elog(), ERROR, MemoryChunkGetBlock(), PointerGetMemoryChunk, 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, dlist_mutable_iter::cur, SlabContext::curBlocklistIndex, dclist_delete_from(), dclist_foreach_modify, dlist_container, dlist_delete(), dlist_foreach_modify, SlabContext::emptyblocks, free, i, MemoryContextData::mem_allocated, 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 876 of file slab.c.
References Assert(), SlabContext::blocklist, SlabContext::blockSize, SlabContext::chunksPerBlock, 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.