public inbox for [email protected]
help / color / mirror / Atom feedFrom: Michael Paquier <[email protected]>
To: Heikki Linnakangas <[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: Shmem allocated wrong for custom cumulative stats
Date: Mon, 6 Apr 2026 09:55:14 +0900
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
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
From 9d0c00e96d8776d21f556e1457abf635fe211f9c Mon Sep 17 00:00:00 2001
From: Michael Paquier <[email protected]>
Date: Mon, 6 Apr 2026 09:47:02 +0900
Subject: [PATCH v2] Use the allocated space properly for custom stats kind
---
src/backend/utils/activity/pgstat_shmem.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/backend/utils/activity/pgstat_shmem.c b/src/backend/utils/activity/pgstat_shmem.c
index 955faf5ebc7d..b8f354c818a0 100644
--- a/src/backend/utils/activity/pgstat_shmem.c
+++ b/src/backend/utils/activity/pgstat_shmem.c
@@ -150,8 +150,7 @@ StatsShmemSize(void)
continue;
Assert(kind_info->shared_size != 0);
-
- sz += MAXALIGN(kind_info->shared_size);
+ sz = add_size(sz, MAXALIGN(kind_info->shared_size));
}
return sz;
@@ -189,6 +188,7 @@ StatsShmemInit(void *arg)
* efficiency win.
*/
ctl->raw_dsa_area = p;
+ p += pgstat_dsa_init_size();
dsa = dsa_create_in_place(ctl->raw_dsa_area,
pgstat_dsa_init_size(),
LWTRANCHE_PGSTATS_DSA, NULL);
@@ -242,7 +242,8 @@ StatsShmemInit(void *arg)
int idx = kind - PGSTAT_KIND_CUSTOM_MIN;
Assert(kind_info->shared_size != 0);
- ctl->custom_data[idx] = ShmemAlloc(kind_info->shared_size);
+ ctl->custom_data[idx] = p;
+ p += MAXALIGN(kind_info->shared_size);
ptr = ctl->custom_data[idx];
}
--
2.53.0
Attachments:
[text/plain] v2-0001-Use-the-allocated-space-properly-for-custom-stats.patch (1.3K, 2-v2-0001-Use-the-allocated-space-properly-for-custom-stats.patch)
download | inline diff:
From 9d0c00e96d8776d21f556e1457abf635fe211f9c Mon Sep 17 00:00:00 2001
From: Michael Paquier <[email protected]>
Date: Mon, 6 Apr 2026 09:47:02 +0900
Subject: [PATCH v2] Use the allocated space properly for custom stats kind
---
src/backend/utils/activity/pgstat_shmem.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/backend/utils/activity/pgstat_shmem.c b/src/backend/utils/activity/pgstat_shmem.c
index 955faf5ebc7d..b8f354c818a0 100644
--- a/src/backend/utils/activity/pgstat_shmem.c
+++ b/src/backend/utils/activity/pgstat_shmem.c
@@ -150,8 +150,7 @@ StatsShmemSize(void)
continue;
Assert(kind_info->shared_size != 0);
-
- sz += MAXALIGN(kind_info->shared_size);
+ sz = add_size(sz, MAXALIGN(kind_info->shared_size));
}
return sz;
@@ -189,6 +188,7 @@ StatsShmemInit(void *arg)
* efficiency win.
*/
ctl->raw_dsa_area = p;
+ p += pgstat_dsa_init_size();
dsa = dsa_create_in_place(ctl->raw_dsa_area,
pgstat_dsa_init_size(),
LWTRANCHE_PGSTATS_DSA, NULL);
@@ -242,7 +242,8 @@ StatsShmemInit(void *arg)
int idx = kind - PGSTAT_KIND_CUSTOM_MIN;
Assert(kind_info->shared_size != 0);
- ctl->custom_data[idx] = ShmemAlloc(kind_info->shared_size);
+ ctl->custom_data[idx] = p;
+ p += MAXALIGN(kind_info->shared_size);
ptr = ctl->custom_data[idx];
}
--
2.53.0
[application/pgp-signature] signature.asc (833B, 3-signature.asc)
download
view thread (5+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: Shmem allocated wrong for custom cumulative stats
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox