Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q1Zjb-0002iB-U6 for pgsql-hackers@arkaria.postgresql.org; Tue, 23 May 2023 21:39:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1q1ZjZ-00053R-5M for pgsql-hackers@arkaria.postgresql.org; Tue, 23 May 2023 21:39:57 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q1ZjY-00051x-RC for pgsql-hackers@lists.postgresql.org; Tue, 23 May 2023 21:39:56 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1q1ZjR-001WPp-V5 for pgsql-hackers@lists.postgresql.org; Tue, 23 May 2023 21:39:55 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 34NLdibx993815; Tue, 23 May 2023 17:39:44 -0400 From: Tom Lane To: Tomas Vondra cc: Andres Freund , PostgreSQL Hackers Subject: Re: memory leak in trigger handling (since PG12) In-reply-to: References: <222a3442-7f7d-246c-ed9b-a76209d19239@enterprisedb.com> <20230523171433.earidmyzock7fnk4@awork3.anarazel.de> Comments: In-reply-to Tomas Vondra message dated "Tue, 23 May 2023 23:26:42 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <993813.1684877984.1@sss.pgh.pa.us> Date: Tue, 23 May 2023 17:39:44 -0400 Message-ID: <993814.1684877984@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Tomas Vondra writes: > The really hard thing was determining what causes the memory leak - the > simple instrumentation doesn't help with that at all. It tells you there > might be a leak, but you don't know where did the allocations came from. > What I ended up doing is a simple gdb script that sets breakpoints on > all palloc/pfree variants, and prints info (including the backtrace) for > each call on ExecutorState. And then a script that aggregate those to > identify which backtraces allocated most chunks that were not freed. FWIW, I've had some success localizing palloc memory leaks with valgrind's leak detection mode. The trick is to ask it for a report before the context gets destroyed. Beats writing your own infrastructure ... > Would require testing with more data, though. I doubt we'd find much > with our regression tests, which have tiny data sets. Yeah, it's not clear whether we could make the still-hypothetical check sensitive enough to find leaks using small test cases without getting an unworkable number of false positives. Still, might be worth trying. It might be an acceptable tradeoff to have stricter rules for what can be allocated in ExecutorState in order to make this sort of problem more easily detectable. regards, tom lane