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 1lYXu9-0000mu-Pv for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Apr 2021 17:41:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lYXu8-0003S0-JY for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Apr 2021 17:41:48 +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 1lYXu8-0003Rn-7R for pgsql-hackers@lists.postgresql.org; Mon, 19 Apr 2021 17:41:48 +0000 Received: from mail-oo1-xc2b.google.com ([2607:f8b0:4864:20::c2b]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lYXu1-0007GH-1d for pgsql-hackers@postgresql.org; Mon, 19 Apr 2021 17:41:47 +0000 Received: by mail-oo1-xc2b.google.com with SMTP id s1-20020a4ac1010000b02901cfd9170ce2so7910700oop.12 for ; Mon, 19 Apr 2021 10:41:40 -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=zaYdv87DaLlrVaHd5QhmITAqUoZl+gY2Cl/ACrjQ9Is=; b=bT1KevYiP8sDrMtA1+Sv6HBlZ0lqASjbo7vqWymK3FhG6ftYtw/olviV3MAPLWISzm wyRSuTIQtjlPzebJAfrkNuiE6k7zvX732jT25Mvv2CusGhNuURBp0jNLdqriCIqsdIEU D/crBSDuAZ+50AMSbRYcDbm3KmdAI1fjRs6Q4wrW+72fDuI/kmWT4OPxMPJgnY/w90LP hOyHwXk6aYWd0/NiWmPu94eq0QKTbNcGkjI+PKdmYMHLLFIFlubnbWppEgHGcHod9yZP UA/jyNVluV2IFrSUXXHx17tq8ShVFrULP+aZMda1QnW6+KaoydAoG3MQKWSXx2HjxpWm toVQ== 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=zaYdv87DaLlrVaHd5QhmITAqUoZl+gY2Cl/ACrjQ9Is=; b=KvshhfewvK2vPVxj5Yr7EB//HAGOhVp0ihK5Gt5C1Iaqxk2IIBHGLgcOg51VgkQPOh mm3+c8faS67RAy46JcRFkNaMEYl1/1NF5O1rCX0baFUpjWp1VGvXa8yRngloF7NIH5w6 cxL9cDPReamzsFAG7NQil/6q3y4edCslEzBgwGnhjwEH9y6cQU0Zd11cT1N2FOWWBXZH U09VYht2/ZysrP7MgTOA4WOYA3WEOFOf0yQSygHPgtIhc+h9VNQ+KDJM9FD8dPGALdF1 Dq98lmzX2ICXhuVmh9eYcXeVvzuDRmYWwk89Otd1ZdF7LqE5KwgQEY7hcNXxZDGs4mr/ 797Q== X-Gm-Message-State: AOAM533+ebb4MXWhZZ30gGj5TCFKZSS/IJfbrv43Y08gtj5yASnyvw5p klLfko93xF2tL3uxxrS/xNbA7sT7JqYlMA== X-Google-Smtp-Source: ABdhPJz0feiaa/hrmnxh0Xx9/0p6eVudlwyWGUkPDHx3JBQPO0ku1exdWLKWb9WAxoenmoWCcU75ug== X-Received: by 2002:a4a:d089:: with SMTP id i9mr1660093oor.15.1618854098923; Mon, 19 Apr 2021 10:41:38 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id e20sm3589964otl.15.2021.04.19.10.41.38 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Apr 2021 10:41:38 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 1A74D800BC5; Mon, 19 Apr 2021 12:41:37 -0500 (CDT) Date: Mon, 19 Apr 2021 12:41:36 -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: <20210419174136.GJ7256@telsasoft.com> References: <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> <20210418001324.GP3315@telsasoft.com> <20210419164130.byegpfrw46mzagcu@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210419164130.byegpfrw46mzagcu@alap3.anarazel.de> 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 Mon, Apr 19, 2021 at 09:41:30AM -0700, Andres Freund wrote: > On 2021-04-17 19:13:24 -0500, Justin Pryzby wrote: > > I'm now realizing that that's RAM use for a single query, not from continuous > > leaks across multiple queries. > > What's the memory usage with inlining disabled, and whats the usage > without jit? PGOPTIONS="-c jit=off -c jit_inline_above_cost=0 -c jit_above_cost=0 -c client_min_messages=debug -c log_executor_stats=on" python3 `pwd`/jitleak.py ! [5.272604 s user, 0.329912 s system total] ! 120948 kB max resident size PGOPTIONS="-c jit=on -c jit_inline_above_cost=0 -c jit_above_cost=0 -c client_min_messages=debug -c log_executor_stats=on" python3 `pwd`/jitleak.py DEBUG: time to inline: 0.003s, opt: 0.000s, emit: 0.003s ... repeated many times ... ! [585.090087 s user, 31.835228 s system total] ! 4639556 kB max resident size PGOPTIONS="-c jit=on -c jit_inline_above_cost=-1 -c jit_above_cost=0 -c client_min_messages=debug -c log_executor_stats=on" python3 `pwd`/jitleak.py DEBUG: time to inline: 0.000s, opt: 0.000s, emit: 0.003s ... repeated many times ... which is confusing, since inlining is disabled ... ! [318.556489 s user, 8.413007 s system total] ! 159436 kB max resident size > > Maybe we're missing this condition somehow ? > > if (llvm_jit_context_in_use_count == 0 && > > Do you utilize cursors or such? Not in this backend/process. I believe postgis/mapserver uses cursors in a separate process, though... Our report runs like: SELECT large_object_oid FROM ... WHERE name=$1 AND user=$2 ... FOR UPDATE -- our reports are stored as LOs and read by readlo begin; SET enable_nestloop=off; -- I'm sorry to say but nothing else has avoids occasional pathological query plans SELECT report text...; rollback; > > 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) > > Hm, I'll try to see how that happens - if not, do you have a backtrace? This may be because I backpatched to v13, which had one conflict (0a2bc5d61). Maybe this is relevant, too: bab150045 If you could provide a patch for v13, it's a good bet there's no issue that I didn't cause. I'm able to reproduce the crash like this, with my patch to v13, but not your patch on master. python3 -c "import pg; db=pg.DB('dbname=postgres'); db.query('SET jit_above_cost=0; SET jit_inline_above_cost=0; SET jit=on; SET client_min_messages=debug'); db.query('begin'); db.query_formatted('SELECT 1 FROM generate_series(1,99)a WHERE a=%s', [1], inline=False);" -- Justin