Re: Proposal: Limitations of palloc inside checkpointer

From: Alexander Korotkov <aekorotkov(at)gmail(dot)com>
To: Xuneng Zhou <xunengzhou(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Maxim Orlov <orlovmg(at)gmail(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, Ekaterina Sokolova <e(dot)sokolova(at)postgrespro(dot)ru>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Proposal: Limitations of palloc inside checkpointer
Date: 2025-08-07 13:32:41
Message-ID: CAPpHfdttxDqc8_XqA9Ztok_LhpgNL=-SvN90i9hu8=nH4ms+Pw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Aug 7, 2025 at 4:01 PM Xuneng Zhou <xunengzhou(at)gmail(dot)com> wrote:
> On Thu, Aug 7, 2025 at 3:16 PM Xuneng Zhou <xunengzhou(at)gmail(dot)com> wrote:
> >
> > Hi, Tom!
> >
> > Thanks for catching this.
> >
> > On Thu, Aug 7, 2025 at 2:58 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> > >
> > > Alexander Korotkov <aekorotkov(at)gmail(dot)com> writes:
> > > > I'm going to push this if no objections.
> > >
> > > I looked at these patches while preparing release notes, and
> > > found an oversight. CheckpointerShmemInit does
> > >
> > > CheckpointerShmem->max_requests = Min(NBuffers, MAX_CHECKPOINT_REQUESTS);
> > >
> > > but CheckpointerShmemSize still does
> > >
> > > size = add_size(size, mul_size(NBuffers, sizeof(CheckpointerRequest)));
> > >
> > > So if NBuffers is more than MAX_CHECKPOINT_REQUESTS, we will allocate
> > > extra CheckpointerRequest array entries that we will never use,
> > > wasting shared memory. Admittedly the amount is small relative to the
> > > shared buffers themselves, but at the very least this is confusing.
> > >
> > > The comment in CheckpointerShmemSize needs adjustment, too.
> >
> > I attached a patch to fix it.
>
> Sorry for the error in this patch. I forgot to take the min of
> NBuffers and MAX_CHECKPOINT_REQUESTS for mem size calculation.
> Many thanks to Alexander for correcting and pushing it.

No problem. Thank you for the patch. And thanks to Tom for catching this.

------
Regards,
Alexander Korotkov
Supabase

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Magnus Hagander 2025-08-07 13:38:10 Re: [PING] fallocate() causes btrfs to never compress postgresql files
Previous Message Fabrice Chapuis 2025-08-07 13:20:04 Issue with logical replication slot during switchover