pgsql: Add macros to make AllocSetContextCreate() calls simpler and saf

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Add macros to make AllocSetContextCreate() calls simpler and saf
Date: 2016-08-27 21:50:57
Message-ID: E1bdlVB-0004lv-6v@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Add macros to make AllocSetContextCreate() calls simpler and safer.

I found that half a dozen (nearly 5%) of our AllocSetContextCreate calls
had typos in the context-sizing parameters. While none of these led to
especially significant problems, they did create minor inefficiencies,
and it's now clear that expecting people to copy-and-paste those calls
accurately is not a great idea. Let's reduce the risk of future errors
by introducing single macros that encapsulate the common use-cases.
Three such macros are enough to cover all but two special-purpose contexts;
those two calls can be left as-is, I think.

While this patch doesn't in itself improve matters for third-party
extensions, it doesn't break anything for them either, and they can
gradually adopt the simplified notation over time.

In passing, change TopMemoryContext to use the default allocation
parameters. Formerly it could only be extended 8K at a time. That was
probably reasonable when this code was written; but nowadays we create
many more contexts than we did then, so that it's not unusual to have a
couple hundred K in TopMemoryContext, even without considering various
dubious code that sticks other things there. There seems no good reason
not to let it use growing blocks like most other contexts.

Back-patch to 9.6, mostly because that's still close enough to HEAD that
it's easy to do so, and keeping the branches in sync can be expected to
avoid some future back-patching pain. The bugs fixed by these changes
don't seem to be significant enough to justify fixing them further back.

Discussion: <21072(dot)1472321324(at)sss(dot)pgh(dot)pa(dot)us>

Branch
------
REL9_6_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/b9fe6cbc81ea120a39be755f23d6615486c11618

Modified Files
--------------
contrib/bloom/blinsert.c | 8 ++----
contrib/dblink/dblink.c | 4 +--
contrib/file_fdw/file_fdw.c | 4 +--
contrib/pg_trgm/trgm_regexp.c | 4 +--
contrib/postgres_fdw/postgres_fdw.c | 20 ++++----------
contrib/sepgsql/uavc.c | 6 ++---
contrib/test_decoding/test_decoding.c | 4 +--
src/backend/access/brin/brin.c | 16 +++--------
src/backend/access/brin/brin_tuple.c | 4 +--
src/backend/access/common/printtup.c | 4 +--
src/backend/access/gin/ginbtree.c | 4 +--
src/backend/access/gin/ginfast.c | 4 +--
src/backend/access/gin/gininsert.c | 12 +++------
src/backend/access/gin/ginscan.c | 8 ++----
src/backend/access/gin/ginvacuum.c | 4 +--
src/backend/access/gin/ginxlog.c | 5 ++--
src/backend/access/gist/gist.c | 8 ++----
src/backend/access/gist/gistscan.c | 8 ++----
src/backend/access/heap/rewriteheap.c | 4 +--
src/backend/access/nbtree/nbtree.c | 4 +--
src/backend/access/nbtree/nbtutils.c | 6 ++---
src/backend/access/spgist/spginsert.c | 8 ++----
src/backend/access/spgist/spgscan.c | 4 +--
src/backend/access/spgist/spgxlog.c | 4 +--
src/backend/access/transam/multixact.c | 6 ++---
src/backend/access/transam/parallel.c | 12 +++------
src/backend/access/transam/xact.c | 8 ++----
src/backend/access/transam/xlog.c | 4 +--
src/backend/access/transam/xloginsert.c | 4 +--
src/backend/bootstrap/bootstrap.c | 4 +--
src/backend/catalog/objectaddress.c | 4 +--
src/backend/commands/analyze.c | 12 +++------
src/backend/commands/cluster.c | 4 +--
src/backend/commands/copy.c | 8 ++----
src/backend/commands/event_trigger.c | 8 ++----
src/backend/commands/indexcmds.c | 4 +--
src/backend/commands/policy.c | 4 +--
src/backend/commands/trigger.c | 8 ++----
src/backend/commands/vacuum.c | 4 +--
src/backend/executor/execUtils.c | 12 +++------
src/backend/executor/functions.c | 4 +--
src/backend/executor/nodeFunctionscan.c | 4 +--
src/backend/executor/nodeHash.c | 8 ++----
src/backend/executor/nodeRecursiveunion.c | 8 ++----
src/backend/executor/nodeSetOp.c | 8 ++----
src/backend/executor/nodeSubplan.c | 8 ++----
src/backend/executor/nodeUnique.c | 4 +--
src/backend/executor/nodeWindowAgg.c | 18 +++++--------
src/backend/executor/spi.c | 23 +++++-----------
src/backend/executor/tqueue.c | 4 +--
src/backend/libpq/be-fsstubs.c | 4 +--
src/backend/libpq/hba.c | 14 +++-------
src/backend/optimizer/geqo/geqo_eval.c | 4 +--
src/backend/optimizer/util/clauses.c | 8 ++----
src/backend/postmaster/autovacuum.c | 24 +++++------------
src/backend/postmaster/bgwriter.c | 4 +--
src/backend/postmaster/checkpointer.c | 4 +--
src/backend/postmaster/pgstat.c | 4 +--
src/backend/postmaster/postmaster.c | 4 +--
src/backend/postmaster/walwriter.c | 4 +--
src/backend/replication/logical/logical.c | 6 ++---
src/backend/replication/logical/reorderbuffer.c | 6 ++---
src/backend/replication/logical/snapbuild.c | 4 +--
src/backend/replication/walsender.c | 4 +--
src/backend/storage/buffer/localbuf.c | 4 +--
src/backend/storage/file/reinit.c | 4 +--
src/backend/storage/lmgr/lwlock.c | 4 +--
src/backend/storage/smgr/md.c | 10 +++----
src/backend/tcop/postgres.c | 8 ++----
src/backend/tsearch/spell.c | 4 +--
src/backend/utils/adt/array_expanded.c | 4 +--
src/backend/utils/adt/arrayfuncs.c | 8 ++----
src/backend/utils/adt/jsonfuncs.c | 16 +++--------
src/backend/utils/adt/xml.c | 6 ++---
src/backend/utils/cache/catcache.c | 4 +--
src/backend/utils/cache/evtcache.c | 4 +--
src/backend/utils/cache/plancache.c | 35 ++++++++-----------------
src/backend/utils/cache/relcache.c | 18 +++----------
src/backend/utils/cache/ts_cache.c | 4 +--
src/backend/utils/cache/typcache.c | 8 ++----
src/backend/utils/fmgr/funcapi.c | 4 +--
src/backend/utils/hash/dynahash.c | 4 +--
src/backend/utils/init/postinit.c | 4 +--
src/backend/utils/misc/guc-file.l | 4 +--
src/backend/utils/misc/tzparser.c | 4 +--
src/backend/utils/mmgr/aset.c | 6 ++++-
src/backend/utils/mmgr/mcxt.c | 11 +++-----
src/backend/utils/mmgr/portalmem.c | 12 +++------
src/backend/utils/sort/tuplesort.c | 8 ++----
src/include/utils/memutils.h | 14 +++++++++-
src/pl/plperl/plperl.c | 12 +++------
src/pl/plpgsql/src/pl_comp.c | 10 +++----
src/pl/plpgsql/src/pl_exec.c | 4 +--
src/pl/plpython/plpy_cursorobject.c | 8 ++----
src/pl/plpython/plpy_main.c | 8 ++----
src/pl/plpython/plpy_procedure.c | 4 +--
src/pl/plpython/plpy_spi.c | 8 ++----
src/pl/plpython/plpy_typeio.c | 8 ++----
src/pl/tcl/pltcl.c | 4 +--
99 files changed, 205 insertions(+), 519 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2016-08-28 16:37:32 pgsql: Update 9.6 release notes through today.
Previous Message Andres Freund 2016-08-26 22:00:26 Re: pgsql: Change the way that LWLocks for extensions are allocated.