Re: define pg_structiszero(addr, s, r)
Michael Paquier <michael@paquier.xyz>
From: Michael Paquier <michael@paquier.xyz>
To: David Rowley <dgrowleyml@gmail.com>
Cc: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>, Ranier Vilela <ranier.vf@gmail.com>, Peter Smith <smithpb2250@gmail.com>, Peter Eisentraut <peter@eisentraut.org>, Heikki Linnakangas <hlinnaka@iki.fi>, pgsql-hackers@lists.postgresql.org
Date: 2024-11-07T00:44:32Z
Lists: pgsql-hackers
Attachments
- allzeros.c (text/x-csrc)
On Thu, Nov 07, 2024 at 08:10:17AM +1300, David Rowley wrote:
> Did you try with a size where there's a decent remainder, say 124
> bytes? FWIW, one of the cases has 112 bytes, and I think that is
> aligned memory meaning we'll do the first 64 in the SIMD loop and have
> to do 48 bytes in the byte-at-a-time loop. If you had the loop Michael
> mentioned, that would instead be 6 loops of size_t-at-a-time.
See the attached allzeros.c, based on the previous versions exchanged.
And now just imagine a structure like that:
#define BLCKSZ 48
typedef union AlignedBlock
{
char data[BLCKSZ];
double force_align_d;
int64_t force_align_i64;
} AlignedBlock;
This structure is optimized so as the first step to do the char step
is skipped because the pointer is aligned when allocated, and the
second step with the potential SIMD is skipped because the structure
is small enough at 48 bytes. Hence only the last step would do the
allzero check. Adding a size_t step to force a loop is going to be
more efficient, as proved upthread:
$ gcc -o allzeros -march=native -O2 allzeros.c
$ ./allzeros
allzeros: done in 118332297 nanoseconds
allzeros_v2: done in 13877745 nanoseconds (8.52677 times faster)
The allzero check is used for pgstat entries, and it could be possible
that some out-of-core code needs to rely on such small-ish sizes, or
even something else when a patch author feels like it. So let's make
that optimized as much as we think we can: that's what this discussion
is about.
--
Michael
Commits
-
Use pg_memory_is_all_zeros() in PageIsVerifiedExtended()
- 03a42c9652f8 18.0 landed
-
Optimize pg_memory_is_all_zeros() in memutils.h
- 5be1dabd2ae0 18.0 landed
-
Remove use of pg_memory_is_all_zeros() in bufpage.c
- e819bbb7c82a 18.0 landed
-
Add pg_memory_is_all_zeros() in memutils.h
- 07e9e28b56db 18.0 landed