Skip to content

Commit 6d2fd66

Browse files
committed
Push dedicated BumpBlocks to the tail of the blocks list
BumpContext relies on using the head block from its 'blocks' field to use as the current block to allocate new chunks to. When we receive an allocation request larger than allocChunkLimit, we place these chunks on a new dedicated block and, until now, we pushed the block onto the *head* of the 'blocks' list. This behavior caused the previous bump block to no longer be available for new normal-sized (non-large) allocations and would result in blocks only being partially filled if a large allocation request arrived before the block became full. Here adjust the code to push these dedicated blocks onto the *tail* of the blocks list so that the head block remains intact and available to be used by normal allocation request sizes until it becomes full. In passing, make the elog(ERROR) calls for the unsupported callbacks consistent. Likewise for the header comments for those functions. Discussion: https://postgr.es/m/CAApHDvp9___r-ayJj0nZ6GD3MeCGwGZ0_6ZptWpwj+zqHtmwCw@mail.gmail.com Discussion: https://postgr.es/m/CAApHDvqerXpzUnuDQfUEi3DZA+9=Ud9WSt3ruxN5b6PcOosx2g@mail.gmail.com
1 parent 2ea5d8b commit 6d2fd66

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/backend/utils/mmgr/bump.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,12 @@ BumpAllocLarge(MemoryContext context, Size size, int flags)
342342
randomize_mem((char *) MemoryChunkGetPointer(chunk), size);
343343
#endif
344344

345-
/* add the block to the list of allocated blocks */
346-
dlist_push_head(&set->blocks, &block->node);
345+
/*
346+
* Add the block to the tail of allocated blocks list. The current block
347+
* is left at the head of the list as it may still have space for
348+
* non-large allocations.
349+
*/
350+
dlist_push_tail(&set->blocks, &block->node);
347351

348352
#ifdef MEMORY_CONTEXT_CHECKING
349353
/* Ensure any padding bytes are marked NOACCESS. */
@@ -612,7 +616,7 @@ BumpBlockFree(BumpContext *set, BumpBlock *block)
612616
void
613617
BumpFree(void *pointer)
614618
{
615-
elog(ERROR, "pfree is not supported by the bump memory allocator");
619+
elog(ERROR, "%s is not supported by the bump memory allocator", "pfree");
616620
}
617621

618622
/*
@@ -638,10 +642,9 @@ BumpGetChunkContext(void *pointer)
638642
}
639643

640644
/*
641-
* BumpGetChunkSpace
642-
* Given a currently-allocated chunk, determine the total space
643-
* it occupies (including all memory-allocation overhead).
644-
*/
645+
* BumpGetChunkSpace
646+
* Unsupported.
647+
*/
645648
Size
646649
BumpGetChunkSpace(void *pointer)
647650
{

src/test/regress/expected/sysviews.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ select name, parent, total_bytes > 0, total_nblocks, free_bytes > 0, free_chunks
4747
from pg_backend_memory_contexts where name = 'Caller tuples';
4848
name | parent | ?column? | total_nblocks | ?column? | free_chunks
4949
---------------+----------------+----------+---------------+----------+-------------
50-
Caller tuples | TupleSort sort | t | 3 | t | 0
50+
Caller tuples | TupleSort sort | t | 2 | t | 0
5151
(1 row)
5252

5353
rollback;

0 commit comments

Comments
 (0)