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 1liR8j-0007Gd-Eo for pgsql-hackers@arkaria.postgresql.org; Mon, 17 May 2021 00:29:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1liR8h-0000FL-AR for pgsql-hackers@arkaria.postgresql.org; Mon, 17 May 2021 00:29:43 +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 1liR8g-0000Ex-W1 for pgsql-hackers@lists.postgresql.org; Mon, 17 May 2021 00:29:43 +0000 Received: from mail-oi1-x234.google.com ([2607:f8b0:4864:20::234]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1liR8d-0004Ot-QY for pgsql-hackers@postgresql.org; Mon, 17 May 2021 00:29:41 +0000 Received: by mail-oi1-x234.google.com with SMTP id x15so4984225oic.13 for ; Sun, 16 May 2021 17:29:39 -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=eCYvqe2FGXggRvZqKvKHoNrJ27Wk8oqUAvOnR0TvRFE=; b=i+9Cz7DgjYv2+F6R7I/MKGzrABvWf47R0Oj4xpmiGXfXaRJR8n+8rhnx4RbRFKS+g9 +cSYq35bqOnX7rJ/RXbWJ2WIpCJbXlY+AxPUIR8+neZOuBKqNb9XWAS4Az61Fagiv5Gx Cl8CdmArqOQ5NO88Ve8D24nNr6/e5QIxapWApZW5hzmWIlIVyMApdH3Yzdvu7oAgiqYu GTGPFtHkd/QQcGtwVwaaFQN0x8hj+exvo72PSyfRAjk/Idjs5qmiAkQnsWfDYAPxaC1n 4yPMNjvBZLGdmCXsIvUzr4SxsKr2NLpnMesV3QsVp0p7OxgO9vxwFDnwIlp3E0YZ4npP qNDg== 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=eCYvqe2FGXggRvZqKvKHoNrJ27Wk8oqUAvOnR0TvRFE=; b=q+DwvPtVL5PhIZnwy7406+QylxLnhEjzUD7e1Uz3R/RJ9xYDSSrEZnRmEjqKorvBZu ec0qToVfrgpbQJyEbBe/9UYV1BlaNtXgan0FnwIofALAd5jDG2SzNsBaYaSFxBMwq6kA KLAtrkFLigLVpBi4VNjdTj6F6oae34tjcO+xePC4f7tbFDP1qOzKhzCb317DSyAg6WlB wF+Oh6R2yfQibi+Jk09aFGavh6UXxI+L+Afnysimojbd6cNcsWoX6r9/tBf/Fq5kdyZ4 gtRFAgXnPkQCTO6pi+RSipjR52N6jKVCeDHDBxAiIUfvSbbHv/cQiIyayhF6j3aMds4s SzRQ== X-Gm-Message-State: AOAM531DlTUV1aSa1eUGMwfa9p1klV5I0MH2WnHO2GQhwSKTaPRvkfqz 0KxQcgD5oxxU5dTyv/nC+O2OHrQHb1IuJg== X-Google-Smtp-Source: ABdhPJyWgpoKDdIchnyQn9X+2/T/JfVHpymdW0CYbVaW8E7bwdrc8yRSv1s1haB4kEw1Y8Mv2pnwxg== X-Received: by 2002:aca:2b16:: with SMTP id i22mr176245oik.121.1621211378771; Sun, 16 May 2021 17:29:38 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id 9sm2465845oie.51.2021.05.16.17.29.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 16 May 2021 17:29:38 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id EBAA18009D6; Sun, 16 May 2021 19:29:36 -0500 (CDT) Date: Sun, 16 May 2021 19:29: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: <20210517002936.GD373@telsasoft.com> References: <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> <20210419174136.GJ7256@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210419174136.GJ7256@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 I think you were thinking that the jit_inline_above_cost=0 for queries within plpgsql functions is pathological and not a useful test case, since the function can be called an arbitrarily large number of times, but the jit context can't be reset mid-query due to nonzero reference count. I think you were wondering whether in our normal environment the plpgsql functions run queries that are expensive enough to be jitted. I think they're not expensive enough to be JITed - but it makes debugging/diagnosing/testing much harder if it somehow "doesn't count" to set inline_above_cost=0. I think that means 1) it's still a memory leak, since it's O(ntuples), which is not generally okay....but, 2) it's certainly better than nothing. It'd be good enough for back branches to have a mitigation rather than be killed by OOM. I'd forgotten doing it, but I had run your patch on one of the servers which first crashed. I remembered after upgrading to v13.3 and having the processed killed by OOM twice per day for the last 3 days (on a very consistent schedule). Could you provide a patch to apply to v13 ? My attempted backpatch introduced some issues. On Mon, Apr 19, 2021 at 12:41:36PM -0500, Justin Pryzby wrote: > > > 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);"