Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1arU5F-0001tZ-Iq for pgsql-hackers@arkaria.postgresql.org; Sat, 16 Apr 2016 17:32:37 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1arU5E-0003sQ-25 for pgsql-hackers@arkaria.postgresql.org; Sat, 16 Apr 2016 17:32:36 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1arU3t-0002OP-PN for pgsql-hackers@postgresql.org; Sat, 16 Apr 2016 17:31:13 +0000 Received: from mimolette.dalibo.net ([212.85.157.144] helo=mail.dalibo.com) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1arU3q-0001UN-I0 for pgsql-hackers@postgresql.org; Sat, 16 Apr 2016 17:31:12 +0000 Received: from [192.168.0.42] (aur75-1-78-192-238-147.fbxo.proxad.net [78.192.238.147]) by mail.dalibo.com (Postfix) with ESMTPSA id 6575D2C28D9; Sat, 16 Apr 2016 19:31:06 +0200 (CEST) To: pgsql-hackers Cc: Marc Cousin From: Julien Rouhaud Subject: Memory leak in GIN index build Message-ID: <571276DD.5050303@dalibo.com> Date: Sat, 16 Apr 2016 19:31:09 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------050004080807000802010809" X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org This is a multi-part message in MIME format. --------------050004080807000802010809 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Hello, Another colleague provided a report of memory leak, during a GIN index build. Test case to reproduce the attached (need to create a gin index on the val column after loading). Sorry, it generates a 24GB table, and memory start leaking with a 1GB maintenance_work_mem after reaching 8 or 9 times the m_w_m setting, leading to ~ 9GB used in Gin build temporary context. After some digging, the leak comes from walbufbegin palloc in registerLeafRecompressWALData(). IIUC, walbufbegin isn't pfree-d and can't be before XLogInsert() is called, which happens in ginPlaceToPage(). I don't see a simple way to fix that. My first idea would be to change GinBtreeData's placeToPage (and all other needed) functions signature to pass a pointer to pfree in ginPlaceToPage() if needed, but it doesn't really seem appealing. In any case, I'd be happy to work on a patch if needed. Also, in dataPlaceToPageLeaf() and ginVacuumPostingTreeLeaf(), shouldn't the START_CRIT_SECTION() calls be placed before the xlog code? Regards. -- Julien Rouhaud http://dalibo.com - http://dalibo.org --------------050004080807000802010809 Content-Type: application/x-perl; name="generate_data.pl" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="generate_data.pl" #!/usr/bin/env perl=0A= =0A= print "CREATE table compteurs(id integer, val integer[]);";=0A= =0A= print "COPY compteurs FROM stdin;\n";=0A= =0A= for (my $i=3D0;$i<100000000;$i++)=0A= {=0A= my $nb_elements=3Dint(rand(100));=0A= my @values;=0A= for (my $j=3D0;$j<$nb_elements;$j++)=0A= {=0A= my $value =3Dint(rand(1000000));=0A= push @values,($value);=0A= }=0A= print "$i\t{",join(',',@values),"}\n";=0A= if (($i % 100000)=3D=3D0)=0A= {=0A= print STDERR $i,"\n";=0A= }=0A= }=0A= print "\\.\n";=0A= --------------050004080807000802010809 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers --------------050004080807000802010809--