Shmem allocated wrong for custom cumulative stats
Heikki Linnakangas <hlinnaka@iki.fi>
From: Heikki Linnakangas <hlinnaka@iki.fi>
To: "pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>
Cc: Michael Paquier <michael@paquier.xyz>
Date: 2026-04-06T00:16:47Z
Lists: pgsql-hackers
Attachments
- 0001-Use-the-allocated-space-properly-for-custom-stats-ki.patch (text/x-patch) patch 0001
There's only one call of ShmemAlloc() left in the tree outside shmem.c, in StatsShmemInit(), and that call doesn't look right: The StatsShmemSize() function takes those allocations into account when it calculates the size for the "Shared Memory Stats" shmem area, but ShmemAlloc() doesn't use that reservation, it uses the general-purpose unreserved shmem that then shows up as "<anonymous>" in pg_shmem_allocations. The space reserved with ShmemRequestStruct() / ShmemInitStruct() goes unused. We should use the memory that we've reserved, per the attached patch. One consequence of this fix though is that the allocations are now only MAXALIGNed, while ShmemAlloc() uses CACHELINEALIGN(). Not sure which we want. I noticed this while working on the new shmem allocation functions, but it's a pre-existing bug in stable branches too. - Heikki
Commits
-
Fix shmem allocation of fixed-sized custom stats kind
- 93f08dc92cf8 18.4 landed
- 17132f55c5a2 19 (unreleased) landed
-
Fix shared memory size of template code for custom fixed-sized pgstats
- af04b04f2f7a 18.4 landed
- 98979578055f 19 (unreleased) landed