diff options
author | Noah Misch <noah@leadboat.com> | 2013-06-27 14:53:57 -0400 |
---|---|---|
committer | Noah Misch <noah@leadboat.com> | 2013-06-27 14:53:57 -0400 |
commit | 263865a48973767ce8ed7b7788059a38a24a9f37 (patch) | |
tree | 282d6522ada24adc923ea869c01b9d94f02685db /src/include/utils/memutils.h | |
parent | 9ef86cd994e9f2a684996df994d4657e84a6c0bb (diff) |
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.
Diffstat (limited to 'src/include/utils/memutils.h')
-rw-r--r-- | src/include/utils/memutils.h | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/include/utils/memutils.h b/src/include/utils/memutils.h index 08851bb2c4b..9acd825e499 100644 --- a/src/include/utils/memutils.h +++ b/src/include/utils/memutils.h @@ -21,26 +21,30 @@ /* - * MaxAllocSize - * Quasi-arbitrary limit on size of allocations. + * MaxAllocSize, MaxAllocHugeSize + * Quasi-arbitrary limits on size of allocations. * * Note: - * There is no guarantee that allocations smaller than MaxAllocSize - * will succeed. Allocation requests larger than MaxAllocSize will - * be summarily denied. + * There is no guarantee that smaller allocations will succeed, but + * larger requests will be summarily denied. * - * XXX This is deliberately chosen to correspond to the limiting size - * of varlena objects under TOAST. See VARSIZE_4B() and related macros - * in postgres.h. Many datatypes assume that any allocatable size can - * be represented in a varlena header. - * - * XXX Also, various places in aset.c assume they can compute twice an - * allocation's size without overflow, so beware of raising this. + * palloc() enforces MaxAllocSize, chosen to correspond to the limiting size + * of varlena objects under TOAST. See VARSIZE_4B() and related macros in + * postgres.h. Many datatypes assume that any allocatable size can be + * represented in a varlena header. This limit also permits a caller to use + * an "int" variable for an index into or length of an allocation. Callers + * careful to avoid these hazards can access the higher limit with + * MemoryContextAllocHuge(). Both limits permit code to assume that it may + * compute twice an allocation's size without overflow. */ #define MaxAllocSize ((Size) 0x3fffffff) /* 1 gigabyte - 1 */ #define AllocSizeIsValid(size) ((Size) (size) <= MaxAllocSize) +#define MaxAllocHugeSize ((Size) -1 >> 1) /* SIZE_MAX / 2 */ + +#define AllocHugeSizeIsValid(size) ((Size) (size) <= MaxAllocHugeSize) + /* * All chunks allocated by any memory context manager are required to be * preceded by a StandardChunkHeader at a spacing of STANDARDCHUNKHEADERSIZE. |