pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomas Vondra <tomas.vondra@2ndquadrant.com>
To: pgsql-bugs@postgresql.org
Subject: Re: BUG #14231: logical replication wal sender process spins when using error traps in function
Date: Wed, 13 Jul 2016 20:36:56 +0200
Message-ID: <b9465329-acc1-8cc0-65e2-d3199a745e4b@2ndquadrant.com> (raw)
In-Reply-To: <CAM3SWZSqBWmJEwu6-aFkN7XkPdybw_nrSfcjNtnJvq8m8-Rcig@mail.gmail.com>
References: <878txea5b4.fsf@news-spur.riddles.org.uk>
	<20160706212600.GA649263@alvherre.pgsql>
	<CAM3SWZSqBWmJEwu6-aFkN7XkPdybw_nrSfcjNtnJvq8m8-Rcig@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

On 07/06/2016 11:40 PM, Peter Geoghegan wrote:
> On Wed, Jul 6, 2016 at 2:26 PM, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:
>>> So I think this is primarily an artifact of doing so much retail
>>> palloc/pfree in a single memory context.
>>
>> As I recall, this is the main reason Andres stuck the slab cache in
>> reorderbuffer.  Maybe it'd be worthwhile to implement a different
>> MemoryContext tailored to this use case, and remove the slab cache
>> stuff.
>
> I withdraw my remarks on that commit -- I don't think that's what it is now.
>
> I had luck adding a new child memory context for tuplesort.c in commit
> 0011c0091e886b874e485a46ff2c94222ffbf550. This allowed tuplesort.c to
> blow away the free list via a new call to MemoryContextReset(). This
> didn't even remove *any* pfree() operations in the affected codepath,
> but was still quite effective.
>
> I'm not sure that that's comparable, but it may be an interesting case
> that others are not aware of.
>

I'm not very familiar with the reorderbuffer.c, but my understanding is 
that it's an object with potentially very long lifetime, doing a lot of 
interleaved palloc/pfree (or accessing the slab cache). The lifetime of 
tuplesort is much shorter with clear boundaries, and probably does not 
need palloc/pfree interleaved that much.

The separate memory context would probably fix the pfree issue, but I'm 
afraid it'd make all pfree() calls pointless useless as AllocSet keeps 
all pfreed chunks in internal freelists and only releases them at the 
end. Which means the memory context would allocate memory and then keep 
it until it's destroyed, meaning the slab limits would be pointless.

I do have a few rough ideas how this might be improved, but it's a bit 
rough at this point. The distinguishing feature of the slab allocator is 
that all objects have exactly the same size, which makes the "many 
freelist" idea in AllocSet a bit pointless. (Let's ignore that we use 
the same context for three different objects for now.)

So I'm thinking about adding a new MemoryContext implementation, e.g. 
SlabMemoryContext, which will only allow allocating pieces with a 
particular size. Then we can get rid of the AllocSet pieces that deal 
with freelists, and also make sure we know which blocks contain free 
chunks so that we can reuse chunks from more full blocks, etc. But I 
haven't tried coding anything, so maybe it's all stupid.

regards

-- 
Tomas Vondra                  http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (19+ messages)  latest in thread

Message-ID: <b9465329-acc1-8cc0-65e2-d3199a745e4b@2ndquadrant.com>
Permalink:  ../b9465329-acc1-8cc0-65e2-d3199a745e4b@2ndquadrant.com/
Also on:    postgresql.org/message-id/b9465329-acc1-8cc0-65e2-d3199a745e4b@2ndquadrant.com

 · 

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-bugs@postgresql.org
  Cc: tomas.vondra@2ndquadrant.com
  Subject: Re: BUG #14231: logical replication wal sender process spins when using error traps in function
  In-Reply-To: <b9465329-acc1-8cc0-65e2-d3199a745e4b@2ndquadrant.com>
  References: <878txea5b4.fsf@news-spur.riddles.org.uk> <20160706212600.GA649263@alvherre.pgsql> <CAM3SWZSqBWmJEwu6-aFkN7XkPdybw_nrSfcjNtnJvq8m8-Rcig@mail.gmail.com> <b9465329-acc1-8cc0-65e2-d3199a745e4b@2ndquadrant.com>

* 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