Re: pg_stat_bgwriter.buffers_backend is pretty meaningless (and more?)

From: Melanie Plageman <melanieplageman(at)gmail(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>, Lukas Fittl <lukas(at)fittl(dot)com>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
Subject: Re: pg_stat_bgwriter.buffers_backend is pretty meaningless (and more?)
Date: 2021-08-11 22:00:40
Message-ID: CAAKRu_Zj=2bfSbhzRHDu8bbsWJ-xOCodY1t+nVGEMBNfaLPQMA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Aug 11, 2021 at 4:11 PM Melanie Plageman
<melanieplageman(at)gmail(dot)com> wrote:
>
> On Tue, Aug 3, 2021 at 2:13 PM Andres Freund <andres(at)anarazel(dot)de> wrote:
> >
> > > @@ -2895,6 +2948,20 @@ FlushBuffer(BufferDesc *buf, SMgrRelation reln)
> > > /*
> > > * bufToWrite is either the shared buffer or a copy, as appropriate.
> > > */
> > > +
> > > + /*
> > > + * TODO: consider that if we did not need to distinguish between a buffer
> > > + * flushed that was grabbed from the ring buffer and written out as part
> > > + * of a strategy which was not from main Shared Buffers (and thus
> > > + * preventable by bgwriter or checkpointer), then we could move all calls
> > > + * to pgstat_increment_buffer_action() here except for the one for
> > > + * extends, which would remain in ReadBuffer_common() before smgrextend()
> > > + * (unless we decide to start counting other extends). That includes the
> > > + * call to count buffers written by bgwriter and checkpointer which go
> > > + * through FlushBuffer() but not BufferAlloc(). That would make it
> > > + * simpler. Perhaps instead we can find somewhere else to indicate that
> > > + * the buffer is from the ring of buffers to reuse.
> > > + */
> > > smgrwrite(reln,
> > > buf->tag.forkNum,
> > > buf->tag.blockNum,
> >
> > Can we just add a parameter to FlushBuffer indicating what the source of the
> > write is?
> >
>
> I just noticed this comment now, so I'll address that in the next
> version. I rebased today and noticed merge conflicts, so, it looks like
> v5 will be on its way soon anyway.
>

Actually, after moving the code around like you suggested, calling
pgstat_increment_buffer_action() before smgrwrite() in FlushBuffer() and
using a parameter to indicate if it is a strategy write or not would
only save us one other call to pgstat_increment_buffer_action() -- the
one in SyncOneBuffer(). We would end up moving the one in BufferAlloc()
to FlushBuffer() and removing the one in SyncOneBuffer().
Do you think it is still worth it?

Rebased v5 attached.

Attachment Content-Type Size
v5-0001-Add-system-view-tracking-shared-buffer-actions.patch text/x-patch 32.0 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Mark Dilger 2021-08-11 22:02:29 Re: Use extended statistics to estimate (Var op Var) clauses
Previous Message Tomas Vondra 2021-08-11 22:00:12 Re: Use extended statistics to estimate (Var op Var) clauses