Re: Shmem allocated wrong for custom cumulative stats

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Shmem allocated wrong for custom cumulative stats
Date: 2026-04-06 00:55:14
Message-ID: adMEcqjRvl0fSndh@paquier.xyz
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: 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 Content-Type Size
v2-0001-Use-the-allocated-space-properly-for-custom-stats.patch text/plain 1.3 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Lukas Fittl 2026-04-06 01:47:51 Re: Reduce timing overhead of EXPLAIN ANALYZE using rdtsc?
Previous Message Daniel Gustafsson 2026-04-06 00:20:34 Re: Changing the state of data checksums in a running cluster