Use pg_memory_is_all_zeros() in PageIsVerifiedExtended()
authorMichael Paquier <[email protected]>
Mon, 18 Nov 2024 02:44:11 +0000 (11:44 +0900)
committerMichael Paquier <[email protected]>
Mon, 18 Nov 2024 02:52:35 +0000 (11:52 +0900)
Relying on pg_memory_is_all_zeros(), which would apply SIMD instructions
when dealing with an aligned page, is proving to be at least three times
faster than the original size_t-based comparisons when checking if a
BLCKSZ page is full of zeros.  Note that PageIsVerifiedExtended() is
called each time a page is read from disk, and making it faster is a
good thing.

Author: Bertrand Drouvot
Discussion: https://postgr.es/m/CAApHDvq7P-JgFhgtxUPqhavG-qSDVUhyWaEX9M8_MNorFEijZA@mail.gmail.com

src/backend/storage/page/bufpage.c

index be6f1f62d292f2b13c6bdc0aebaa90f80d7e4620..aa264f61b9c453a4f9a8607f7b5af1565c1fefe6 100644 (file)
@@ -89,10 +89,8 @@ PageIsVerifiedExtended(Page page, BlockNumber blkno, int flags)
 {
    PageHeader  p = (PageHeader) page;
    size_t     *pagebytes;
-   int         i;
    bool        checksum_failure = false;
    bool        header_sane = false;
-   bool        all_zeroes = false;
    uint16      checksum = 0;
 
    /*
@@ -126,18 +124,9 @@ PageIsVerifiedExtended(Page page, BlockNumber blkno, int flags)
    }
 
    /* Check all-zeroes case */
-   all_zeroes = true;
    pagebytes = (size_t *) page;
-   for (i = 0; i < (BLCKSZ / sizeof(size_t)); i++)
-   {
-       if (pagebytes[i] != 0)
-       {
-           all_zeroes = false;
-           break;
-       }
-   }
 
-   if (all_zeroes)
+   if (pg_memory_is_all_zeros(pagebytes, BLCKSZ))
        return true;
 
    /*