Re: define pg_structiszero(addr, s, r)

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
Cc: David Rowley <dgrowleyml(at)gmail(dot)com>, Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>, Peter Smith <smithpb2250(at)gmail(dot)com>, Peter Eisentraut <peter(at)eisentraut(dot)org>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: define pg_structiszero(addr, s, r)
Date: 2024-11-14 00:27:06
Message-ID: ZzVD2tUN-hSVT6xG@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Nov 13, 2024 at 07:50:50AM +0000, Bertrand Drouvot wrote:
> I did a quick check with clang and it looks like it is not as smart as gcc
> for the non inline case.

Not as much, still smart enough to skip the > 64B part when dealing
with a structure that does not require it. So it's actually still
good considering where we are at now on HEAD for the 8kB all-zero page
case.

> Anyway it's not like we have the choice: we need (at least) one len check for
> safety reason (to not crash or read invalid data).
>
> So, I'd vote for pg_memory_is_all_zeros_v12() then, thoughts?

Makes sense to me to just do that, with a first < 8 loop, and a second
for the 8~63 range. And I can understand the code I read here as it
self-documents what it does.

* There is no risk to read beyond the memory area thanks to the len < 64
* check done below.

This comment should do a s/below/above/ and a s/check/checks/, as it
refers to the two checks done before the trick with the 64B-per-loop
check.

There is also a "cant'" in the last size_t check. Simple typo.
--
Michael

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2024-11-14 00:35:18 Re: .ready and .done files considered harmful
Previous Message Peter Smith 2024-11-13 23:58:45 Re: Introduce XID age and inactive timeout based replication slot invalidation