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 1t8BEo-002YUa-CZ for pgsql-hackers@arkaria.postgresql.org; Tue, 05 Nov 2024 04:32:18 +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 1t8BEl-008opW-FJ for pgsql-hackers@arkaria.postgresql.org; Tue, 05 Nov 2024 04:32:16 +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 1t8BEk-008opO-IP for pgsql-hackers@lists.postgresql.org; Tue, 05 Nov 2024 04:32:15 +0000 Received: from fout-a4-smtp.messagingengine.com ([103.168.172.147]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t8BEi-000F7o-7y for pgsql-hackers@lists.postgresql.org; Tue, 05 Nov 2024 04:32:13 +0000 Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfout.phl.internal (Postfix) with ESMTP id 79B3113805E5; Mon, 4 Nov 2024 23:32:11 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-12.internal (MEProxy); Mon, 04 Nov 2024 23:32:11 -0500 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=1730781131; x=1730867531; bh=WX9RlXebiV TI4s5ShXwks6zhodVrVqefAB/KiIgk6y0=; b=Z4J5t3cG4RBKNidq5okVOnSHoG /OIvLavQ0errWJSOPfi0LCneK5yTQs0swCStMS6lJZCnawN8q+rWWnal7AklHwdl sbl6WVAaRVbSN9G7kL2ljGG8a6MvkT313SIe+R3vP8UZ27jtWg2ankO4WwE6elFr r9mrujkDylhrr36Lu1ifZpllJI9CjS1wkc8Dem+UbMypiGtZ9dbnMlympIqSdjld KbcD04LiFohQLO+F+aY+XpShR6byY79xTL9PjZhTwb6lGjkZr5v08BT9lEuOPz3Y h9qZsc5FbvQFo6rs8QxLTQXaXz/PxernXnnv7cYCx3nFUEeIoKN7XFq3w61A== 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= 1730781131; x=1730867531; bh=WX9RlXebiVTI4s5ShXwks6zhodVrVqefAB/ KiIgk6y0=; b=KzKIDgDF+jCAhfRSYUK+nGjq1o1iTfj6ZgxVrWHhp/pA/W/jlnN Ifjsf9+XpGscW4QNTjCQ4NWfGkJdDa81hsET4/QdfX2NDV51bX6CRv4CjzSnqpFS G71ZlBU/Sa7OsS7JlsQUNetWBt6TQvazETXp2Sas0IYQ4WUQwfIaST8nxKx0js7K Rkl0pAgfTUa+2pPKuPSUH58rJQV3NqgvjQMmdWb5BqbPNeHJZWwstVf2RIeiPINO yyhrKqhuVYYzM6AdV+4UzyBcPL2OfeK2+xde4qrppeSjviUHUS78ijH9spr23NNu hcRPViqeLxmstjCwVsb0s2/ZJVqWNb+epXw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdeljedgjeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnegfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvvefukfhf gggtuggjsehgtdorredttddvnecuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruc eomhhitghhrggvlhesphgrqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepffdu leehgefhkeefgfeftdfhkedutddvhfdukeeggeehieekffelhfelkeehteefnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhes phgrqhhuihgvrhdrgiihiidpnhgspghrtghpthhtohepiedpmhhouggvpehsmhhtphhouh htpdhrtghpthhtohepsggvrhhtrhgrnhguughrohhuvhhothdrphhgsehgmhgrihhlrdgt ohhmpdhrtghpthhtohepughgrhhofihlvgihmhhlsehgmhgrihhlrdgtohhmpdhrtghpth htohepshhmihhthhhpsgdvvdehtdesghhmrghilhdrtghomhdprhgtphhtthhopehpvght vghrsegvihhsvghnthhrrghuthdrohhrghdprhgtphhtthhopehhlhhinhhnrghkrgesih hkihdrfhhipdhrtghpthhtohepphhgshhqlhdqhhgrtghkvghrsheslhhishhtshdrphho shhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 4 Nov 2024 23:32:09 -0500 (EST) Date: Tue, 5 Nov 2024 13:31:58 +0900 From: Michael Paquier To: Bertrand Drouvot Cc: David Rowley , Peter Smith , Peter Eisentraut , Heikki Linnakangas , pgsql-hackers@lists.postgresql.org Subject: Re: define pg_structiszero(addr, s, r) Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="mpLK473rJOm5hlxr" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --mpLK473rJOm5hlxr Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Nov 04, 2024 at 05:17:54PM +0000, Bertrand Drouvot wrote: > Hi, >=20 > On Tue, Nov 05, 2024 at 12:24:48AM +1300, David Rowley wrote: > > On Sat, 2 Nov 2024 at 01:50, Bertrand Drouvot > > wrote: > > > > > > On Fri, Nov 01, 2024 at 09:47:05PM +1300, David Rowley wrote: > > > > I've attached what I thought a more optimal version might look like= in > > > > case anyone thinks making it better is a good idea. > > > > > > > > > > Thanks for the proposal! > > > > > > I like the idea, I think that's worth to add a few comments, somethin= g like: > >=20 > > I'm happy if you want to pick this up and continue working on it. >=20 > Sure, please find attached v1, the changes are: >=20 > - switch from "const char" to "const unsigned char" (could have been done= in the > current version of pg_memory_is_all_zeros() though) > - added some comments + * The test is divided into three phases for efficiency: + * - Initial alignment (byte per byte comparison) + * - Multiple bytes comparison at once + * - Remaining bytes (byte per byte comparison) It does not look like this insists enough on the alignment part of the optization? A MAXALIGN'd size would use only size_t comparisons, and a pointer aligned would do no byte comparisons. > - adding an Assert for ptr !=3D 0 I'm not sure that the Assert() addition is a good idea. That could get hot very easily depending on the caller, even if for assert builds we don't care much about the performance, that could lead to some paths being a lot slower. On Fri, 01 Nov 2024 at 21:47, David Rowley wr= ote: > The thought of having to write a comment to warn people not to use it > for performance-critical things makes me think it might be better just > to write a more optimal version of the function so we don't need to > warn people. I looked around at the callers of the function I saw the > following numbers of bytes being used for the length: 8192 (the one in > question), 88, 32 and 112. > > I don't know how performance-critical the final three of those are, > but I imagine all apart from the 32-byte one might be better with a > non-inlined and more optimised version of the function. The problem > with inlining the optimised version is that it's more code to inline. These three don't matter in terms of performance. The cycles spent for all-zero checks of the checkpointer and bgwriter are nothing compared to the concurrent I/O activity they handle, and the sizes are small compared to the 8k pages. The flush callback for relation pgstats happens once at a given interval (see around PGSTAT_[MIN|MAX]_INTERVAL). -- Michael --mpLK473rJOm5hlxr Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmcpn74ACgkQnvQgOdby QH0Flw//ZWrFXPnvIEXWMNDwOs1gs9jCTyXnnpina3hwW2Ovm/I6FlvR8WXA1Z1s MkPuVYzCKsATcRilEuR+Yii83eN0I8wF0c+DFt/BpXiIDEXrlVsil2WlM6uIijy3 zoSH9kSvfr/v45Z85JRy5BW8ttuEJzgVFstRQ3ueygWlUGeVPuPjO3ZSDsig6tBB qj7096g/mzgp18qyCW8BrmkIFqG0BqIqA5pehWGy0V68j+1mzdB9I+qA+EUSxEwR UVqEXazGXOGK5jigA3mIUQZGoOQc/dYzi/a9wrfk2Vx0k0bKoKpd6s2nL6+pwNUF PD5fjwDZWG7AwW+RF6XxQdTgL0nEy7QKz/K4/ATDVxojyWITyf3z87yg3Ymgq9Pt qbTIdWIPvSDOOdrXiIZMtQ6hWzB8Bhu364wmNFxx3v78vwZpbb/WRyb6SiuyAd4Q qqKmmPmDmR4Q11XZHnk1y+yBlwSbzzTEDJ2STGKqGSfAzFzWdPz+2bV5SWKnhyDv xNofNuxiWu4ivZ/KcIlnujcT0naekbxOxFil8WFJPOERB/STix3W2eDn2MDDEF7R CUtgDG0R1u+OgdOYN6zHFEUHrx1UivZmvXri2mT7uSaaBJgaPwXMWnp/yGeZYgqB UvMgvixelAmN2rPX85dwoCHxREuSwBId93uA6Cdt0LdvYkbqlcs= =gwjt -----END PGP SIGNATURE----- --mpLK473rJOm5hlxr--