Re: Safe memory allocation functions

Поиск
Список
Период
Сортировка
От Michael Paquier
Тема Re: Safe memory allocation functions
Дата
Msg-id CAB7nPqQka2dMENhRym3+JnFbgFFYwQz6i5mh1GqpxFC4zQoc2g@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Safe memory allocation functions  (Michael Paquier <michael.paquier@gmail.com>)
Ответы Re: Safe memory allocation functions  (Robert Haas <robertmhaas@gmail.com>)
Список pgsql-hackers
I wrote:
> Yes, this refactoring was good for testing actually...
Oops, I have been too hasty when sending previous patch, there was a
bug related to huge allocations. Patch correcting this bug is
attached.

Attached are as well two things I have used to test the new API:
- A hack refactoring the existing routines MemoryContextAlloc* to use
the extended API
- An extension with a function doing a direct call to the extended API
able to control the flags used:
CREATE FUNCTION blackhole_palloc(size bigint,
        is_huge bool,
        is_no_oom bool,
        is_zero bool,
        is_zero_aligned bool)

Here are some tests done on a small box of 384MB with direct calls of
the extended API:
=# create extension blackhole ;
CREATE EXTENSION
-- failure for normal allocation because size >= 1GB
=# select blackhole_palloc(1024 * 1024 * 1024, false, false, false, false);
ERROR:  XX000: invalid memory alloc request size 1073741824
LOCATION:  MemoryContextAllocExtended, mcxt.c:628
-- Failure of OOM because normal allocation can be done, but no memory
=# select blackhole_palloc(1024 * 1024 * 1024 - 1, false, false, false, false);
ERROR:  53200: out of memory
DETAIL:  Failed on request of size 1073741823.
LOCATION:  MemoryContextAllocExtended, mcxt.c:639
-- No failure, bypassing OOM error
=# select blackhole_palloc(1024 * 1024 * 1024 - 1, false, true, false, false);
 blackhole_palloc
------------------
 null
(1 row)
-- Huge allocation, no error because OOM error is bypassed
=# select blackhole_palloc(1024 * 1024 * 1024, true, true, false, false);
 blackhole_palloc
------------------
 null
(1 row)
-- OOM error, huge allocation failure
=# select blackhole_palloc(1024 * 1024 * 1024, true, false, false, false);
ERROR:  53200: out of memory
DETAIL:  Failed on request of size 1073741824.
LOCATION:  MemoryContextAllocExtended, mcxt.c:639
-- Assertion failure, zero and zero aligned cannot be called at the same time
=# select blackhole_palloc(1024 * 1024, false, false, true, true);
server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
--
Michael

Вложения

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: jsonb, unicode escapes and escaped backslashes
Следующее
От: Tom Lane
Дата:
Сообщение: Re: jsonb, unicode escapes and escaped backslashes