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 1kZOp5-000160-O9 for pgsql-hackers@arkaria.postgresql.org; Mon, 02 Nov 2020 01:39:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kZOp4-0003yB-MK for pgsql-hackers@arkaria.postgresql.org; Mon, 02 Nov 2020 01:39:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kZOp3-0003y3-Mf for pgsql-hackers@lists.postgresql.org; Mon, 02 Nov 2020 01:39:50 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kZOp0-0005wu-9j for pgsql-hackers@lists.postgresql.org; Mon, 02 Nov 2020 01:39:49 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 5376C1296; Sun, 1 Nov 2020 20:39:43 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Sun, 01 Nov 2020 20:39:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm3; bh=TlzxcbqXeR0DaXnbGAtpGe59b5G uGmtXdJsoS+UF4S4=; b=X4i3M7cVIVwlNHfSgMQF2NYRmPPqu42u99uTZvaBKd4 lReX5l479g/4zfhY+cEA5ag+rpFENgji7Znd9I0gap8OA4sLoj58NSGKIo3vWRwA ZEZSnmJeJk+YzY8lVrpA95INcx7hQGIfHterD0Ul5KfZPBikNJMOxlZCDZzFwP6k Tvn8fUdwGCUMp16kagWIgo6z1JahU/GB8DENUjxzZd2PF7k46GTHquRSh99yNZu9 vkbnnMUMh/h/t6eJYtqbTtFx+kqb95qhO1WELPaKPiO3GCCoJU0Iw5TwnLODLE9r 3+ED218WWbAdDYO2dKntJwlipC5x/XXnPOeLY167MdA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=Tlzxcb qXeR0DaXnbGAtpGe59b5GuGmtXdJsoS+UF4S4=; b=F+sq+Jy6kbvk2ckQwDhcJ1 3gODkyYcKVNQ8vHyKAuSDuJvpp9POW2anXhc5iwo888QSle77ui7UDAJspImjlWC csoMYpAkzQzD5mKcM10NcFufTzebIgJpr1rcNm+24omA+uBqyVj7sULk/OZN45Rn GuXe6lw7Ozdb9TljTVrzRN1WbaReVyjK5XMQftrbQfnAUpNVGHt3BSYP6wXyUZin TAgUD4uoPBASTsGpVgANznbnuLY+DjGTLD97X2LviTMdS30JMIGn341JxG/C5TNC 9tbUL0SN6AvULfmYjAEZuaznh+wba2F6RVzcLWN1uYlxQbMQAjMj8UGvwyz82C8w == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedruddttddgfeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeetnhgurhgv shcuhfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucggtffrrg htthgvrhhnpeetheehiefgudelhfevvddvtdejheehkeelteekveeggeduieelieduuefg fedtjeenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgnecukfhppeeijedrud eitddrvddujedrvdehtdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgr ihhlfhhrohhmpegrnhgurhgvshesrghnrghrrgiivghlrdguvg X-ME-Proxy: Received: from intern.anarazel.de (c-67-160-217-250.hsd1.ca.comcast.net [67.160.217.250]) by mail.messagingengine.com (Postfix) with ESMTPA id 844D13280065; Sun, 1 Nov 2020 20:39:41 -0500 (EST) Date: Sun, 1 Nov 2020 17:39:40 -0800 From: Andres Freund To: Michael Paquier Cc: Julien Rouhaud , Justin Pryzby , Masahiko Sawada , Robert Haas , PostgreSQL Hackers , Masahiko Sawada Subject: Re: Online checksums verification in the backend Message-ID: <20201102013940.tk5e2co2maedzksw@alap3.anarazel.de> References: <20201023090630.GA26347@paquier.xyz> <20201027070746.GD28445@paquier.xyz> <20201028050852.GF28445@paquier.xyz> <20201029181729.2nrub47u7yqncsv7@alap3.anarazel.de> <20201030025834.6spoioldj3jiqif3@alap3.anarazel.de> <20201030050852.5eenoh3sk2uxnv53@alap3.anarazel.de> <20201102010525.GA27101@paquier.xyz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201102010525.GA27101@paquier.xyz> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, I'm a bit limited writing - one handed for a while following an injury on Friday... On 2020-11-02 10:05:25 +0900, Michael Paquier wrote: > On Thu, Oct 29, 2020 at 10:08:52PM -0700, Andres Freund wrote: > > I think its pretty much *never* OK to do IO while holding a buffer > > mapping lock. You're locking a significant fraction of shared buffers > > over IO. That's just not OK. Don't think there's any place doing so > > currently either. > > There is no place doing that on HEAD. Err? /* see if the block is in the buffer pool or not */ LWLockAcquire(partLock, LW_SHARED); buf_id = BufTableLookup(&buf_tag, buf_hash); if (buf_id >= 0) { ... /* Read the buffer from disk, with the I/O lock still held */ smgrread(smgr, forknum, blkno, buffer); LWLockRelease(BufferDescriptorGetIOLock(bufdesc)); } else { /* * Simply read the buffer. There's no risk of modification on it as * we are holding the buffer pool partition mapping lock. */ smgrread(smgr, forknum, blkno, buffer); } /* buffer lookup done, so now do its check */ LWLockRelease(partLock); How is this not doing IO while holding a buffer mapping lock? > This specific point was mentioned in the first message of this thread, > 7th paragraph. That was a long thread, so it is easy to miss: > https://www.postgresql.org/message-id/CAOBaU_aVvMjQn=ge5qPiJOPMmOj5=ii3st5Q0Y+WuLML5sR17w@mail.gmail.com The code clearly doesnt implement it that way. > I am wondering what you have in mind regarding the use of > BM_IO_IN_PROGRESS or a similar flag. Wouldn't that imply some > consequences for other existing buffers in the table, like a possible > eviction? You'd need exactly one empty buffer for that - it can be reused for the next to-be-checked buffer. > I'd like to think that we should not do any manipulation of > the buffer tables in this case. Why? Its the way we lock buffers - why is this so special that we need to do differently? > Hence, in order to prevent a > concurrent activity to load in shared buffers the page currently > checked on disk, I got to think that we would need something new here, > like a filtering hash table that would be checked each time a backend > tries to insert an entry into the buffer tables. Thats going to slow down everything a bit - the mapping already is a bottleneck. > 1) If the buffer is in shared buffers, we have the APIs to solve that > by using a pin, unlock the partition, and then do the I/O. (Still > that's unsafe with the smgrwrite() argument?) Thats why you need an appropriate relation lock... Something CheckBuffer didnt bother to document. Its a restriction, but one we probably can live with. > 2) If the buffer is not in shared buffers, we don't have what it takes > to solve the problem yet. We do. Set up enough state for the case to be otherwise the same as the in s_b case. > But even if we solve this problem, we will > never really be sure that this is entirely safe, as per the argument > with concurrent smgrwrite() calls. Current in-core code assumes that > this can happen only for init forks of unlogged relations which would > not be visible yet in the backend doing a page check, still it can be > really easy to break this assumption with any new code added by a new > feature. It also happens in a few other cases than just init forks. But visibility & relation locking can take care of that. But you need to document that. If the locking allows concurent readers - and especially concurrent writers, then you cant really use smgrwite for anything but relation extension. Greetings, Andres Freund