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.92) (envelope-from ) id 1jCreP-00079r-PQ for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Mar 2020 21:15: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 1jCreM-0000H2-Re for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Mar 2020 21:15:22 +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 1jCreM-0000Gv-7Y for pgsql-hackers@lists.postgresql.org; Fri, 13 Mar 2020 21:15:22 +0000 Received: from mail-qv1-xf43.google.com ([2607:f8b0:4864:20::f43]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jCreE-0004gz-8a for pgsql-hackers@postgresql.org; Fri, 13 Mar 2020 21:15:20 +0000 Received: by mail-qv1-xf43.google.com with SMTP id r15so5436398qve.3 for ; Fri, 13 Mar 2020 14:15:14 -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:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=2qz2352vLkbDyvC4HvW4LYGDy/zKMVrPzT8M8H3GHzU=; b=W4QzeUYl4q9PHDYTwz0llRzMeSk4esmlLR0UFrY85+mprxUDWz9aWwEkNVxd/uuHxB 2LUSGga25xZfK4jlBUH6PzNaRJnCXdWoP8f3L4P2FLuxaZH8c9Dzp5trkf4z7N6EwSsc jxPJ63E9N8weqKNTej8ZT+wFFPqwxqObI7W5qrBLmX7lb3Dyzm1R8KOQIZBhbwUui1ra GVxH0eL4sd9QQG68CrkbODkF7PVaA5q1c5NrCxZpue58IEdBFFBE8t/bMJP3bTCvgdoZ gMebECmVl/YFHJaYBsMi3FMEImndIFw7skhLaaBiyWL5YnSotNWsAbpH9K72vXML5Vsm FkWw== 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:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=2qz2352vLkbDyvC4HvW4LYGDy/zKMVrPzT8M8H3GHzU=; b=dbjKMTSHk1jZT2Ikljg0+eTK9Hi1VDZ7FMTFryTedfl3MsZ9Bqk/Lngft9/faQ5v46 bH1EAHaQd/yl+MB7+4K0SSc1cQpBvWQBwDnE1c4xju24+e7TRXJPhf8szgfa8AtLXUyA uIKaForuFTgZFEBpnFx4udGZj3JsSuH0/x5XqHTgfLcJd18nooY/i9f3sJMIHk6Pvlpg sE+35+3+LUe9Z6/Ck5kruikGmO7NVtu3t0ubpVikyMUbRcA9HBL5K467fQLCzUCMx7u/ /IqjixCI5JmxdPpu92dULNOCEXVOWq5svjLYjXrv4ounImK/fS/6MtK2J9u/ooxlpzea wuNQ== X-Gm-Message-State: ANhLgQ2JQekIxX2eRMl/cGjOxrcFKpGYYYHGaO2ufp1U95naQVS7llR3 v7vT5vzKK8/2FA7Q1DgdgkOwLQ== X-Google-Smtp-Source: ADFU+vtTsrGTNMktvVczU7+M6OQLusBItmTK1Uwb0iRFLgTahKMqz8qXXlM3uzp9FknjmZHjZCHA5Q== X-Received: by 2002:ad4:4026:: with SMTP id q6mr12556870qvp.118.1584134113322; Fri, 13 Mar 2020 14:15:13 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([190.121.31.1]) by smtp.gmail.com with ESMTPSA id m22sm19896455qkk.94.2020.03.13.14.15.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Mar 2020 14:15:12 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id EFB9E300898; Fri, 13 Mar 2020 18:15:09 -0300 (-03) Date: Fri, 13 Mar 2020 18:15:09 -0300 From: Alvaro Herrera To: Thomas Munro Cc: Tomas Vondra , pgsql-hackers Subject: Re: WIP: WAL prefetch (another approach) Message-ID: <20200313211509.GA14359@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I tried my luck at a quick read of this patchset. I didn't manage to go over 0005 though, but I agree with Tomas that having this be configurable in terms of bytes of WAL is not very user-friendly. First of all, let me join the crowd chanting that this is badly needed; I don't need to repeat what Chittenden's talk showed. "WAL recovery is now 10x-20x times faster" would be a good item for pg13 press release, I think. > From a61b4e00c42ace5db1608e02165f89094bf86391 Mon Sep 17 00:00:00 2001 > From: Thomas Munro > Date: Tue, 3 Dec 2019 17:13:40 +1300 > Subject: [PATCH 1/5] Allow PrefetchBuffer() to be called with a SMgrRelation. > > Previously a Relation was required, but it's annoying to have > to create a "fake" one in recovery. LGTM. It's a pity to have to include smgr.h in bufmgr.h. Maybe it'd be sane to use a forward struct declaration and "struct SMgrRelation *" instead. > From acbff1444d0acce71b0218ce083df03992af1581 Mon Sep 17 00:00:00 2001 > From: Thomas Munro > Date: Mon, 9 Dec 2019 17:10:17 +1300 > Subject: [PATCH 2/5] Rename GetWalRcvWriteRecPtr() to GetWalRcvFlushRecPtr(). > > The new name better reflects the fact that the value it returns > is updated only when received data has been flushed to disk. > > An upcoming patch will make use of the latest data that was > written without waiting for it to be flushed, so use more > precise function names. Ugh. (Not for your patch -- I mean for the existing naming convention). It would make sense to rename WalRcvData->receivedUpto in this commit, maybe to flushedUpto. > From d7fa7d82c5f68d0cccf441ce9e8dfa40f64d3e0d Mon Sep 17 00:00:00 2001 > From: Thomas Munro > Date: Mon, 9 Dec 2019 17:22:07 +1300 > Subject: [PATCH 3/5] Add WalRcvGetWriteRecPtr() (new definition). > > A later patch will read received WAL to prefetch referenced blocks, > without waiting for the data to be flushed to disk. To do that, > it needs to be able to see the write pointer advancing in shared > memory. > > The function formerly bearing name was recently renamed to > WalRcvGetFlushRecPtr(), which better described what it does. > + pg_atomic_init_u64(&WalRcv->writtenUpto, 0); Umm, how come you're using WalRcv here instead of walrcv? I would flag this patch for sneaky nastiness if this weren't mostly harmless. (I think we should do away with local walrcv pointers altogether. But that should be a separate patch, I think.) > + pg_atomic_uint64 writtenUpto; Are we already using uint64s for XLogRecPtrs anywhere? This seems novel. Given this, I wonder if the comment near "mutex" needs an update ("except where atomics are used"), or perhaps just move the member to after the line with mutex. I didn't understand the purpose of inc_counter() as written. Why not just pg_atomic_fetch_add_u64(..., 1)? > /* > * smgrprefetch() -- Initiate asynchronous read of the specified block of a relation. > + * > + * In recovery only, this can return false to indicate that a file > + * doesn't exist (presumably it has been dropped by a later WAL > + * record). > */ > -void > +bool > smgrprefetch(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum) I think this API, where the behavior of a low-level module changes depending on InRecovery, is confusingly crazy. I'd rather have the callers specifying whether they're OK with a file that doesn't exist. > +extern PrefetchBufferResult SharedPrefetchBuffer(SMgrRelation smgr_reln, > + ForkNumber forkNum, > + BlockNumber blockNum); > extern void PrefetchBuffer(Relation reln, ForkNumber forkNum, > BlockNumber blockNum); Umm, I would keep the return values of both these functions in sync. It's really strange that PrefetchBuffer does not return PrefetchBufferResult, don't you think? -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services