40#define MaxAllocSize ((Size) 0x3fffffff)
42#define AllocSizeIsValid(size) ((Size) (size) <= MaxAllocSize)
45#define MaxAllocHugeSize (SIZE_MAX / 2)
47#define InvalidAllocSize SIZE_MAX
49#define AllocHugeSizeIsValid(size) ((Size) (size) <= MaxAllocHugeSize)
91 int max_level,
int max_children,
92 bool print_to_stderr);
96#ifdef MEMORY_CONTEXT_CHECKING
101#define MemoryContextCopyAndSetIdentifier(cxt, id) \
102 MemoryContextSetIdentifier(cxt, MemoryContextStrdup(cxt, id))
123#ifdef HAVE__BUILTIN_CONSTANT_P
124#define AllocSetContextCreate(parent, name, ...) \
125 (StaticAssertExpr(__builtin_constant_p(name), \
126 "memory context names must be constant strings"), \
127 AllocSetContextCreateInternal(parent, name, __VA_ARGS__))
129#define AllocSetContextCreate \
130 AllocSetContextCreateInternal
157#define ALLOCSET_DEFAULT_MINSIZE 0
158#define ALLOCSET_DEFAULT_INITSIZE (8 * 1024)
159#define ALLOCSET_DEFAULT_MAXSIZE (8 * 1024 * 1024)
160#define ALLOCSET_DEFAULT_SIZES \
161 ALLOCSET_DEFAULT_MINSIZE, ALLOCSET_DEFAULT_INITSIZE, ALLOCSET_DEFAULT_MAXSIZE
167#define ALLOCSET_SMALL_MINSIZE 0
168#define ALLOCSET_SMALL_INITSIZE (1 * 1024)
169#define ALLOCSET_SMALL_MAXSIZE (8 * 1024)
170#define ALLOCSET_SMALL_SIZES \
171 ALLOCSET_SMALL_MINSIZE, ALLOCSET_SMALL_INITSIZE, ALLOCSET_SMALL_MAXSIZE
177#define ALLOCSET_START_SMALL_SIZES \
178 ALLOCSET_SMALL_MINSIZE, ALLOCSET_SMALL_INITSIZE, ALLOCSET_DEFAULT_MAXSIZE
187#define ALLOCSET_SEPARATE_THRESHOLD 8192
189#define SLAB_DEFAULT_BLOCK_SIZE (8 * 1024)
190#define SLAB_LARGE_BLOCK_SIZE (8 * 1024 * 1024)
221 const unsigned char *p = (
const unsigned char *) ptr;
222 const unsigned char *end = &p[
len];
223 const unsigned char *aligned_end = (
const unsigned char *)
224 ((uintptr_t) end & (~(
sizeof(size_t) - 1)));
226 if (
len <
sizeof(
size_t))
237 if (
len <
sizeof(
size_t) * 8)
240 while (((uintptr_t) p & (
sizeof(size_t) - 1)) != 0)
254 for (; p < aligned_end; p +=
sizeof(size_t))
256 if (*(
size_t *) p != 0)
272 while (((uintptr_t) p & (
sizeof(size_t) - 1)) != 0)
291 for (; p < aligned_end - (
sizeof(size_t) * 7); p +=
sizeof(size_t) * 8)
293 if ((((
size_t *) p)[0] != 0) | (((
size_t *) p)[1] != 0) |
294 (((
size_t *) p)[2] != 0) | (((
size_t *) p)[3] != 0) |
295 (((
size_t *) p)[4] != 0) | (((
size_t *) p)[5] != 0) |
296 (((
size_t *) p)[6] != 0) | (((
size_t *) p)[7] != 0))
306 for (; p < aligned_end; p +=
sizeof(size_t))
308 if (*(
size_t *) p != 0)
PGDLLIMPORT MemoryContext CurTransactionContext
bool MemoryContextIsEmpty(MemoryContext context)
void MemoryContextMemConsumed(MemoryContext context, MemoryContextCounters *consumed)
void MemoryContextReset(MemoryContext context)
PGDLLIMPORT MemoryContext MessageContext
PGDLLIMPORT MemoryContext TopMemoryContext
PGDLLIMPORT MemoryContext TopTransactionContext
void HandleLogMemoryContextInterrupt(void)
void MemoryContextSetParent(MemoryContext context, MemoryContext new_parent)
Size GetMemoryChunkSpace(void *pointer)
void MemoryContextDeleteChildren(MemoryContext context)
MemoryContext GetMemoryChunkContext(void *pointer)
PGDLLIMPORT MemoryContext PostmasterContext
void MemoryContextStatsDetail(MemoryContext context, int max_level, int max_children, bool print_to_stderr)
Size MemoryContextMemAllocated(MemoryContext context, bool recurse)
void MemoryContextStats(MemoryContext context)
MemoryContext SlabContextCreate(MemoryContext parent, const char *name, Size blockSize, Size chunkSize)
void MemoryContextInit(void)
MemoryContext BumpContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
PGDLLIMPORT MemoryContext CacheMemoryContext
MemoryContext MemoryContextGetParent(MemoryContext context)
void ProcessLogMemoryContextInterrupt(void)
PGDLLIMPORT MemoryContext PortalContext
MemoryContext GenerationContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
static bool pg_memory_is_all_zeros(const void *ptr, size_t len)
void MemoryContextDelete(MemoryContext context)
void MemoryContextAllowInCriticalSection(MemoryContext context, bool allow)
void MemoryContextResetChildren(MemoryContext context)
void MemoryContextSetIdentifier(MemoryContext context, const char *id)
void MemoryContextResetOnly(MemoryContext context)
PGDLLIMPORT MemoryContext ErrorContext
MemoryContext AllocSetContextCreateInternal(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)