From: | Michael Paquier <michael(dot)paquier(at)gmail(dot)com> |
---|---|
To: | PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Safe memory allocation functions |
Date: | 2015-01-13 06:54:30 |
Message-ID: | CAB7nPqTvECYmsu6hWRtASivNtBnTBzzSXFmvbaZ2-4+jHa=sNw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi all,
For the last couple of weeks it has been mentioned a couple of times
that it would be useful to have a set of palloc APIs able to return
NULL on OOM to allow certain code paths to not ERROR and to take
another route when memory is under pressure. This has been for example
mentioned on the FPW compression thread or here:
http://www.postgresql.org/message-id/CAB7nPqRbewhSbJ_tkAogtpcMrxYJsvKKB9p030d0TpijB4t3YA@mail.gmail.com
Attached is a patch adding the following set of functions for frontend
and backends returning NULL instead of reporting ERROR when allocation
fails:
- palloc_safe
- palloc0_safe
- repalloc_safe
This has simply needed some refactoring in aset.c to set up the new
functions by passing an additional control flag, and I didn't think
that adding a new safe version for AllocSetContextCreate was worth it.
Those APIs are not called anywhere yet, but I could for example write
a small extension for that that could be put in src/test/modules or
publish on github in my plugin repo. Also, I am not sure if this is
material for 9.5, even if the patch is not complicated, but let me
know if you are interested in it and I'll add it to the next CF.
Regards,
--
Michael
Attachment | Content-Type | Size |
---|---|---|
20150113_palloc_safe.patch | text/x-diff | 27.6 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2015-01-13 07:24:51 | Re: Safe memory allocation functions |
Previous Message | Etsuro Fujita | 2015-01-13 05:51:00 | Re: Comment typo in src/backend/executor/execMain.c |