Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a0cd954

Browse files
committed
Optimize GenerationAlloc() and SlabAlloc()
In a similar effort to 413c184, separate out the hot and cold paths in GenerationAlloc() and SlabAlloc() to avoid having to setup the stack frame for the hot path. This additionally adjusts how we use the GenerationContext's freeblock. Freeblock, when set, is now always empty and we only switch to using it when the current allocation request finds the current block does not have enough space and the freeblock is large enough to accomodate the allocation. This commit also adjusts GenerationFree() so that if we pfree the final allocation in the current generation block, we now mark that block as empty and keep it as the current block. Previously we free'd that block and set the current block to NULL. Doing that meant we needed a special case in GenerationAlloc to check if GenerationContext.block was NULL. So this both reduces free/malloc calls and reduces the work done in GenerationAlloc(). In passing, improve some comments in aset.c Discussion: https://postgr.es/m/CAApHDvpHVSJqqb4B4OZLixr=CotKq-eKkbwZqvZVo_biYvUvQA@mail.gmail.com
1 parent 07c36c1 commit a0cd954

File tree

3 files changed

+386
-277
lines changed

3 files changed

+386
-277
lines changed

src/backend/utils/mmgr/aset.c

+9-7
Original file line numberDiff line numberDiff line change
@@ -943,8 +943,9 @@ AllocSetAllocFromNewBlock(MemoryContext context, Size size, int flags,
943943

944944
/*
945945
* AllocSetAlloc
946-
* Returns pointer to allocated memory of given size or NULL if
947-
* request could not be completed; memory is added to the set.
946+
* Returns a pointer to allocated memory of given size or raises an ERROR
947+
* on allocation failure, or returns NULL when flags contains
948+
* MCXT_ALLOC_NO_OOM.
948949
*
949950
* No request may exceed:
950951
* MAXALIGN_DOWN(SIZE_MAX) - ALLOC_BLOCKHDRSZ - ALLOC_CHUNKHDRSZ
@@ -955,11 +956,12 @@ AllocSetAllocFromNewBlock(MemoryContext context, Size size, int flags,
955956
* return space that is marked NOACCESS - AllocSetRealloc has to beware!
956957
*
957958
* This function should only contain the most common code paths. Everything
958-
* else should be in pg_noinline helper functions, thus avoiding the overheads
959-
* creating a stack frame for the common cases. Allocating memory is often a
960-
* bottleneck in many workloads, so avoiding stack frame setup is worthwhile.
961-
* Helper functions should always directly return the newly allocated memory
962-
* so that we can just return that address directly as a tail call.
959+
* else should be in pg_noinline helper functions, thus avoiding the overhead
960+
* of creating a stack frame for the common cases. Allocating memory is often
961+
* a bottleneck in many workloads, so avoiding stack frame setup is
962+
* worthwhile. Helper functions should always directly return the newly
963+
* allocated memory so that we can just return that address directly as a tail
964+
* call.
963965
*/
964966
void *
965967
AllocSetAlloc(MemoryContext context, Size size, int flags)

0 commit comments

Comments
 (0)