From: Andres Freund <andres@anarazel.de>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: Getting better results from valgrind leak tracking
Date: Wed, 17 Mar 2021 20:02:50 -0700
Message-ID: <20210318030250.xlqxcppknzrakcs5@alap3.anarazel.de> (raw)
In-Reply-To: <3482163.1615953715@sss.pgh.pa.us>
References: <3471359.1615937770@sss.pgh.pa.us>
<20210317023101.anvejcfotwka6gaa@alap3.anarazel.de>
<3479700.1615950107@sss.pgh.pa.us>
<cea52c41-f005-4ec3-8dd8-4d12dbfbe9f6@www.fastmail.com>
<3482163.1615953715@sss.pgh.pa.us>
Hi,
On 2021-03-17 00:01:55 -0400, Tom Lane wrote:
> As for the particular point about ParallelBlockTableScanWorkerData,
> I agree with your question to David about why that's in TableScanDesc
> not HeapScanDesc, but I can't get excited about it not being freed in
> heap_endscan. That's mainly because I do not believe that anything as
> complex as a heap or indexscan should be counted on to be zero-leakage.
> The right answer is to not do such operations in long-lived contexts.
> So if we're running such a thing while switched into CacheContext,
> *that* is the bug, not that heap_endscan didn't free this particular
> allocation.
I agree that it's a bad idea to do scans in non-transient contexts. It
does however seems like there's a number of places that do...
I added the following hacky definition of "permanent" contexts
/*
* NB: Only for assertion use.
*
* TopMemoryContext itself obviously is permanent. Treat CacheMemoryContext
* and all its children as permanent too.
*
* XXX: Might be worth adding this as an explicit flag on the context?
*/
bool
MemoryContextIsPermanent(MemoryContext c)
{
if (c == TopMemoryContext)
return true;
while (c)
{
if (c == CacheMemoryContext)
return true;
c = c->parent;
}
return false;
}
and checked that the CurrentMemoryContext is not permanent in
SearchCatCacheInternal() and systable_beginscan(). Hit a number of
times.
The most glaring case is the RelationInitTableAccessMethod() call in
RelationBuildLocalRelation(). Seems like the best fix is to just move
the MemoryContextSwitchTo() to just before the
RelationInitTableAccessMethod(). Although I wonder if we shouldn't go
further, and move it to much earlier, somewhere after the rd_rel
allocation.
There's plenty other hits, but I think I should get back to working on
making the shared memory stats patch committable. I really wouldn't want
it to slip yet another year.
But I think it might make sense to add a flag indicating contexts that
shouldn't be used for non-transient data. Seems like we fairly regularly
have "bugs" around this?
Greetings,
Andres Freund
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: andres@anarazel.de, tgl@sss.pgh.pa.us
Subject: Re: Getting better results from valgrind leak tracking
In-Reply-To: <20210318030250.xlqxcppknzrakcs5@alap3.anarazel.de>
References: <3471359.1615937770@sss.pgh.pa.us> <20210317023101.anvejcfotwka6gaa@alap3.anarazel.de> <3479700.1615950107@sss.pgh.pa.us> <cea52c41-f005-4ec3-8dd8-4d12dbfbe9f6@www.fastmail.com> <3482163.1615953715@sss.pgh.pa.us> <20210318030250.xlqxcppknzrakcs5@alap3.anarazel.de>
* 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