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 1t6r6Y-00G1Cu-Pu for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Nov 2024 12:50: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 1t6r6X-00DRkq-4U for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Nov 2024 12:50:17 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t6r6W-00DRiR-Pw for pgsql-hackers@lists.postgresql.org; Fri, 01 Nov 2024 12:50:17 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1t6r6U-004BTk-HJ for pgsql-hackers@lists.postgresql.org; Fri, 01 Nov 2024 12:50:16 +0000 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-37d462c91a9so1221268f8f.2 for ; Fri, 01 Nov 2024 05:50:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730465413; x=1731070213; darn=lists.postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=hHeZQbmklTTc/MstzqIm06jOwtsPMp1aje2yd8IjrMI=; b=OSoJWd9g4mV4ltq0Szkqhi7GcZxwHFINlrWuEZ14n4LhJfe+9EsU4u5/WgZnsr9noZ zDNiOnDaLPOhdqqQE0yalkM1u5Xzexu+iafgI7TkSb+dJHUEcpyTXdYr+Biz7JJAWjOE dRW1JwcwB3iPktnXTGEQM+zl0fEuHjLUpktqnvCh+tZSS9iXa2Onuyl8LgiDIrBfs8GK BzB8Zom0tQjMh9DkHxsuzGYTr0V63JxSZRz4vOUorhu/i9AgHPqeqg51AZJ7wZ0KjJXP mbe6pc/aAHx5zbZbDZ9QkXAx3tLxmNcCgQhP/EyPhGsBWQFJQgxAMof/46YgGwh2ut0x PKxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730465413; x=1731070213; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=hHeZQbmklTTc/MstzqIm06jOwtsPMp1aje2yd8IjrMI=; b=c+CGpnEYXufq15wZ6avy+9dNomxwMySLBCVf+jAzffGu4w2aS4rKeQfKzOfBPr+MOr VOwPq1VgnKhmUo7EQCbk5F9i0edlFDa7kq/eUoMbk3oLZ44TUrzTsvzYDhEKwGRYyMSe fQDtZeeXzLBvBgJs+zgaN8pnomVQFvs30fcPkWjZpVBQEiEpwIC0Ua/uQmaVwXkSZxtg O4iNNTsPXtNUNAZqrP6ZYF2saKGek737Nt/zgSMgYuBXeoNQ7d9IflQrX76RIz91Zfpv CEi2z0ze87/u9PeiuRezfxErUmrGgfehUjJ2RIey2koDPskJkHaAz+KhOJE7CEKFn40X d8aQ== X-Forwarded-Encrypted: i=1; AJvYcCW2ZQdT2x9JB3T5uTFcGJuEdVvA/fq36898RrEQL1muv6W4UhwGiR6v81nRxu3AOZNSaxI9suUMvw7STpZP@lists.postgresql.org X-Gm-Message-State: AOJu0YwXLo77La4oLj878LKEgoAu+iE/OQDqNJwU7LRzyf0arNkEmOpN EMMAIK8jVHKHom3fMh08QparlByIp5BPkxRRGeqOG5mzr4CKBV4C X-Google-Smtp-Source: AGHT+IFEaT29ZXppLVSxBoRlIlsHjO9OeVfm23aqysKXHeUWvhsVEXfuZb1uDGh9Y98h60ZFN526AA== X-Received: by 2002:a5d:4d82:0:b0:371:8319:4dcc with SMTP id ffacd0b85a97d-381b705764fmr8231503f8f.2.1730465412849; Fri, 01 Nov 2024 05:50:12 -0700 (PDT) Received: from ip-10-97-1-34.eu-west-3.compute.internal (ec2-15-236-134-5.eu-west-3.compute.amazonaws.com. [15.236.134.5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4327d5abfb1sm60740995e9.9.2024.11.01.05.50.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Nov 2024 05:50:12 -0700 (PDT) Date: Fri, 1 Nov 2024 12:50:10 +0000 From: Bertrand Drouvot To: David Rowley Cc: Michael Paquier , 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: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Fri, Nov 01, 2024 at 09:47:05PM +1300, David Rowley wrote: > On Fri, 1 Nov 2024 at 20:49, Michael Paquier wrote: > > > > On Fri, Nov 01, 2024 at 07:44:22AM +0000, Bertrand Drouvot wrote: > > > Worth to add a comment as to why pg_memory_is_all_zeros() should not > > > be used here? > > > > I would not add one in bufpage.c, documenting that where > > pg_memory_is_all_zeros() is defined may be more adapted. > > 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. Yeah, that's probably a good idea to write a more elaborate function. > 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. I agree that's more code to inline and contains multiple loops and branches. For the last 3 callers, I think that non inline would still be "cheap" as compared to what lead to those code paths (stats increments). > 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, something like: 1 === + while (((uintptr_t) p & (sizeof(size_t) - 1)) != 0) Add a comment like "Checks bytes, byte by byte, until the pointer is aligned"? 2 === + for (; p < aligned_end; p += sizeof(size_t)) Add a comment like "Multiple bytes comparison(s) at once"? 3 === + while (p < end) + { Add a comment like "Compare remaining bytes, byte by byte"? 4 === Out of curiosity I did test your proposal and it performs well (see [0]) for the PageIsVerifiedExtended() case. [0]: https://godbolt.org/z/Mdaxz5W7c Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com