PostgreSQL Source Code
git master
|
#include "postgres.h"
#include "port/pg_bitutils.h"
#include "utils/memdebug.h"
#include "utils/memutils.h"
#include "utils/memutils_internal.h"
#include "utils/memutils_memorychunk.h"
Go to the source code of this file.
Data Structures | |
struct | AllocFreeListLink |
struct | AllocSetContext |
struct | AllocBlockData |
struct | AllocSetFreeList |
Typedefs | |
typedef struct AllocBlockData * | AllocBlock |
typedef void * | AllocPointer |
typedef struct AllocFreeListLink | AllocFreeListLink |
typedef struct AllocSetContext | AllocSetContext |
typedef AllocSetContext * | AllocSet |
typedef struct AllocBlockData | AllocBlockData |
typedef struct AllocSetFreeList | AllocSetFreeList |
Variables | |
static AllocSetFreeList | context_freelists [2] |
#define ALLOC_BLOCKHDRSZ MAXALIGN(sizeof(AllocBlockData)) |
#define ALLOC_CHUNK_LIMIT (1 << (ALLOCSET_NUM_FREELISTS-1+ALLOC_MINBITS)) |
#define ALLOC_CHUNKHDRSZ sizeof(MemoryChunk) |
#define AllocBlockIsValid | ( | block | ) | (PointerIsValid(block) && AllocSetIsValid((block)->aset)) |
#define AllocPointerIsValid | ( | pointer | ) | PointerIsValid(pointer) |
#define AllocSetIsValid | ( | set | ) | (PointerIsValid(set) && IsA(set, AllocSetContext)) |
#define ExternalChunkGetBlock | ( | chunk | ) | (AllocBlock) ((char *) chunk - ALLOC_BLOCKHDRSZ) |
#define FreeListIdxIsValid | ( | fidx | ) | ((fidx) >= 0 && (fidx) < ALLOCSET_NUM_FREELISTS) |
#define GetChunkSizeFromFreeListIdx | ( | fidx | ) | ((((Size) 1) << ALLOC_MINBITS) << (fidx)) |
#define GetFreeListLink | ( | chkptr | ) | (AllocFreeListLink *) ((char *) (chkptr) + ALLOC_CHUNKHDRSZ) |
#define IsKeeperBlock | ( | set, | |
block | |||
) | ((block) == (KeeperBlock(set))) |
#define KeeperBlock | ( | set | ) | ((AllocBlock) (((char *) set) + MAXALIGN(sizeof(AllocSetContext)))) |
#define MAX_FREE_CONTEXTS 100 /* arbitrary limit on freelist length */ |
typedef struct AllocBlockData* AllocBlock |
typedef struct AllocBlockData AllocBlockData |
typedef struct AllocFreeListLink AllocFreeListLink |
typedef void* AllocPointer |
typedef AllocSetContext* AllocSet |
typedef struct AllocSetContext AllocSetContext |
typedef struct AllocSetFreeList AllocSetFreeList |
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().
|
inlinestatic |
Definition at line 774 of file aset.c.
References ALLOC_CHUNKHDRSZ, Assert, chunk, AllocBlockData::endptr, AllocBlockData::freeptr, MCTX_ASET_ID, MemoryChunkGetPointer, MemoryChunkSetHdrMask(), size, VALGRIND_MAKE_MEM_NOACCESS, and VALGRIND_MAKE_MEM_UNDEFINED.
Referenced by AllocSetAlloc(), and AllocSetAllocFromNewBlock().
|
static |
Definition at line 819 of file aset.c.
References ALLOC_BLOCKHDRSZ, ALLOC_CHUNKHDRSZ, ALLOC_MINBITS, AllocSetAllocChunkFromBlock(), AllocSetFreeIndex(), AllocBlockData::aset, Assert, AllocSetContext::blocks, chunk, context, AllocBlockData::endptr, AllocSetContext::freelist, AllocBlockData::freeptr, GetChunkSizeFromFreeListIdx, GetFreeListLink, InvalidAllocSize, link(), malloc, AllocSetContext::maxBlockSize, MCTX_ASET_ID, MemoryChunkSetHdrMask(), MemoryContextAllocationFailure(), AllocBlockData::next, AllocSetContext::nextBlockSize, AllocBlockData::prev, size, VALGRIND_MAKE_MEM_DEFINED, VALGRIND_MAKE_MEM_NOACCESS, and VALGRIND_MAKE_MEM_UNDEFINED.
Referenced by AllocSetAlloc().
|
static |
Definition at line 696 of file aset.c.
References ALLOC_BLOCKHDRSZ, ALLOC_CHUNKHDRSZ, AllocBlockData::aset, Assert, AllocSetContext::blocks, chunk, context, AllocBlockData::endptr, AllocBlockData::freeptr, malloc, MAXALIGN, MCTX_ASET_ID, MemoryChunkGetPointer, MemoryChunkSetHdrMaskExternal(), MemoryContextAllocationFailure(), MemoryContextCheckSize(), AllocBlockData::next, AllocBlockData::prev, size, and VALGRIND_MAKE_MEM_NOACCESS.
Referenced by AllocSetAlloc().
MemoryContext AllocSetContextCreateInternal | ( | MemoryContext | parent, |
const char * | name, | ||
Size | minContextSize, | ||
Size | initBlockSize, | ||
Size | maxBlockSize | ||
) |
Definition at line 347 of file aset.c.
References ALLOC_BLOCKHDRSZ, ALLOC_CHUNK_FRACTION, ALLOC_CHUNK_LIMIT, ALLOC_CHUNKHDRSZ, ALLOC_MINBITS, AllocSetContext::allocChunkLimit, AllocHugeSizeIsValid, ALLOCSET_DEFAULT_INITSIZE, ALLOCSET_DEFAULT_MINSIZE, ALLOCSET_SEPARATE_THRESHOLD, ALLOCSET_SMALL_INITSIZE, ALLOCSET_SMALL_MINSIZE, AllocBlockData::aset, Assert, AllocSetContext::blocks, context_freelists, AllocBlockData::endptr, ereport, errcode(), errdetail(), errmsg(), ERROR, AllocSetFreeList::first_free, AllocSetContext::freelist, AllocSetContext::freeListIndex, AllocBlockData::freeptr, AllocSetContext::header, AllocSetContext::initBlockSize, KeeperBlock, malloc, Max, MAXALIGN, AllocSetContext::maxBlockSize, MCTX_ASET_ID, MEMORYCHUNK_MAX_BLOCKOFFSET, MemoryContextCreate(), MemoryContextStats(), MemSetAligned, name, AllocBlockData::next, AllocSetContext::nextBlockSize, MemoryContextData::nextchild, AllocSetFreeList::num_free, AllocBlockData::prev, StaticAssertDecl, StaticAssertStmt, TopMemoryContext, and VALGRIND_MAKE_MEM_NOACCESS.
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().
|
inlinestatic |
Definition at line 277 of file aset.c.
References ALLOC_CHUNK_LIMIT, ALLOC_MINBITS, ALLOCSET_NUM_FREELISTS, Assert, idx(), pg_leftmost_one_pos, pg_leftmost_one_pos32(), size, and StaticAssertDecl.
Referenced by AllocSetAlloc(), and AllocSetAllocFromNewBlock().
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.
|
static |
Definition at line 257 of file aset.c.
Referenced by AllocSetContextCreateInternal(), and AllocSetDelete().