diff options
author | Michael Paquier <michael@paquier.xyz> | 2024-11-01 11:35:46 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2024-11-01 11:35:46 +0900 |
commit | 07e9e28b56db4d8533b62b3a921f1e74aae26b1f (patch) | |
tree | 3811ed7c85d79d4e55525139a1f8ac3928fd572a /src/include | |
parent | 49d6c7d8dabad8c59ba21afe72ff32e79f822291 (diff) | |
download | postgresql-07e9e28b56db4d8533b62b3a921f1e74aae26b1f.tar.gz postgresql-07e9e28b56db4d8533b62b3a921f1e74aae26b1f.zip |
Add pg_memory_is_all_zeros() in memutils.h
This new function tests if a memory region starting at a given location
for a defined length is made only of zeroes. This unifies in a single
path the all-zero checks that were happening in a couple of places of
the backend code:
- For pgstats entries of relation, checkpointer and bgwriter, where
some "all_zeroes" variables were previously used with memcpy().
- For all-zero buffer pages in PageIsVerifiedExtended().
This new function uses the same forward scan as the check for all-zero
buffer pages, applying it to the three pgstats paths mentioned above.
Author: Bertrand Drouvot
Reviewed-by: Peter Eisentraut, Heikki Linnakangas, Peter Smith
Discussion: https://postgr.es/m/ZupUDDyf1hHI4ibn@ip-10-97-1-34.eu-west-3.compute.internal
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/utils/memutils.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/include/utils/memutils.h b/src/include/utils/memutils.h index cd9596ff219..3590c8bad9a 100644 --- a/src/include/utils/memutils.h +++ b/src/include/utils/memutils.h @@ -189,4 +189,21 @@ extern MemoryContext BumpContextCreate(MemoryContext parent, #define SLAB_DEFAULT_BLOCK_SIZE (8 * 1024) #define SLAB_LARGE_BLOCK_SIZE (8 * 1024 * 1024) +/* + * Test if a memory region starting at "ptr" and of size "len" is full of + * zeroes. + */ +static inline bool +pg_memory_is_all_zeros(const void *ptr, size_t len) +{ + const char *p = (const char *) ptr; + + for (size_t i = 0; i < len; i++) + { + if (p[i] != 0) + return false; + } + return true; +} + #endif /* MEMUTILS_H */ |