Re: Safe memory allocation functions

Поиск
Список
Период
Сортировка
От Michael Paquier
Тема Re: Safe memory allocation functions
Дата
Msg-id CAB7nPqQnCkE9NqfAbDq+GMptEBFWo83dG3H00BDkfOaZ1V6HWQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Safe memory allocation functions  (Andres Freund <andres@2ndquadrant.com>)
Ответы Re: Safe memory allocation functions  (Robert Haas <robertmhaas@gmail.com>)
Список pgsql-hackers
On Tue, Jan 27, 2015 at 5:34 PM, Andres Freund <andres@2ndquadrant.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

Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Thom Brown
Дата:
Сообщение: Re: Parallel Seq Scan
Следующее
От: Kevin Grittner
Дата:
Сообщение: Re: pg_dump with both --serializable-deferrable and -j