pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@postgresql.org
Subject: pgsql: Add macros to make AllocSetContextCreate() calls simpler and saf
Date: Sat, 27 Aug 2016 21:50:57 +0000
Message-ID: <E1bdlVB-0004lu-6r@gemulon.postgresql.org> (raw)
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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.1472321324@sss.pgh.pa.us>

Branch
------
master

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

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                    |  8 ++----
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, 206 insertions(+), 522 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


view thread (2+ messages)

Message-ID: <E1bdlVB-0004lu-6r@gemulon.postgresql.org>
Permalink:  ../E1bdlVB-0004lu-6r@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1bdlVB-0004lu-6r@gemulon.postgresql.org

 · 

reply

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: Add macros to make AllocSetContextCreate() calls simpler and saf
  In-Reply-To: <E1bdlVB-0004lu-6r@gemulon.postgresql.org>
  References: <E1bdlVB-0004lu-6r@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