Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eJ11D-00086L-O6 for pgsql-committers@arkaria.postgresql.org; Sun, 26 Nov 2017 17:47:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eJ11D-0002BG-2g for pgsql-committers@arkaria.postgresql.org; Sun, 26 Nov 2017 17:47:03 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eJ11C-0002Aw-UA for pgsql-committers@lists.postgresql.org; Sun, 26 Nov 2017 17:47:02 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eJ114-0003Hf-8D for pgsql-committers@postgresql.org; Sun, 26 Nov 2017 17:47:01 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id vAQHkkk6016798; Sun, 26 Nov 2017 12:46:46 -0500 From: Tom Lane To: Simon Riggs cc: Andres Freund , Tomas Vondra , pgsql-committers Subject: Re: pgsql: Generational memory allocator In-reply-to: References: <20171123001649.y2nf7422iay6cw3v@alap3.anarazel.de> <16449.1511548313@sss.pgh.pa.us> <4618.1511573138@sss.pgh.pa.us> <6189.1511587105@sss.pgh.pa.us> <8991.1511639441@sss.pgh.pa.us> <20171125200014.qbewtip5oydqsklt@alap3.anarazel.de> <21466.1511644760@sss.pgh.pa.us> <2875.1511646362@sss.pgh.pa.us> Comments: In-reply-to Simon Riggs message dated "Sun, 26 Nov 2017 20:33:01 +1100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <16796.1511718406.1@sss.pgh.pa.us> Date: Sun, 26 Nov 2017 12:46:46 -0500 Message-ID: <16797.1511718406@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Simon Riggs writes: > On 26 November 2017 at 08:46, Tom Lane wrote: >> I've confirmed that the attached is sufficient to stop the valgrind crash >> on my machine. But as I said, I think we should be more aggressive at >> resizing the buffer, to reduce resize cycles. I'm inclined to start out >> with a buffer size of 128 or 256 or so bytes and double it when needed. >> Anybody have a feeling for a typical size for the "main data" part >> of a WAL record? > We reuse the buffer and only pfree/palloc when we need to enlarge the > buffer, so not sure we need to do the doubling thing and it probably > doesn't matter what the typical size is. Well, I'm concerned about the possibility of a lot of palloc thrashing if the first bunch of records it reads happen to have steadily increasing sizes. However, rather than doubling, it might be sufficient to set a robust minimum on the first allocation, ie use something along the lines of Max(1024, MAXALIGN(state->main_data_len)). regards, tom lane