pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Rowley <drowley@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Recompute allocChunkLimit when reusing an AllocSet context
Date: Mon, 19 Oct 2026 08:03:31 +0000
Message-ID: <E1xIiLD-00000002EYV-3w12@gemulon.postgresql.org> (raw)

Recompute allocChunkLimit when reusing an AllocSet context

AllocSet contexts with different maxBlockSize values can have the same
freeListIndex.  When reusing a context from one of the context_freelists,
we updated maxBlockSize, but we failed to adjust allocChunkLimit, even
though that ordinarily depends on maxBlockSize.  This could result in
some allocations being put on an external block when they shouldn't have
been, resulting in excessive malloc() calls, or if the allocChunkLimit was
left set higher than it should be, allocations could have resulted in
memory not being free()'d after pfree() due to the chunk having been put
on a multi-chunk block (these would still later be cleaned up when the
context is reset, so no memory leaks).

The repercussions of this are only inefficient use of memory and perhaps
some performance instability depending on which context happened to be
top of the freelist when a new AllocSet context was created.

To fix, we move the allocChunkLimit calculation code into a helper
function and call that to reset the allocChunkLimit when reusing a
context.

Author: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Donghang Lin <donghanglin@gmail.com>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/1D54961E-6BEF-411A-BFAD-610C3B18D7E7@gmail.com
Backpatch-through: 14

Branch
------
REL_14_STABLE

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

Modified Files
--------------
src/backend/utils/mmgr/aset.c | 77 +++++++++++++++++++++++++++++--------------
1 file changed, 52 insertions(+), 25 deletions(-)



view thread (7+ messages)

Message-ID: <E1xIiLD-00000002EYV-3w12@gemulon.postgresql.org>
Permalink:  ../E1xIiLD-00000002EYV-3w12@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xIiLD-00000002EYV-3w12@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: drowley@postgresql.org
  Subject: Re: pgsql: Recompute allocChunkLimit when reusing an AllocSet context
  In-Reply-To: <E1xIiLD-00000002EYV-3w12@gemulon.postgresql.org>
  References: <E1xIiLD-00000002EYV-3w12@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