PostgreSQL Source Code git master
|
#include "postgres.h"
#include "lib/ilist.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 | SlabContext |
struct | SlabBlock |
Macros | |
#define | Slab_BLOCKHDRSZ MAXALIGN(sizeof(SlabBlock)) |
#define | Slab_CONTEXT_HDRSZ(chunksPerBlock) sizeof(SlabContext) |
#define | SLAB_BLOCKLIST_COUNT 3 |
#define | SLAB_MAXIMUM_EMPTY_BLOCKS 10 |
#define | Slab_CHUNKHDRSZ sizeof(MemoryChunk) |
#define | SlabChunkGetPointer(chk) ((void *) (((char *) (chk)) + sizeof(MemoryChunk))) |
#define | SlabBlockGetChunk(slab, block, n) |
#define | SlabIsValid(set) (PointerIsValid(set) && IsA(set, SlabContext)) |
#define | SlabBlockIsValid(block) (PointerIsValid(block) && SlabIsValid((block)->slab)) |
Typedefs | |
typedef struct SlabContext | SlabContext |
typedef struct SlabBlock | SlabBlock |
#define Slab_CHUNKHDRSZ sizeof(MemoryChunk) |
#define Slab_CONTEXT_HDRSZ | ( | chunksPerBlock | ) | sizeof(SlabContext) |
#define SlabBlockGetChunk | ( | slab, | |
block, | |||
n | |||
) |
#define SlabBlockIsValid | ( | block | ) | (PointerIsValid(block) && SlabIsValid((block)->slab)) |
#define SlabChunkGetPointer | ( | chk | ) | ((void *) (((char *) (chk)) + sizeof(MemoryChunk))) |
#define SlabIsValid | ( | set | ) | (PointerIsValid(set) && IsA(set, SlabContext)) |
typedef struct SlabContext SlabContext |
void * SlabAlloc | ( | MemoryContext | context, |
Size | size, | ||
int | flags | ||
) |
Definition at line 630 of file slab.c.
References Assert(), SlabContext::blocklist, SlabContext::chunkSize, SlabContext::chunksPerBlock, SlabContext::curBlocklistIndex, dlist_delete_from(), dlist_head_element, dlist_is_empty(), dlist_push_head(), SlabBlock::nfree, SlabBlock::node, SlabAllocFromNewBlock(), SlabAllocInvalidSize(), SlabAllocSetupNewChunk(), SlabBlocklistIndex(), SlabFindNextBlockListIndex(), SlabGetNextFreeChunk(), SlabIsValid, and unlikely.
|
static |
Definition at line 539 of file slab.c.
References Assert(), SlabContext::blocklist, SlabContext::blockSize, SlabContext::chunksPerBlock, SlabContext::curBlocklistIndex, dclist_count(), dclist_pop_head_node(), dlist_container, dlist_is_empty(), dlist_push_head(), SlabContext::emptyblocks, SlabBlock::freehead, malloc, MemoryContextData::mem_allocated, MemoryContextAllocationFailure(), SlabBlock::nfree, SlabBlock::node, SlabBlock::nunused, SlabBlock::slab, SlabAllocSetupNewChunk(), SlabBlockGetChunk, SlabBlocklistIndex(), SlabGetNextFreeChunk(), unlikely, and SlabBlock::unused.
Referenced by SlabAlloc().
|
static |
Definition at line 606 of file slab.c.
References SlabContext::chunkSize, elog, and ERROR.
Referenced by SlabAlloc().
|
inlinestatic |
Definition at line 498 of file slab.c.
References Assert(), SlabContext::chunkSize, SlabContext::chunksPerBlock, SlabContext::fullChunkSize, MAXALIGN, MCTX_SLAB_ID, MemoryChunkGetPointer, MemoryChunkSetHdrMask(), Slab_CHUNKHDRSZ, SlabBlockGetChunk, VALGRIND_MAKE_MEM_NOACCESS, and VALGRIND_MAKE_MEM_UNDEFINED.
Referenced by SlabAlloc(), and SlabAllocFromNewBlock().
|
inlinestatic |
Definition at line 211 of file slab.c.
References Assert(), SlabContext::blocklist_shift, and SLAB_BLOCKLIST_COUNT.
Referenced by SlabAlloc(), SlabAllocFromNewBlock(), and SlabFree().
MemoryContext SlabContextCreate | ( | MemoryContext | parent, |
const char * | name, | ||
Size | blockSize, | ||
Size | chunkSize | ||
) |
Definition at line 322 of file slab.c.
References Assert(), SlabContext::blocklist, SlabContext::blocklist_shift, SlabContext::blockSize, SlabContext::chunkSize, SlabContext::chunksPerBlock, SlabContext::curBlocklistIndex, dclist_init(), dlist_init(), elog, SlabContext::emptyblocks, ereport, errcode(), errdetail(), errmsg(), ERROR, SlabContext::fullChunkSize, i, malloc, MAXALIGN, MCTX_SLAB_ID, MEMORYCHUNK_MAX_BLOCKOFFSET, MEMORYCHUNK_MAX_VALUE, MemoryContextCreate(), MemoryContextStats(), name, Slab_BLOCKHDRSZ, SLAB_BLOCKLIST_COUNT, Slab_CHUNKHDRSZ, Slab_CONTEXT_HDRSZ, StaticAssertDecl, and TopMemoryContext.
Referenced by for(), ReorderBufferAllocate(), and test_random().
void SlabDelete | ( | MemoryContext | context | ) |
|
static |
Definition at line 251 of file slab.c.
References SlabContext::blocklist, dlist_is_empty(), i, and SLAB_BLOCKLIST_COUNT.
Referenced by SlabAlloc(), and SlabFree().
void SlabFree | ( | void * | pointer | ) |
Definition at line 701 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 863 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 887 of file slab.c.
References Assert(), SlabContext::fullChunkSize, MemoryChunkGetBlock(), PointerGetMemoryChunk, SlabBlock::slab, Slab_CHUNKHDRSZ, SlabBlockIsValid, VALGRIND_MAKE_MEM_DEFINED, and VALGRIND_MAKE_MEM_NOACCESS.
|
inlinestatic |
Definition at line 271 of file slab.c.
References Assert(), SlabContext::chunksPerBlock, SlabBlock::freehead, SlabContext::fullChunkSize, SlabBlock::nfree, SlabBlock::nunused, SlabBlockGetChunk, SlabChunkGetPointer, SlabBlock::unused, and VALGRIND_MAKE_MEM_DEFINED.
Referenced by SlabAlloc(), and SlabAllocFromNewBlock().
bool SlabIsEmpty | ( | MemoryContext | context | ) |
Definition at line 912 of file slab.c.
References Assert(), MemoryContextData::mem_allocated, and SlabIsValid.
void * SlabRealloc | ( | void * | pointer, |
Size | size, | ||
int | flags | ||
) |
Definition at line 826 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 929 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.