pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andres Freund <andres@anarazel.de>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: Getting better results from valgrind leak tracking
Date: Wed, 17 Mar 2021 22:33:59 -0400
Message-ID: <3665254.1616034839@sss.pgh.pa.us> (raw)
In-Reply-To: <20210318020519.4ok4q7sgjt536u36@alap3.anarazel.de>
References: <20210317023101.anvejcfotwka6gaa@alap3.anarazel.de>
	<3479700.1615950107@sss.pgh.pa.us>
	<cea52c41-f005-4ec3-8dd8-4d12dbfbe9f6@www.fastmail.com>
	<20210317055718.v6qs3ltzrformqoa@alap3.anarazel.de>
	<3508520.1615990604@sss.pgh.pa.us>
	<3c52ffa1-d46d-4838-9e67-a9760399ecee@www.fastmail.com>
	<20210317181531.7oggpqevzz6bka3g@alap3.anarazel.de>
	<3617762.1616018856@sss.pgh.pa.us>
	<20210318002656.7fezwucw4qdlivzk@alap3.anarazel.de>
	<3662652.1616031048@sss.pgh.pa.us>
	<20210318020519.4ok4q7sgjt536u36@alap3.anarazel.de>

Andres Freund <andres@anarazel.de> writes:
> On 2021-03-17 21:30:48 -0400, Tom Lane wrote:
>> I believe I've just tracked down the cause of that.  Those errors
>> are (as far as I've seen) only happening in parallel workers, and
>> the reason is this gem in RestoreGUCState: ...

> Ouch. At least it's a short lived issue rather than something permanently
> leaking memory on every SIGHUP...

Yeah.  This leak is really insignificant in practice, although I'm
suspicious that randomly init'ing GUCs like this might have semantic
issues that we've not detected yet.

>> I've not yet tried to grok the comment that purports to justify it,
>> but I fail to see why it'd ever be useful to drop values inherited
>> from the postmaster.

> I can't really make sense of it either. I think it may be trying to
> restore the GUC state to what it would have been in postmaster,
> disregarding all the settings that were set as part of PostgresInit()
> etc?

At least in a non-EXEC_BACKEND build, the most reliable way to reproduce
the postmaster's settings is to do nothing whatsoever.  And I think the
same is true for EXEC_BACKEND, really, because the guc.c subsystem is
responsible for restoring what would have been the inherited-via-fork
settings.  So I'm really not sure what this is on about, and I'm too
tired to try to figure it out tonight.

In other news, I found that there's a genuine leak in
RelationBuildLocalRelation: RelationInitTableAccessMethod
was added in a spot where CurrentMemoryContext is CacheMemoryContext,
which is bad because it does a syscache lookup that can lead to
a table access which can leak some memory.  Seems easy to fix though.

The plpgsql situation looks like a mess.  As a short-term answer,
I'm inclined to recommend adding an exclusion that will ignore anything
allocated within plpgsql_compile().  Doing better will require a fair
amount of rewriting.  (Although I suppose we could also consider adding
an on_proc_exit callback that runs through and frees all the function
cache entries.)

			regards, tom lane





view thread (23+ messages)  latest in thread

Message-ID: <3665254.1616034839@sss.pgh.pa.us>
Permalink:  ../3665254.1616034839@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3665254.1616034839@sss.pgh.pa.us

 · 

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-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, andres@anarazel.de, robertmhaas@gmail.com
  Subject: Re: Getting better results from valgrind leak tracking
  In-Reply-To: <3665254.1616034839@sss.pgh.pa.us>
  References: <20210317023101.anvejcfotwka6gaa@alap3.anarazel.de> <3479700.1615950107@sss.pgh.pa.us> <cea52c41-f005-4ec3-8dd8-4d12dbfbe9f6@www.fastmail.com> <20210317055718.v6qs3ltzrformqoa@alap3.anarazel.de> <3508520.1615990604@sss.pgh.pa.us> <3c52ffa1-d46d-4838-9e67-a9760399ecee@www.fastmail.com> <20210317181531.7oggpqevzz6bka3g@alap3.anarazel.de> <3617762.1616018856@sss.pgh.pa.us> <20210318002656.7fezwucw4qdlivzk@alap3.anarazel.de> <3662652.1616031048@sss.pgh.pa.us> <20210318020519.4ok4q7sgjt536u36@alap3.anarazel.de> <3665254.1616034839@sss.pgh.pa.us>

* 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