Re: Shmem allocated wrong for custom cumulative stats - Mailing list pgsql-hackers

From Michael Paquier
Subject Re: Shmem allocated wrong for custom cumulative stats
Date
Msg-id adMEcqjRvl0fSndh@paquier.xyz
Whole thread Raw
In response to Shmem allocated wrong for custom cumulative stats  (Heikki Linnakangas <hlinnaka@iki.fi>)
Responses Re: Shmem allocated wrong for custom cumulative stats
List pgsql-hackers
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

Attachment

pgsql-hackers by date:

Previous
From: Daniel Gustafsson
Date:
Subject: Re: Changing the state of data checksums in a running cluster
Next
From: Lukas Fittl
Date:
Subject: Re: Reduce timing overhead of EXPLAIN ANALYZE using rdtsc?