Re: define pg_structiszero(addr, s, r)
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
From: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
To: Ranier Vilela <ranier.vf@gmail.com>
Cc: Michael Paquier <michael@paquier.xyz>, David Rowley <dgrowleyml@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-15T14:43:32Z
Lists: pgsql-hackers
Hi,
On Fri, Nov 15, 2024 at 09:54:33AM -0300, Ranier Vilela wrote:
> There is a tiny typo with V13.
> + /* "len" in the [sizeof(size_t) * 8, inf] range */
I think "[sizeof(size_t) * 8, inf[ range" is correct. Infinity can not be included
into a interval.
Thinking about it, actually, "[sizeof(size_t) * 8, inf)" (note the ')' at the end)
might be the proper notation from a mathematical point of view.
> But, I'm not sure if I'm still doing something wrong.
> If so, forgive me for the noise.
>
> Of course I expected "not is_allzeros".
That's the test case which is "wrong" (not the function):
"
size_t pagebytes[BLCKSZ] = {0};
volatile bool result;
pagebytes[BLCKSZ-2] = 1;
result = pg_memory_is_all_zeros_v12(pagebytes, BLCKSZ);
"
The pagebytes is an array of size_t (8 bytes each), so the actual array size
is 8192 * 8 = 65536 bytes.
So, pagebytes[BLCKSZ-2] = 1, sets byte 65528 ((8192-2)*8) to 1.
But the function is checking up to BLCKSZ bytes (8192), so the results you
observed (which are correct).
> Anyway, I made another attempt to optimize a bit more, I don't know if it's
> safe though.
There is an issue in your v14, it calls:
"
return pg_memory_is_all_zeros_simd(ptr, ptr + len);
"
but you defined it that way:
"
static inline bool
pg_memory_is_all_zeros_simd(const size_t *p, const size_t * end)
"
while that should be:
"
static inline bool
pg_memory_is_all_zeros_simd(const void *p, const void *end)
"
Doing so, I do not observe any improvments with v14.
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
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