On Tue, Jan 27, 2015 at 5:34 PM, Andres Freund <andres(at)2ndquadrant(dot)com> wrote:
> On 2015-01-27 17:27:53 +0900, Michael Paquier wrote:
>> Alvaro Herrera wrote:
>> >> So how about something like
>> >>
>> >> #define ALLOCFLAG_HUGE 0x01
>> >> #define ALLOCFLAG_NO_ERROR_ON_OOM 0x02
>> >> void *
>> >> MemoryContextAllocFlags(MemoryContext context, Size size, int flags);
>> The flag for huge allocations may be useful, but I don't actually see
>> much value in the flag ALLOC_NO_OOM if the stuff in aset.c returns
>> unconditionally NULL in case of an OOM and we let palloc complain
>> about an OOM when allocation returns NULL. Something I am missing
>> perhaps?
>
> I guess the idea is to have *user facing* MemoryContextAllocExtended()
> that can do both huge and no-oom allocations. Otherwise we need palloc
> like wrappers for all combinations.
> We're certainly not just going to ignore memory allocation failures
> generally in in MemoryContextAllocExtended()....
As a result of all the comments on this thread, here are 3 patches
implementing incrementally the different ideas from everybody:
1) 0001 modifies aset.c to return unconditionally NULL in case of an
OOM instead of reporting an error. All the OOM error reports are moved
to mcxt.c (MemoryContextAlloc* and palloc*)
2) 0002 adds the noerror routines for frontend and backend.
3) 0003 adds MemoryContextAllocExtended that can be called with the
following control flags:
#define ALLOC_HUGE 0x01 /* huge allocation */
#define ALLOC_ZERO 0x02 /* clear allocated memory */
#define ALLOC_NO_OOM 0x04 /* no failure if out-of-memory */
#define ALLOC_ALIGNED 0x08 /* request length suitable for MemSetLoop */
This groups MemoryContextAlloc, MemoryContextAllocHuge,
MemoryContextAllocZero and MemoryContextAllocZeroAligned under the
same central routine.
Regards,
--
Michael