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 1lXv4D-0005a8-Tf for pgsql-hackers@arkaria.postgresql.org; Sun, 18 Apr 2021 00:13:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lXv4A-0005AE-I8 for pgsql-hackers@arkaria.postgresql.org; Sun, 18 Apr 2021 00:13:34 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lXv4A-0005A7-77 for pgsql-hackers@lists.postgresql.org; Sun, 18 Apr 2021 00:13:34 +0000 Received: from mail-oi1-x22e.google.com ([2607:f8b0:4864:20::22e]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lXv44-00044D-Iz for pgsql-hackers@postgresql.org; Sun, 18 Apr 2021 00:13:32 +0000 Received: by mail-oi1-x22e.google.com with SMTP id v6so4078101oiv.3 for ; Sat, 17 Apr 2021 17:13:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=1ete8Ugj9UEZyJcSTvocI4ZyeZIJssAJ8DFnj6ku3Vg=; b=EFkPEcpvzL01GiJgNCnXHJPW7SorAG0/NGqZ0sjd9SUleT/095Drg3eh617/1v07gE OEdMj2mnEYa2gTPrFfv09BGzTJ7Rx+exp5/as8m6OQafZEVbObDMnvqahF3xSl1d4Qbl GwnqIvKGNCMcKWMyct2RRzYhhvjxO8lLvvvdd88TaFa7qwlEnT6nTAUrLR/7JaNhDDRw Ky24Mj8p72QJm9NGCbKqr6dv5bgN8P24jEoS4rYLnjG3Fu/sM+6tZWyLMfu5pXrqbXq3 0LUGzQnURq3DhQ8S6AV4NoVZ/fbRYkWF5S0t9SXKO5aTX30HGVm7Gth3OwKRhERpmGzK H4eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=1ete8Ugj9UEZyJcSTvocI4ZyeZIJssAJ8DFnj6ku3Vg=; b=oiwzo8pEPE1yoy9m6UZ2IktORH6NddSSzDUzqiM1fZ+JSp5uPGjRUsxZqE8rAavgll Fq6CShsm3eTrc3NloaXnkMCdjKHmU5gijJqT/rMIW+svYdhxl6s2oyzkwu8/c+oWyn84 VNuMRHUM7PUGS7WZKYq/AmX98d4CpWNrGD0ZtR8cIIHtSA1BWuPq1oAiz7YKqxK0YUjY TWlMvPxVKTGGBzJulZIjhdzqlIlDLq9pztVBV2+xcx7Fg1AEqolGJewexoe+pu47TJT3 BOPRd6wP3taLc5j8zVRq6leOPQVWpYpkklTosIdtYrJdIiYYHByX7obmQ7QudvciUhRw LuQg== X-Gm-Message-State: AOAM5334auprKGj7hLPFvWKA7TEvFPIDt5994capicxBaPpWerzt5ztr Cq/nNKkZu59yfe0Ej8Kyxjj668xbIA7azg== X-Google-Smtp-Source: ABdhPJx6J9Afyo7mNRrdWTLPnnAWxNg6FWBJT7gHvRf63HU6WuWAV4pcOZ45WOFGE5tF/vwjZP2smQ== X-Received: by 2002:aca:b7d5:: with SMTP id h204mr11717273oif.18.1618704805893; Sat, 17 Apr 2021 17:13:25 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id a7sm2087075ooo.30.2021.04.17.17.13.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Apr 2021 17:13:25 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 40066800BC5; Sat, 17 Apr 2021 19:13:24 -0500 (CDT) Date: Sat, 17 Apr 2021 19:13:24 -0500 From: Justin Pryzby To: Andres Freund Cc: pgsql-hackers@postgresql.org, Tom Lane Subject: Re: terminate called after throwing an instance of 'std::bad_alloc' Message-ID: <20210418001324.GP3315@telsasoft.com> References: <20201001021609.GC8476@telsasoft.com> <20201003220236.GL8476@telsasoft.com> <20201003230149.mtd7fjsjwgii3jv7@alap3.anarazel.de> <20201003233045.GM8476@telsasoft.com> <20201004020127.zbrol2ypu6tg2bei@alap3.anarazel.de> <20201007230242.rnwsbnxywvthef3w@alap3.anarazel.de> <20201218235607.GC30237@telsasoft.com> <20210417021755.xdcqaqqt4y46wzt7@alap3.anarazel.de> <20210417024854.GL3315@telsasoft.com> <20210417031837.GM3315@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210417031837.GM3315@telsasoft.com> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Apr 16, 2021 at 10:18:37PM -0500, Justin Pryzby wrote: > On Fri, Apr 16, 2021 at 09:48:54PM -0500, Justin Pryzby wrote: > > On Fri, Apr 16, 2021 at 07:17:55PM -0700, Andres Freund wrote: > > > Hi, > > > > > > On 2020-12-18 17:56:07 -0600, Justin Pryzby wrote: > > > > I'd be happy to run with a prototype fix for the leak to see if the other issue > > > > does (not) recur. > > > > > > I just posted a prototype fix to https://www.postgresql.org/message-id/20210417021602.7dilihkdc7oblrf7%40alap3.anarazel.de > > > (just because that was the first thread I re-found). It'd be cool if you > > > could have a look! > > > > This doesn't seem to address the problem triggered by the reproducer at > > https://www.postgresql.org/message-id/20210331040751.GU4431@telsasoft.com > > (sorry I didn't CC you) > > I take that back - I forgot that this doesn't release RAM until hitting a > threshold. I tried this on the query that was causing the original c++ exception. It still grows to 2GB within 5min. PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 23084 postgres 20 0 2514364 1.6g 29484 R 99.7 18.2 3:40.87 postgres: telsasoft ts 192.168.122.11(50892) SELECT PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 23084 postgres 20 0 3046960 2.1g 29484 R 100.0 24.1 4:30.64 postgres: telsasoft ts 192.168.122.11(50892) SELECT PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 23084 postgres 20 0 4323500 3.3g 29488 R 99.7 38.4 8:20.63 postgres: telsasoft ts 192.168.122.11(50892) SELECT When I first reported this issue, the affected process was a long-running, single-threaded python tool. We since updated it (partially to avoid issues like this) to use multiprocessing, therefor separate postgres backends. I'm now realizing that that's RAM use for a single query, not from continuous leaks across multiple queries. This is still true with the patch even if I #define LLVMJIT_LLVM_CONTEXT_REUSE_MAX 1 PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 28438 postgres 20 0 3854264 2.8g 29428 R 98.7 33.2 8:56.79 postgres: telsasoft ts 192.168.122.11(53614) BIND python3 ./jitleak.py # runs telsasoft reports INFO: recreating LLVM context after 2 uses INFO: recreating LLVM context after 2 uses INFO: recreating LLVM context after 2 uses INFO: recreating LLVM context after 2 uses INFO: recreating LLVM context after 2 uses PID 27742 finished running report; est=None rows=40745; cols=34; ... duration:538 INFO: recreating LLVM context after 81492 uses I did: - llvm_llvm_context_reuse_count = 0; Assert(llvm_context != NULL); + elog(INFO, "recreating LLVM context after %zu uses", llvm_llvm_context_reuse_count); + llvm_llvm_context_reuse_count = 0; Maybe we're missing this condition somehow ? if (llvm_jit_context_in_use_count == 0 && Also, I just hit this assertion by cancelling the query with ^C / sigint. But I don't have a reprodcer for it. < 2021-04-17 19:14:23.509 ADT telsasoft >PANIC: LLVMJitContext in use count not 0 at exit (is 1) -- Justin