Thinko in pgstat_build_snapshot()

Started by Etsuro Fujitaabout 1 year ago5 messageshackers
Jump to latest
#1Etsuro Fujita
fujita.etsuro@lab.ntt.co.jp

While working on something else I noticed $SUBJECT: we are allocating
more memory than necessary and copying more data than necessary
because we specify the wrong PgStat_KindInfo member as the size
argument for MemoryContextAlloc and memcpy. This could become
problematic if snapshotting a very large number of variables stats, so
I fixed it. Attached is a patch for that.

Best regards,
Etsuro Fujita

Attachments:

fix-thinko-in-pgstat_build_snapshot.patchapplication/octet-stream; name=fix-thinko-in-pgstat_build_snapshot.patchDownload+2-2
#2Heikki Linnakangas
heikki.linnakangas@enterprisedb.com
In reply to: Etsuro Fujita (#1)
Re: Thinko in pgstat_build_snapshot()

On 30/03/2025 13:23, Etsuro Fujita wrote:

While working on something else I noticed $SUBJECT: we are allocating
more memory than necessary and copying more data than necessary
because we specify the wrong PgStat_KindInfo member as the size
argument for MemoryContextAlloc and memcpy. This could become
problematic if snapshotting a very large number of variables stats, so
I fixed it. Attached is a patch for that.

Good catch. Patch looks good to me at quick glance.

--
Heikki Linnakangas
Neon (https://neon.tech)

#3Gurjeet Singh
gurjeet@singh.im
In reply to: Heikki Linnakangas (#2)
Re: Thinko in pgstat_build_snapshot()

On Sun, Mar 30, 2025 at 4:31 AM Heikki Linnakangas <hlinnaka@iki.fi> wrote:

On 30/03/2025 13:23, Etsuro Fujita wrote:

While working on something else I noticed $SUBJECT: we are allocating
more memory than necessary and copying more data than necessary
because we specify the wrong PgStat_KindInfo member as the size
argument for MemoryContextAlloc and memcpy. This could become
problematic if snapshotting a very large number of variables stats, so
I fixed it. Attached is a patch for that.

Good catch. Patch looks good to me at quick glance.

+1 on both counts.

Best regards,
Gurjeet
http://Gurje.et

#4Etsuro Fujita
fujita.etsuro@lab.ntt.co.jp
In reply to: Gurjeet Singh (#3)
Re: Thinko in pgstat_build_snapshot()

On Sun, Mar 30, 2025 at 10:47 PM Gurjeet Singh <gurjeet@singh.im> wrote:

On Sun, Mar 30, 2025 at 4:31 AM Heikki Linnakangas <hlinnaka@iki.fi> wrote:

On 30/03/2025 13:23, Etsuro Fujita wrote:

While working on something else I noticed $SUBJECT: we are allocating
more memory than necessary and copying more data than necessary
because we specify the wrong PgStat_KindInfo member as the size
argument for MemoryContextAlloc and memcpy. This could become
problematic if snapshotting a very large number of variables stats, so
I fixed it. Attached is a patch for that.

Good catch. Patch looks good to me at quick glance.

+1 on both counts.

I will push the patch as well.

Thank you both for looking at the patch!

Best regards,
Etsuro Fujita

#5Etsuro Fujita
fujita.etsuro@lab.ntt.co.jp
In reply to: Etsuro Fujita (#4)
Re: Thinko in pgstat_build_snapshot()

On Sun, Apr 6, 2025 at 8:35 PM Etsuro Fujita <etsuro.fujita@gmail.com> wrote:

I will push the patch as well.

I pushed this one too.

Thanks!

Best regards,
Etsuro Fujita