Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eIiH9-0007vR-FC for pgsql-committers@arkaria.postgresql.org; Sat, 25 Nov 2017 21:46:15 +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 1eIiH8-0005zp-KM for pgsql-committers@arkaria.postgresql.org; Sat, 25 Nov 2017 21:46:14 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eIiH8-0005zf-CE for pgsql-committers@lists.postgresql.org; Sat, 25 Nov 2017 21:46:14 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eIiH2-0007DY-1q for pgsql-committers@postgresql.org; Sat, 25 Nov 2017 21:46:13 +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 vAPLk2FZ002876; Sat, 25 Nov 2017 16:46:02 -0500 From: Tom Lane To: Andres Freund cc: Tomas Vondra , Simon Riggs , pgsql-committers Subject: Re: pgsql: Generational memory allocator In-reply-to: <21466.1511644760@sss.pgh.pa.us> 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> Comments: In-reply-to Tom Lane message dated "Sat, 25 Nov 2017 16:19:20 -0500" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <2833.1511646307.0@sss.pgh.pa.us> Date: Sat, 25 Nov 2017 16:46:02 -0500 Message-ID: <2875.1511646362@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2833.1511646307.1@sss.pgh.pa.us> I wrote: > Instead I propose that we should make sure that the palloc request size > for XLogReaderState->main_data is always maxalign'd. The existing > behavior in DecodeXLogRecord of palloc'ing it only just barely big > enough for the current record seems pretty brain-dead performance-wise > even without this consideration. Generally, if we need to enlarge > that buffer, we should enlarge it significantly, IMO. 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? regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="pad-xlog-buffer-size.patch"; charset="us-ascii" Content-ID: <2833.1511646307.2@sss.pgh.pa.us> Content-Description: pad-xlog-buffer-size.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/= transam/xlogreader.c index aeaafed..4840b0e 100644 *** a/src/backend/access/transam/xlogreader.c --- b/src/backend/access/transam/xlogreader.c *************** DecodeXLogRecord(XLogReaderState *state, *** 1279,1285 **** { if (state->main_data) pfree(state->main_data); ! state->main_data_bufsz =3D state->main_data_len; state->main_data =3D palloc(state->main_data_bufsz); } memcpy(state->main_data, ptr, state->main_data_len); --- 1279,1285 ---- { if (state->main_data) pfree(state->main_data); ! state->main_data_bufsz =3D MAXALIGN(state->main_data_len); state->main_data =3D palloc(state->main_data_bufsz); } memcpy(state->main_data, ptr, state->main_data_len); ------- =_aaaaaaaaaa0--