pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas Munro <tmunro@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Use MemoryContext API for regex memory management.
Date: Sat, 08 Apr 2023 10:18:13 +0000
Message-ID: <E1pl5e7-0021kv-PC@gemulon.postgresql.org> (raw)

Use MemoryContext API for regex memory management.

Previously, regex_t objects' memory was managed with malloc() and free()
directly.  Switch to palloc()-based memory management instead.
Advantages:

 * memory used by cached regexes is now visible with MemoryContext
   observability tools

 * cleanup can be done automatically in certain failure modes
   (something that later commits will take advantage of)

 * cleanup can be done in bulk

On the downside, there may be more fragmentation (wasted memory) due to
per-regex MemoryContext objects.  This is a problem shared with other
cached objects in PostgreSQL and can probably be improved with later
tuning.

Thanks to Noah Misch for suggesting this general approach, which
unblocks later work on interrupts.

Suggested-by: Noah Misch <noah@leadboat.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CA%2BhUKGK3PGKwcKqzoosamn36YW-fsuTdOPPF1i_rtEO%3DnEYKSg%40mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/bea3d7e3831fa6a1395eadbad7d97cebc7aa8aee

Modified Files
--------------
src/backend/regex/regprefix.c  |  2 +-
src/backend/utils/adt/regexp.c | 57 ++++++++++++++++++++++++++++++------------
src/include/regex/regcustom.h  |  6 ++---
3 files changed, 45 insertions(+), 20 deletions(-)



Message-ID: <E1pl5e7-0021kv-PC@gemulon.postgresql.org>
Permalink:  ../E1pl5e7-0021kv-PC@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1pl5e7-0021kv-PC@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 using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: tmunro@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Use MemoryContext API for regex memory management.
  In-Reply-To: <E1pl5e7-0021kv-PC@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