PostgreSQL Source Code
git master
|
#include "postgres.h"
#include "port/pg_bitutils.h"
#include "utils/memdebug.h"
#include "utils/memutils.h"
#include "utils/memutils_memorychunk.h"
#include "utils/memutils_internal.h"
Go to the source code of this file.
Data Structures | |
struct | AllocFreeListLink |
struct | AllocSetContext |
struct | AllocBlockData |
struct | AllocSetFreeList |
Macros | |
#define | ALLOC_MINBITS 3 /* smallest chunk size is 8 bytes */ |
#define | ALLOCSET_NUM_FREELISTS 11 |
#define | ALLOC_CHUNK_LIMIT (1 << (ALLOCSET_NUM_FREELISTS-1+ALLOC_MINBITS)) |
#define | ALLOC_CHUNK_FRACTION 4 |
#define | ALLOC_BLOCKHDRSZ MAXALIGN(sizeof(AllocBlockData)) |
#define | ALLOC_CHUNKHDRSZ sizeof(MemoryChunk) |
#define | GetFreeListLink(chkptr) (AllocFreeListLink *) ((char *) (chkptr) + ALLOC_CHUNKHDRSZ) |
#define | FreeListIdxIsValid(fidx) ((fidx) >= 0 && (fidx) < ALLOCSET_NUM_FREELISTS) |
#define | GetChunkSizeFromFreeListIdx(fidx) ((((Size) 1) << ALLOC_MINBITS) << (fidx)) |
#define | AllocPointerIsValid(pointer) PointerIsValid(pointer) |
#define | AllocSetIsValid(set) (PointerIsValid(set) && IsA(set, AllocSetContext)) |
#define | AllocBlockIsValid(block) (PointerIsValid(block) && AllocSetIsValid((block)->aset)) |
#define | ExternalChunkGetBlock(chunk) (AllocBlock) ((char *) chunk - ALLOC_BLOCKHDRSZ) |
#define | MAX_FREE_CONTEXTS 100 /* arbitrary limit on freelist length */ |
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 |
Functions | |
static int | AllocSetFreeIndex (Size size) |
MemoryContext | AllocSetContextCreateInternal (MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize) |
void | AllocSetReset (MemoryContext context) |
void | AllocSetDelete (MemoryContext context) |
void * | AllocSetAlloc (MemoryContext context, Size size) |
void | AllocSetFree (void *pointer) |
void * | AllocSetRealloc (void *pointer, Size size) |
MemoryContext | AllocSetGetChunkContext (void *pointer) |
Size | AllocSetGetChunkSpace (void *pointer) |
bool | AllocSetIsEmpty (MemoryContext context) |
void | AllocSetStats (MemoryContext context, MemoryStatsPrintFunc printfunc, void *passthru, MemoryContextCounters *totals, bool print_to_stderr) |
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 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 | ||
) |
Definition at line 699 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().
MemoryContext AllocSetContextCreateInternal | ( | MemoryContext | parent, |
const char * | name, | ||
Size | minContextSize, | ||
Size | initBlockSize, | ||
Size | maxBlockSize | ||
) |
Definition at line 341 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, AllocSetContext::keeper, 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 603 of file aset.c.
References AllocSetIsValid, Assert(), AllocSetContext::blocks, context_freelists, AllocBlockData::endptr, AllocSetFreeList::first_free, free, AllocSetContext::freeListIndex, AllocBlockData::freeptr, AllocSetContext::header, MemoryContextData::isReset, AllocSetContext::keeper, 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 998 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().
|
inlinestatic |
Definition at line 271 of file aset.c.
References ALLOC_CHUNK_LIMIT, ALLOC_MINBITS, ALLOCSET_NUM_FREELISTS, Assert(), idx(), pg_leftmost_one_pos, pg_leftmost_one_pos32(), and StaticAssertDecl.
Referenced by AllocSetAlloc().
MemoryContext AllocSetGetChunkContext | ( | void * | pointer | ) |
Definition at line 1366 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 1395 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 1429 of file aset.c.
References AllocSetIsValid, Assert(), and MemoryContextData::isReset.
void* AllocSetRealloc | ( | void * | pointer, |
Size | size | ||
) |
Definition at line 1105 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 533 of file aset.c.
References ALLOC_BLOCKHDRSZ, AllocSetIsValid, Assert(), AllocSetContext::blocks, AllocBlockData::endptr, free, AllocSetContext::freelist, AllocBlockData::freeptr, AllocSetContext::initBlockSize, AllocSetContext::keeper, 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 1454 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.
|
static |
Definition at line 251 of file aset.c.
Referenced by AllocSetContextCreateInternal(), and AllocSetDelete().