From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Store GUC data in a memory context, instead of using malloc().
Date: Fri, 14 Oct 2022 16:36:28 +0000
Message-ID: <E1ojNff-002MLw-Og@gemulon.postgresql.org> (raw)
Store GUC data in a memory context, instead of using malloc().
The only real argument for using malloc directly was that we needed
the ability to not throw error on OOM; but mcxt.c grew that feature
awhile ago.
Keeping the data in a memory context improves accountability and
debuggability --- for example, without this it's almost impossible
to detect memory leaks in the GUC code with anything less costly
than valgrind. Moreover, the next patch in this series will add a
hash table for GUC lookup, and it'd be pretty silly to be using
palloc-dependent hash facilities alongside malloc'd storage of the
underlying data.
This is a bit invasive though, in particular causing an API break
for GUC check hooks that want to modify the GUC's value or use an
"extra" data structure. They must now use guc_malloc() and
guc_free() instead of malloc() and free(). Failure to change
affected code will result in assertion failures or worse; but
thanks to recent effort in the mcxt infrastructure, it shouldn't
be too hard to diagnose such oversights (at least in assert-enabled
builds).
One note is that this changes ParseLongOption() to return short-lived
palloc'd not malloc'd data. There wasn't any caller for which the
previous definition was better.
Discussion: https://postgr.es/m/2982579.1662416866@sss.pgh.pa.us
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/407b50f2d421bca5b134a0033176ea8f8c68dc6b
Modified Files
--------------
src/backend/bootstrap/bootstrap.c | 4 +-
src/backend/commands/tablespace.c | 4 +-
src/backend/commands/variable.c | 34 +++---
src/backend/postmaster/postmaster.c | 4 +-
src/backend/replication/syncrep.c | 4 +-
src/backend/tcop/postgres.c | 4 +-
src/backend/utils/adt/datetime.c | 7 +-
src/backend/utils/cache/ts_cache.c | 6 +-
src/backend/utils/misc/README | 15 ++-
src/backend/utils/misc/guc.c | 225 ++++++++++++++++++++++--------------
src/backend/utils/misc/tzparser.c | 2 +-
src/include/utils/guc.h | 1 +
src/pl/plpgsql/src/pl_handler.c | 2 +-
13 files changed, 185 insertions(+), 127 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: pgsql: Store GUC data in a memory context, instead of using malloc().
In-Reply-To: <E1ojNff-002MLw-Og@gemulon.postgresql.org>
References: <E1ojNff-002MLw-Og@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox