Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iF7dN-0001Eo-Gz for pgsql-hackers@arkaria.postgresql.org; Tue, 01 Oct 2019 02:11:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iF7dL-00014K-0Y for pgsql-hackers@arkaria.postgresql.org; Tue, 01 Oct 2019 02:11:23 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iF7dK-000147-DQ for pgsql-hackers@lists.postgresql.org; Tue, 01 Oct 2019 02:11:22 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iF7dH-0007dz-D9 for pgsql-hackers@postgresql.org; Tue, 01 Oct 2019 02:11:21 +0000 Received: by mail-wr1-x444.google.com with SMTP id n14so13417212wrw.9 for ; Mon, 30 Sep 2019 19:11:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-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=lvLgHHXUIvdiZZQdwuEMbSPiWXQwERGwOrNm42MwBVw=; b=rYfHP+qmr0HH/yP76XEvJPMWZcQCcQ4Xxq77cfdocEVtMpRucfXk+gSvbTg2v2xDKu 8Llpc3QnqJ/1HoT4iC42cRPLgRNRlov/ST3Oh0QFor5XjqPoJiYZ5pfWtguVYa5wyZ88 +JSGL5aOVbXCuwItcMjmaXn0XlVe+afAnkn4GfOEc7If6al6tzWCEjQ/yP+TNHu2feJ5 6k6ljmq+gsUK+fgbwmGiTecKc3oNi+A5ZFhycDPhoD7ux/h/s2lkwcSsXEJE7jv+a9U6 PWtj7eCALCa5muPKtnoojeaWDL3Va5xrLMOPrqE12+zao4VNmIaVEo+BUS6xgaU/E2Ty X5aQ== 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=lvLgHHXUIvdiZZQdwuEMbSPiWXQwERGwOrNm42MwBVw=; b=faSbyCCE0xHGZmPr3iLQsR57zijm9ZsM1jukzebOJQBfFqigSTSAeCRMedvLqVrD3f NmZYbrOp13bmx6y2hL34TGyf2S3r44176CBVi6P3LQJD96dbnym0MD4z3ZydASAZgtU6 VR54y+JvSjUcLnFohHZIfz650KEzkW9KAnYmjbyNakCyLg+UZNrRiB0BD02c4/mq1+Ep +YaDVxDef0E0VJ3C4DOn/jb5uifpDqexGrpms5Dq0f1xggapr/1qqNOTbqwHMHLKRDPd q6z55zkapKtNFhcoAg76HOO1XRcH1QmjTIKoRPL2JcCCB15aogik05Kakx6QlsDA41Ca o54A== X-Gm-Message-State: APjAAAXOAZ0Y5gwFh052ThlZaScGHigzYjfZeH5pOuSzVGOOr5d9o1xm eizPumyNx0V/IdVxfNp4R3zk9A== X-Google-Smtp-Source: APXvYqy7UUVGR8WBDt78sVFy9S4dADtPRj7Al8ScgrwsAYBvvPeJGx7DyqKw91K7uVI24xQYiyFy9g== X-Received: by 2002:adf:e386:: with SMTP id e6mr15209631wrm.91.1569895877352; Mon, 30 Sep 2019 19:11:17 -0700 (PDT) Received: from localhost (ip-86-49-253-183.net.upcbroadband.cz. [86.49.253.183]) by smtp.gmail.com with ESMTPSA id b194sm1268775wmg.46.2019.09.30.19.11.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2019 19:11:16 -0700 (PDT) Date: Tue, 1 Oct 2019 04:11:14 +0200 From: Tomas Vondra To: Jeff Davis Cc: Melanie Plageman , Soumyadeep Chakraborty , Robert Haas , Pg Hackers , soumyadeep2007@gmail.com Subject: Re: Memory Accounting Message-ID: <20191001021114.iimd77xgnstaww7j@development> References: <20190724215228.tlyj74ie4l2jn7ji@development> <67f66d2fa39e35aef90093c74531a38dcd5c0f73.camel@j-davis.com> <20190926192244.mk5ru6nkofo7am3h@development> <57780817877d4b40106b248b63261e21a7a56261.camel@j-davis.com> <20190928221249.mo2jrtlakingnc5e@development> <20190928222206.thidzeygazl7axhg@development> <392e034c1b674a1a58c217dc440ea6197081ccfa.camel@j-davis.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <392e034c1b674a1a58c217dc440ea6197081ccfa.camel@j-davis.com> User-Agent: NeoMutt/20180716 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, Sep 30, 2019 at 01:34:13PM -0700, Jeff Davis wrote: >On Sun, 2019-09-29 at 00:22 +0200, Tomas Vondra wrote: >> Notice that when CLOBBER_FREED_MEMORY is defined, the code first >> > calls >> > wipe_mem and then accesses fields of the (wiped) block. >> > Interesringly >> > enough, the regression tests don't seem to exercise these bits - >> > I've >> > tried adding elog(ERROR) and it still passes. For (2) that's not >> > very >> > surprising because Generation context is only really used in >> > logical >> > decoding (and we don't delete the context I think). Not sure about >> > (1) >> > but it might be because AllocSetReset does the right thing and only >> > leaves behind the keeper block. >> > >> > I'm pretty sure a custom function calling the contexts explicitly >> > would >> > fall over, but I haven't tried. >> > > >Fixed. > >I tested with some custom use of memory contexts. The reason >AllocSetDelete() didn't fail before is that most memory contexts use >the free lists (the list of free memory contexts, not the free list of >chunks), so you need to specify a non-default minsize in order to >prevent that and trigger the bug. > >AllocSetReset() worked, but it was reading the header of the keeper >block after wiping the contents of the keeper block. It technically >worked, because the header of the keeper block was not wiped, but it >seems more clear to explicitly save the size of the keeper block. In >AllocSetDelete(), saving the keeper size is required, because it wipes >the block headers in addition to the contents. > OK, looks good to me now. >> Oh, and one more thing - this probably needs to add at least some >> basic >> explanation of the accounting to src/backend/mmgr/README. > >Added. > Well, I've meant a couple of paragraphs explaining the motivation, and relevant trade-offs considered. So I've written a brief summary of the design as I understand it and pushed it like that. Of course, if you could proof-read it, that'd be good. I had a bit of a hard time deciding who to list as a reviewer - this patch started sometime in ~2015, and it was initially discussed as part of the larger hashagg effort, with plenty of people discussing various ancient versions of the patch. In the end I've included just people from the current thread. If that omits important past reviews, I'm sorry. For the record, results of the benchmarks I've done over the past couple of days are in [1]. It includes both the reindex benchmark used by by Robert in 2015, and a regular read-only pgbench. In general, the overhead of the accounting is pretty much indistinguishable from noise (at least on those two machines). In any case, thanks for the perseverance working on this. [1] https://github.com/tvondra/memory-accounting-benchmarks regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services