Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t6l8b-00FKig-5D for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Nov 2024 06:28:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1t6l8X-00A2HP-Tg for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Nov 2024 06:27:58 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t6l8W-00A2G6-GP for pgsql-hackers@lists.postgresql.org; Fri, 01 Nov 2024 06:27:57 +0000 Received: from fhigh-a5-smtp.messagingengine.com ([103.168.172.156]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t6l8T-003uSF-Lm for pgsql-hackers@lists.postgresql.org; Fri, 01 Nov 2024 06:27:55 +0000 Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfhigh.phl.internal (Postfix) with ESMTP id 348761140151; Fri, 1 Nov 2024 02:27:52 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-11.internal (MEProxy); Fri, 01 Nov 2024 02:27:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1730442472; x=1730528872; bh=JsGG6b0a7L N/RwNzISsQKHWpudxzckTxKVSTwdzsmRQ=; b=LtY7DNVOB5N016avR0s1UzX051 TCgAcdyMM5dPnOSJIg+Xa1iS0lxTcD61A5v4+z8kbQcNJFh9Ij45E/YN7i1eoFN6 aY0YZg6FQXm7QOTp0IyUT+emeuabv+wo9JFZKuWnOKesxBxucP4jZZqt9hjaVnIL MfJ7cpYFuzaCDw0293EsQX3USxhf7uFZdbyfLwxS4LCCPFNkHxHCyZ1zVeZ/F7Kj eDlCD4tnaiDs8VYhLGkBqDYzgYq7Gc3W18OWIJbdEgJDz/sCUXgHomtwIl27Xf08 o8imAR2wTOt8mVY7o9NDp+GSdecf7DfF0riZeSjEDj3CXnWdjJT8cqsfQIcA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1730442472; x=1730528872; bh=JsGG6b0a7LN/RwNzISsQKHWpudxzckTxKVS TwdzsmRQ=; b=IoE0VLrqw7qv908JBPoFCuRJobTobQ/S1M8wj/gdXyI3Zbfe2Mw sAEdVs1VEFTGHulR8Sp6iQTAIa+b1SW5lNvoMdh936hq9KPkgn/Sqi9QdEh4X+Um z6XVgLjSNrBojhE/gTNzdgZrZCJLlFdpG41X6zsaG/xJD/PvjaclGq0FSTFpB58J CFOrteD5E+tapdVECPNLOhyE7qF5wiFHnYOd8WSL6FzOvsuWSyQflGwejYMIaaEo qOsPYbP5pG4g0eKKFWFSA0vgXkz9c/sZyLGx93+sFWesB6Iie2DWOlLdsmhHVSgs AucXNVhB2qET8O3AzZ1ZZ5GwSlTv6x9DzDQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdekkedgleefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnegfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvvefukfhf gggtuggjsehgtderredttddvnecuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruc eomhhitghhrggvlhesphgrqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepteel ieefudffhffhtdetleeggeegfffhkeeuveetiefgudduvedutefggeeivdejnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhes phgrqhhuihgvrhdrgiihiidpnhgspghrtghpthhtohepiedpmhhouggvpehsmhhtphhouh htpdhrtghpthhtohepughgrhhofihlvgihmhhlsehgmhgrihhlrdgtohhmpdhrtghpthht ohepsggvrhhtrhgrnhguughrohhuvhhothdrphhgsehgmhgrihhlrdgtohhmpdhrtghpth htohepshhmihhthhhpsgdvvdehtdesghhmrghilhdrtghomhdprhgtphhtthhopehpvght vghrsegvihhsvghnthhrrghuthdrohhrghdprhgtphhtthhopehhlhhinhhnrghkrgesih hkihdrfhhipdhrtghpthhtohepphhgshhqlhdqhhgrtghkvghrsheslhhishhtshdrphho shhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 1 Nov 2024 02:27:49 -0400 (EDT) Date: Fri, 1 Nov 2024 15:27:38 +0900 From: Michael Paquier To: David Rowley Cc: Bertrand Drouvot , Peter Smith , Peter Eisentraut , Heikki Linnakangas , pgsql-hackers@lists.postgresql.org Subject: Re: define pg_structiszero(addr, s, r) Message-ID: References: <36371fab-f90c-427c-9c14-210e93e9cd12@eisentraut.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="NJ1b5JVMdTICb1Gd" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --NJ1b5JVMdTICb1Gd Content-Type: multipart/mixed; boundary="3xp3NznjLn2eWmmj" Content-Disposition: inline --3xp3NznjLn2eWmmj Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Nov 01, 2024 at 05:45:44PM +1300, David Rowley wrote: > I think this should be passing BLCKSZ rather than (BLCKSZ / > sizeof(size_t)), otherwise, it'll just check the first 1 kilobyte is > zero rather than the entire page. Ugh, Friday brain fart. The attached should be able to fix that, this brings back the movl to its correct path: - movl $1024, %esi + movl $8192, %esi Does that look fine to you? > I didn't test how performance-critical this is, but the header comment > for this function does use the words "cheaply detect". Under gcc -O2 or -O3, the single-byte check or the 8-byte check don't make a difference. Please see the attached (allzeros.txt) for a quick check if you want to check by yourself. With 1M iterations, both average around 3ms for 1M iterations on my laptop (not the fastest thing around). Under -O0, though, the difference is noticeable: - 1-byte check: 3.52s for 1M iterations, averaging one check at 3.52ns. - 8-byte check: 0.46s for 1M iterations, averaging one check at 0.46ns. Even for that, I doubt that this is going to be noticeable in practice, still the difference exists. -- Michael --3xp3NznjLn2eWmmj Content-Type: text/x-csrc; charset=us-ascii Content-Disposition: attachment; filename="allzeros.c" #include #include #include #define BLCKSZ 8192 #define LOOPS 1000000 /* 1M */ static inline bool allzeros_char(const void *ptr, size_t len) { const char *p = (const char *) ptr; for (size_t i = 0; i < len; i++) { if (p[i] != 0) return false; } return true; } static inline bool allzeros_size_t(const void *ptr, size_t len) { const size_t *p = (const size_t *) ptr; for (size_t i = 0; i < len / sizeof(size_t); i++) { if (p[i] != 0) return false; } return true; } int main() { size_t pagebytes[BLCKSZ] = {0}; for (int i = 0; i < LOOPS; i++) { allzeros_char(pagebytes, BLCKSZ); //allzeros_size_t(pagebytes, BLCKSZ); } return 0; } --3xp3NznjLn2eWmmj Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="page-allzeros.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/storage/page/bufpage.c b/src/backend/storage/page/= bufpage.c index 5ee1e58cd4..db5954def2 100644 --- a/src/backend/storage/page/bufpage.c +++ b/src/backend/storage/page/bufpage.c @@ -88,7 +88,6 @@ bool PageIsVerifiedExtended(Page page, BlockNumber blkno, int flags) { PageHeader p =3D (PageHeader) page; - size_t *pagebytes; bool checksum_failure =3D false; bool header_sane =3D false; uint16 checksum =3D 0; @@ -124,9 +123,7 @@ PageIsVerifiedExtended(Page page, BlockNumber blkno, in= t flags) } =20 /* Check all-zeroes case */ - pagebytes =3D (size_t *) page; - - if (pg_memory_is_all_zeros(pagebytes, (BLCKSZ / sizeof(size_t)))) + if (pg_memory_is_all_zeros(page, BLCKSZ)) return true; =20 /* --3xp3NznjLn2eWmmj-- --NJ1b5JVMdTICb1Gd Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmckdNoACgkQnvQgOdby QH3/QA//W8BfXdYhYJqvQhBMDUJDqjc6R6vOaRrxFHhLbytlR31N7Bhp1zXSlgXI c2ujVbpUC18t4qAo94Ml/Q3uqdVdcO1wrc9+yzE0VAd6araIYWiQgwzIwGuTYAXV otnO0g5bR3wfEY3CyPAiK/Wly2dSpVL4q4xIjw+qC4hKbH4q7WRRh4wQFsR6OCgG nYsWehbreXt+fXTXj0D2+ITkYADAALLR2RVcLDKFnDqc+ZR5NYaWJl7vWG+Sq1Vt BTuETckBawAV1UB+cvjeccBTALGEyeJqFVJ1DsjxZ8edcI3pVXjzmCD1WknJhKAZ M942grrUAb2OHYDbpAxpqNjXpTOAw56aMXczeGTM/SpufJizNCYpKlhopUels9LM bj2e9/n4DgJVcxIJ3xZOGudruOv5Z0HWHGbiSN9r8w0L0X2L1uTdV4z3gYN9d0H9 KZr6gCgrjBK7nngU1gg45yqH5UvVj8hTnMVfPbnUhKrcdpbPhWnbCIxuyEysVgHZ F0kEDErs4oezKqbbIr7Zphzf5rEtCznBWQ+LtT94F9YzTEF9fs7DdnTbDmGV+m5D 67t2gjoTPlJCzqqGCTabXpLocqxXypQ2o0qgxYWLVdgINeObDSz5WH8zJZb0ErNB EFt7ZRxWbyNOey8xXeKs8Gybz4fK5/4S8LOeKVl8WdYCyrMsvLs= =SMZ/ -----END PGP SIGNATURE----- --NJ1b5JVMdTICb1Gd--