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 1t812q-001Vc5-6z for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Nov 2024 17:39:15 +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 1t812m-003h7F-0X for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Nov 2024 17:39:12 +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 1t812l-003h76-Ll for pgsql-hackers@lists.postgresql.org; Mon, 04 Nov 2024 17:39:12 +0000 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1t812i-000B7q-8s for pgsql-hackers@lists.postgresql.org; Mon, 04 Nov 2024 17:39:11 +0000 Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-7eda47b7343so2814616a12.0 for ; Mon, 04 Nov 2024 09:39:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730741946; x=1731346746; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=98WsA2iPPYFmnjcMJROHFrIGtJcIZVG1cQ66IHiDA+I=; b=Z16eHXqUitnIYksuh8tmPFo2/mOOc+2grRp+TxrjXBPQoEXi4HVdr4xmNYwqMYkIWu q7McZ47TuzcQ60A489TYdE/Xbmdk0/mabs8olMilkUXh2tl03sJpENCCRZ1qkFaXbHTo XyXTPau0LK/yBM0mBhhYQr6bFQo1sbOZHWv/ZCqKscXMUMZBSlhO6ytu/8II6W5TeEuC A8ivJQt5ySQG3QT/sKnmK3DUwgEgpmc2/dhtqL1CSmqW/wR84T+C6PmMM89Zv60Q6Sa6 Uu8HtFG9XodCdKJgV9DtnyIzKY8bNJovG/5CetHyggLK8hjZGlbHCD7SSmHfLo0P3d0b wmdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741946; x=1731346746; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=98WsA2iPPYFmnjcMJROHFrIGtJcIZVG1cQ66IHiDA+I=; b=WrcuGKpoiyyAPe1sluT/96gZETEcU9c2yR7xzqc9/tLqXmhk7Ls2Pmfa6wewav/H79 mvM637WneiLQt8hWg4mWcdldaNtEbUQmIa5J6pS8h4baQQ8pjiP+VqPMFoC+sqJzqVEv CcyrqZZ4PYU0VwpDO3e2jWfsPceK6xQNKA6L0Sh9A0qw9oWuxqKIMW5jmAD0zJBr9RDW YIJNdeMP2CdCMvEQvS3QyylKluIEd8HzzxGzDshY03B7fVEjldKMwOEgyKjga+kcRto0 7Ynkz5Y31VmgO1l7o4XzlCJaAdrzGdog8xZj3X/rSVel6l3yV3Jje+fABkgNNW0bKpR5 Zlcg== X-Forwarded-Encrypted: i=1; AJvYcCXTL6Dyfhuc1Uqq3Tk6GqJ1f+4j5yBRhB2j8gdIV0CVIzzWVqkIsxtTKTL/wzpIew5mu8xTxhkHJil5p3Wr@lists.postgresql.org X-Gm-Message-State: AOJu0YwlY/HnfBjkcaS5gG775iOzWV1KMtQjTZmPU4kfNNxtPNZKDRXJ cnHBCOYUIWAEikiqc6wP9r3etUuKly9eiVz/lG/Po5+p/y8n0ZKF40xsfuwVVZ0pbq3UF5M4zJs +irrFtg/FiXB4e93N4QRIf4p/ivo= X-Google-Smtp-Source: AGHT+IG7raluCTcLdHIi7FEf7q0bo3CisAUx8LArHSrYunyAbk9K/wcqPd5f6teZUjbeITNxsyi2XrWb1aIJSsMLyPk= X-Received: by 2002:a05:6a20:6a23:b0:1db:ec83:ca4f with SMTP id adf61e73a8af0-1dbec83d697mr1128078637.3.1730741946515; Mon, 04 Nov 2024 09:39:06 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Ranier Vilela Date: Mon, 4 Nov 2024 14:38:54 -0300 Message-ID: Subject: Re: define pg_structiszero(addr, s, r) To: Bertrand Drouvot Cc: David Rowley , Michael Paquier , Peter Smith , Peter Eisentraut , Heikki Linnakangas , pgsql-hackers@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000eb8b2a062619c29f" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000eb8b2a062619c29f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi. Em seg., 4 de nov. de 2024 =C3=A0s 14:18, Bertrand Drouvot < bertranddrouvot.pg@gmail.com> escreveu: > Hi, > > 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: > > > > I'm happy if you want to pick this up and continue working on it. > > Sure, please find attached v1, the changes are: > > - 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 > - adding an Assert for ptr !=3D 0 > - re-introduce the function call in PageIsVerifiedExtended() > - propose a commit message > I think we can add a small optimization to this last patch [1]. The variable *aligned_end* is only needed in the second loop (for). So, only before the for loop do we actually declare it. Result before this change: check zeros using BERTRAND 1 0.000031s Result after this change: check zeros using BERTRAND 1 0.000018s + const unsigned char *aligned_end; + /* Multiple bytes comparison(s) at once */ + aligned_end =3D (const unsigned char *) ((uintptr_t) end & (~(sizeof(size_t) - 1))); + for (; p < aligned_end; p +=3D sizeof(size_t)) best regards, Ranier Vilela [1] https://godbolt.org/z/fvdzjbnc7 --000000000000eb8b2a062619c29f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi.

Em seg., 4 de nov. de 2024 =C3=A0s 14:18, Ber= trand Drouvot <bertrandd= rouvot.pg@gmail.com> escreveu:
Hi,

On Tue, Nov 05, 2024 at 12:24:48AM +1300, David Rowley wrote:
> On Sat, 2 Nov 2024 at 01:50, Bertrand Drouvot
> <= bertranddrouvot.pg@gmail.com> wrote:
> >
> > On Fri, Nov 01, 2024 at 09:47:05PM +1300, David Rowley wrote:
> > > I've attached what I thought a more optimal version migh= t 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:
>
> I'm happy if you want to pick this up and continue working on it.<= br>
Sure, please find attached v1, the changes are:

- switch from "const char" to "const unsigned char" (co= uld have been done in the
current version of pg_memory_is_all_zeros() though)
- added some comments
- adding an Assert for ptr !=3D 0
- re-introduce the function call in PageIsVerifiedExtended()
- propose a commit message

I think we c= an add a small optimization to this last patch [1].
The variable *aligne= d_end* is only needed in the second loop (for).
So, only before the for = loop do we actually declare it.

Result before this change:
check = zeros using BERTRAND 1 0.000031s

Result after this change:
check = zeros using BERTRAND 1 0.000018s

+ const unsigned = char *aligned_end;

+ /* Multiple bytes comparison(= s) at once */
+ aligned_end =3D (const unsigned char *) ((uintptr_t) end= & (~(sizeof(size_t) - 1)));
+ for (; p < aligned_end; p +=3D siz= eof(size_t))

best rega= rds,
Ranier Vilela

--000000000000eb8b2a062619c29f--