mirror of
https://github.com/postgres/postgres.git
synced 2025-11-19 13:42:17 +03:00
Permit super-MaxAllocSize allocations with MemoryContextAllocHuge().
The MaxAllocSize guard is convenient for most callers, because it reduces the need for careful attention to overflow, data type selection, and the SET_VARSIZE() limit. A handful of callers are happy to navigate those hazards in exchange for the ability to allocate a larger chunk. Introduce MemoryContextAllocHuge() and repalloc_huge(). Use this in tuplesort.c and tuplestore.c, enabling internal sorts of up to INT_MAX tuples, a factor-of-48 increase. In particular, B-tree index builds can now benefit from much-larger maintenance_work_mem settings. Reviewed by Stephen Frost, Simon Riggs and Jeff Janes.
This commit is contained in:
@@ -458,6 +458,7 @@ AllocSetContextCreate(MemoryContext parent,
|
||||
maxBlockSize = MAXALIGN(maxBlockSize);
|
||||
if (maxBlockSize < initBlockSize)
|
||||
maxBlockSize = initBlockSize;
|
||||
Assert(AllocHugeSizeIsValid(maxBlockSize)); /* must be safe to double */
|
||||
context->initBlockSize = initBlockSize;
|
||||
context->maxBlockSize = maxBlockSize;
|
||||
context->nextBlockSize = initBlockSize;
|
||||
@@ -643,6 +644,10 @@ AllocSetDelete(MemoryContext context)
|
||||
* AllocSetAlloc
|
||||
* Returns pointer to allocated memory of given size; memory is added
|
||||
* to the set.
|
||||
*
|
||||
* No request may exceed:
|
||||
* MAXALIGN_DOWN(SIZE_MAX) - ALLOC_BLOCKHDRSZ - ALLOC_CHUNKHDRSZ
|
||||
* All callers use a much-lower limit.
|
||||
*/
|
||||
static void *
|
||||
AllocSetAlloc(MemoryContext context, Size size)
|
||||
|
||||
Reference in New Issue
Block a user