pg_buffercache: Fix memory allocation formula
authorMichael Paquier <[email protected]>
Thu, 11 Dec 2025 05:11:06 +0000 (14:11 +0900)
committerMichael Paquier <[email protected]>
Thu, 11 Dec 2025 05:11:06 +0000 (14:11 +0900)
The code over-allocated the memory required for os_page_status, relying
on uint64 for its element size instead of an int, hence doubling what
was required.  This could mean quite a lot of memory if dealing with a
lot of NUMA pages.

Oversight in ba2a3c2302f1.

Author: David Geier <[email protected]>
Discussion: https://postgr.es/m/ad0748d4-3080-436e-b0bc-ac8f86a3466a@gmail.com
Backpatch-through: 18

contrib/pg_buffercache/pg_buffercache_pages.c

index 702307a49e25ecc1029a2ddbe86c2af0a549a466..e18fed220460e69d30884520e765aec7e4b1ebbb 100644 (file)
@@ -383,7 +383,7 @@ pg_buffercache_os_pages_internal(FunctionCallInfo fcinfo, bool include_numa)
 
            /* Used to determine the NUMA node for all OS pages at once */
            os_page_ptrs = palloc0(sizeof(void *) * os_page_count);
-           os_page_status = palloc(sizeof(uint64) * os_page_count);
+           os_page_status = palloc(sizeof(int) * os_page_count);
 
            /*
             * Fill pointers for all the memory pages.  This loop stores and