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 1kYCUy-00039g-Ep for pgsql-hackers@arkaria.postgresql.org; Thu, 29 Oct 2020 18:18:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kYCUR-0002Ab-Ic for pgsql-hackers@arkaria.postgresql.org; Thu, 29 Oct 2020 18:17:35 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kYCUR-0002AA-BU for pgsql-hackers@lists.postgresql.org; Thu, 29 Oct 2020 18:17:35 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kYCUO-0001HC-TP for pgsql-hackers@lists.postgresql.org; Thu, 29 Oct 2020 18:17:34 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 385F65C011A; Thu, 29 Oct 2020 14:17:31 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 29 Oct 2020 14:17:31 -0400 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=fm2; bh=+W+VGhRSCx9wgSuru3tV2fFOLpR C/PDkkk4iPylhhXw=; b=aiYaVLfrcKqcpFwNSCqG5Fd8g+fQb5NkfprrE2e0HZ/ UFBOElsgWc8JBMigR0klsxd8JQU6wR6yRlasmhAsmNeD4N0koGB6EObnwok8TOpP IVWD1udi7I9QLk+IO+iS8yqeGAlHRW69VlAy8kr7/Z0QxGYU2zn0x9hlACHuYt+q hwSiAycgFp/ur0mbuCyOgs4FF1t06XY8Gd9GpVAy1P1vRgnuu7CKxdDQqTyXQNkv 1dTqDXiXU/4VMG0i+Dz3NraRPxAZXEanVd4oVz9okQBh+tg0o7mB/ttJGeHEYaZL 6cTPyBaykO4JqLSNHJXF6ke+FcwmL5O/YnNvFmX4Ykg== 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=+W+VGh RSCx9wgSuru3tV2fFOLpRC/PDkkk4iPylhhXw=; b=MhuYt3oGduWVxxlUFdVHtX XnsPQm/c/852NgD/O1q6TqrXc5AZSkCom6X8iXJWmidYinpKukKVxpI4P9P/qr09 T5eie4sC03Be+FFIXijKOCaF7JmlrrAB2+5xXkbaKx/KwswyYbSQxCtrPK1TgjXM w9cN6I3QesizIy2JE6i1C75fUbmQzD2whfQA/Qc1Lo81nMdlCZOpgCS+ldkRUfQa MCMsAX2vnC9QfDu9qvYpNAKiBuxsd2k1dgcdl/m+GJPAHMaLukiQRK7oNShzYS83 a4higoJyEQvLRitZ36+Xda8LftD0uLQmGnRNh3UgkWui5VOfeMzjaaINv9u8V2mQ == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrleefgdduuddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeetnhgurhgv shcuhfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucggtffrrg htthgvrhhnpedukefhkeelueegveetheelffffjeegleeuudelfeefuedtleffueejfffh ueffudenucfkphepieejrdduiedtrddvudejrddvhedtnecuvehluhhsthgvrhfuihiivg eptdenucfrrghrrghmpehmrghilhhfrhhomheprghnughrvghssegrnhgrrhgriigvlhdr uggv 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 571AE3064683; Thu, 29 Oct 2020 14:17:30 -0400 (EDT) Date: Thu, 29 Oct 2020 11:17:29 -0700 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: <20201029181729.2nrub47u7yqncsv7@alap3.anarazel.de> References: <20201019023918.GB9612@paquier.xyz> <20201019075248.GD9612@paquier.xyz> <20201023072832.GE5180@paquier.xyz> <20201023090630.GA26347@paquier.xyz> <20201027070746.GD28445@paquier.xyz> <20201028050852.GF28445@paquier.xyz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201028050852.GF28445@paquier.xyz> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, On 2020-10-28 14:08:52 +0900, Michael Paquier wrote: > Thanks for confirming. I have gone through the whole set today, > splitted the thing into two commits and applied them. We had > buildfarm member florican complain about a mistake in one of the > GetDatum() calls that I took care of already, and there is nothing > else on my radar. The code does IO while holding the buffer mapping lock. That seems *entirely* unacceptable to me. That basically locks 1/128 of shared buffers against concurrent mapping changes, while reading data that is likely not to be on disk? Seriously? /* 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) { uint32 buf_state; /* * Found it. Now, retrieve its state to know what to do with it, and * release the pin immediately. We do so to limit overhead as much as * possible. We keep the shared LWLock on the target buffer mapping * partition for now, so this buffer cannot be evicted, and we acquire * an I/O Lock on the buffer as we may need to read its contents from * disk. */ bufdesc = GetBufferDescriptor(buf_id); LWLockAcquire(BufferDescriptorGetIOLock(bufdesc), LW_SHARED); buf_state = LockBufHdr(bufdesc); UnlockBufHdr(bufdesc, buf_state); /* If the page is dirty or invalid, skip it */ if ((buf_state & BM_DIRTY) != 0 || (buf_state & BM_TAG_VALID) == 0) { LWLockRelease(BufferDescriptorGetIOLock(bufdesc)); LWLockRelease(partLock); return true; } /* 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); } The justification in the in-shared-buffers case seems to completely mis-judge costs too: * Found it. Now, retrieve its state to know what to do with it, and * release the pin immediately. We do so to limit overhead as much as * possible. We keep the shared LWLock on the target buffer mapping * partition for now, so this buffer cannot be evicted, and we acquire * an I/O Lock on the buffer as we may need to read its contents from * disk. a pin is cheap. Holding the partition lock is not. Also, using char[BLCKSZ] as a buffer isn't ok. This should use PGAlignedBlock: /* * Use this, not "char buf[BLCKSZ]", to declare a field or local variable * holding a page buffer, if that page might be accessed as a page and not * just a string of bytes. Otherwise the variable might be under-aligned, * causing problems on alignment-picky hardware. (In some places, we use * this to declare buffers even though we only pass them to read() and * write(), because copying to/from aligned buffers is usually faster than * using unaligned buffers.) We include both "double" and "int64" in the * union to ensure that the compiler knows the value must be MAXALIGN'ed * (cf. configure's computation of MAXIMUM_ALIGNOF). */ typedef union PGAlignedBlock I think this needs to be quickly reworked or reverted. Greetings, Andres Freund