pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Sergey Burladyan <eshkinkot@gmail.com>
To: pgsql-bugs@postgresql.org
Cc: pgsql-hackers@postgresql.org
Subject: Re: [BUGS] BUG #9223: plperlu result memory leak
Date: Tue, 25 Feb 2014 17:56:01 +0400
Message-ID: <87ppmbmh3i.fsf@seb.koffice.internal> (raw)
In-Reply-To: <20140214163125.24620.66179@wrigleys.postgresql.org>
References: <20140214163125.24620.66179@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

Hello, All!

eshkinkot@gmail.com writes:

> create function perl_test(IN data text, OUT v1 text, OUT v2 integer, OUT v3
> integer, OUT v4 json, OUT v5 json)
>   returns record as
> $BODY$
>
> use strict;
> use warnings;
>
> my $res->{'v1'} = 'content';
>
> return $res;
>
> $BODY$
>   language plperlu volatile strict;

> test case:
> select count(perl_test('')) from generate_series(1, 1000000);

It looks like I found the problem, Perl use reference count and something that
is called "Mortal" for memory management.  As I understand it, mortal is free
after FREETMPS. Plperl call FREETMPS in plperl_call_perl_func() but after it,
plperl ask perl interpreter again for new mortal SV variables, for example, in
hek2cstr from plperl_sv_to_datum, and this new SV is newer freed.

I experiment with this patch, and it fix memory leak in my case, but patch
is incomplete. It does not free on error and fix only plperl_func_handler,
plperl_trigger_handler and may be plperl_inline_handler must be also fixed.

Patch for REL9_2_STABLE.

without patch:
  PID    VSZ   RSS
 2503  74112  7740
 2503 152928 86860
 2503 232208 165836
 2503 310732 244508
 2503 389264 323032

with patch:
  PID    VSZ   RSS
 4322  74112  7740
 4322  74380  8340
 4322  74380  8340
 4322  74380  8340
 4322  74380  8340

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

Attachments:

0001-WIP-plperl-memory-leak.patch (text/x-diff, 523B) download diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c index 49d50c4..9c9874d 100644 --- a/src/pl/plperl/plperl.c +++ b/src/pl/plperl/plperl.c @@ -2173,6 +2173,9 @@ plperl_func_handler(PG_FUNCTION_ARGS) ReturnSetInfo *rsi; ErrorContextCallback pl_error_context; + ENTER; + SAVETMPS; + if (SPI_connect() != SPI_OK_CONNECT) elog(ERROR, "could not connect to SPI manager"); @@ -2271,6 +2274,9 @@ plperl_func_handler(PG_FUNCTION_ARGS) SvREFCNT_dec(perlret); + FREETMPS; + LEAVE; + return retval; }

view thread (9+ messages)  latest in thread

Message-ID: <87ppmbmh3i.fsf@seb.koffice.internal>
Permalink:  ../87ppmbmh3i.fsf@seb.koffice.internal/
Also on:    postgresql.org/message-id/87ppmbmh3i.fsf@seb.koffice.internal

 ·  · 

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: eshkinkot@gmail.com, pgsql-hackers@postgresql.org
  Subject: Re: [BUGS] BUG #9223: plperlu result memory leak
  In-Reply-To: <87ppmbmh3i.fsf@seb.koffice.internal>
  References: <20140214163125.24620.66179@wrigleys.postgresql.org> <87ppmbmh3i.fsf@seb.koffice.internal>

* 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