Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita0cd954

Browse files
committed
Optimize GenerationAlloc() and SlabAlloc()
In a similar effort to413c184, separate out the hot and cold paths inGenerationAlloc() and SlabAlloc() to avoid having to setup the stack framefor 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 itwhen the current allocation request finds the current block does not haveenough space and the freeblock is large enough to accomodate theallocation.This commit also adjusts GenerationFree() so that if we pfree the finalallocation in the current generation block, we now mark that block asempty and keep it as the current block. Previously we free'd that blockand set the current block to NULL. Doing that meant we needed a specialcase in GenerationAlloc to check if GenerationContext.block was NULL.So this both reduces free/malloc calls and reduces the work done inGenerationAlloc().In passing, improve some comments in aset.cDiscussion:https://postgr.es/m/CAApHDvpHVSJqqb4B4OZLixr=CotKq-eKkbwZqvZVo_biYvUvQA@mail.gmail.com
1 parent07c36c1 commita0cd954

File tree

3 files changed

+386
-277
lines changed

3 files changed

+386
-277
lines changed

‎src/backend/utils/mmgr/aset.c

Lines changed: 9 additions & 7 deletions
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(MemoryContextcontext,Sizesize,intflags)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp