Re: Shmem allocated wrong for custom cumulative stats
Michael Paquier <michael@paquier.xyz>
From: Michael Paquier <michael@paquier.xyz>
To: Heikki Linnakangas <hlinnaka@iki.fi>
Cc: "pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>
Date: 2026-04-06T00:55:14Z
Lists: pgsql-hackers
Attachments
- v2-0001-Use-the-allocated-space-properly-for-custom-stats.patch (text/plain) patch v2-0001
On Mon, Apr 06, 2026 at 03:16:47AM +0300, Heikki Linnakangas wrote: > 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. Indeed, it's not right. Thanks for the report. I am pretty sure that I intended each chunk to be MAXALIGN()-d for each custom stats kind registered, allocated in a non-anonymous way, without cache alignment. > I noticed this while working on the new shmem allocation functions, but it's > a pre-existing bug in stable branches too. Right, down to v18 where this has been introduced. That's my bug, so I'd be OK to take care of it myself, if you are OK with that of course. Actually, shouldn't StatsShmemSize() use an add_size() for each shared_size? Noted while passing through the code, extra error from the same commit. -- Michael
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