Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1afCar-0002a2-1W for pgsql-hackers@arkaria.postgresql.org; Sun, 13 Mar 2016 20:26:29 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1afCaq-0003x8-KA for pgsql-hackers@arkaria.postgresql.org; Sun, 13 Mar 2016 20:26:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1afCZU-00021o-Vv for pgsql-hackers@postgresql.org; Sun, 13 Mar 2016 20:25:05 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1afCZR-0005im-5r for pgsql-hackers@postgresql.org; Sun, 13 Mar 2016 20:25:04 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u2DKOkeh019754; Sun, 13 Mar 2016 16:24:46 -0400 From: Tom Lane To: Jeff Janes cc: Jaime Casanova , Pg Hackers , Heikki Linnakangas Subject: Re: memory leak in GIN In-reply-to: References: Comments: In-reply-to Jeff Janes message dated "Sun, 13 Mar 2016 11:54:03 -0700" Date: Sun, 13 Mar 2016 16:24:46 -0400 Message-ID: <19753.1457900686@sss.pgh.pa.us> 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 Jeff Janes writes: > I bisected it down to: > d88976cfa1302e8dccdcbfe55e9e29faee8c0cdf is the first bad commit > commit d88976cfa1302e8dccdcbfe55e9e29faee8c0cdf > Author: Heikki Linnakangas > Date: Wed Feb 4 17:40:25 2015 +0200 > Use a separate memory context for GIN scan keys. Yeah, I had come to the same conclusion. The leak comes from removing this bit from ginFreeScanKeys(): - if (entry->list) - pfree(entry->list); Heikki evidently supposed that entry->list would be allocated in the so->keyCtx, but as things stand, it is not: it gets allocated in the query-lifespan context, so this change causes a leak of potentially several kB per ginrescan cycle. And the test query does about 120000 of those. I think it would likely be a good thing to fix things so that that assumption actually holds, but I'm not familiar enough with this code to decide what's the best way to do that. (Basically, the question is "how much of startScanEntry() ought to run with keyCtx as current memory context?") As a short-term fix I plan to reinstall the above-cited pfree. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers