pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alexander Korotkov <akorotkov@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Avoid recursion in MemoryContext functions
Date: Fri, 08 Mar 2024 11:19:14 +0000
Message-ID: <E1riYFt-002i1D-UI@gemulon.postgresql.org> (raw)

Avoid recursion in MemoryContext functions

You might run out of stack space with recursion, which is not nice in
functions that might be used e.g. at cleanup after transaction
abort. MemoryContext contains pointer to parent and siblings, so we
can traverse a tree of contexts iteratively, without using
stack. Refactor the functions to do that.

MemoryContextStats() still recurses, but it now has a limit to how
deep it recurses. Once the limit is reached, it prints just a summary
of the rest of the hierarchy, similar to how it summarizes contexts
with lots of children. That seems good anyway, because a context dump
with hundreds of nested contexts isn't very readable.

Report by Egor Chindyaskin and Alexander Lakhin.

Discussion: https://postgr.es/m/1672760457.940462079%40f306.i.mail.ru
Author: Heikki Linnakangas
Reviewed-by: Robert Haas, Andres Freund, Alexander Korotkov, Tom Lane

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/4c1973fcaecd9ef11de14ac55d3ec1432f6b82dc

Modified Files
--------------
src/backend/utils/mmgr/mcxt.c | 269 +++++++++++++++++++++++++++++-------------
src/include/utils/memutils.h  |   3 +-
2 files changed, 190 insertions(+), 82 deletions(-)



view thread (2+ messages)

Message-ID: <E1riYFt-002i1D-UI@gemulon.postgresql.org>
Permalink:  ../E1riYFt-002i1D-UI@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1riYFt-002i1D-UI@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: akorotkov@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Avoid recursion in MemoryContext functions
  In-Reply-To: <E1riYFt-002i1D-UI@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