Re: Buffer locking is special (hints, checksums, AIO writes)

From: Melanie Plageman <melanieplageman(at)gmail(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Noah Misch <noah(at)leadboat(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Subject: Re: Buffer locking is special (hints, checksums, AIO writes)
Date: 2025-12-01 20:41:07
Message-ID: CAAKRu_bFyKsGcoCznoT78sF9EYbVeWsXPfhdJnGLsHzoA01Sww@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Dec 1, 2025 at 3:28 PM Andres Freund <andres(at)anarazel(dot)de> wrote:
>
> > I noticed that the BUF_STATE_GET_REFCOUNT and BUF_STATE_GET_USAGECOUNT
> > macros cast the return value to a uint32. We won't use the extra bits
> > but we did bother to keep the macro result sized to the field width
> > before so keeping it uint32 is probably more confusing now that state
> > is 64 bit.
>
> I can't really follow - why would we want to return a 64bit value if none of
> the values ever can get anywhere near that big?

Well, usagecount could never have reached anything close to a uint32
either, so I thought that this cast was meant to match the datatype. I
found it rather confusing otherwise.

> > 0007
> > needs a commit message. overall seems fine though.
>
> This is what I've since written:
>
> bufmgr: Add one-entry cache for private refcount
>
> The private refcount entry for a buffer is often looked up repeatedly for the
> same buffer, e.g. to pin and then unpin a buffer. Benchmarking shows that it's
> worthwhile to have a one-entry cache for that case. With that cache in place,
> it's worth splitting GetPrivateRefCountEntry() into a small inline
> portion (for the cache hit case) and an out-of-line helper for the rest.
>
> This is helpful for some workloads today, but becomes more important in an
> upcoming patch that will utilize the private refcount infrastructure to also
> store whether the buffer is currently locked, as that increases the rate of
> lookups substantially.

Sounds good based on what I recall of the patch.

- Melanie

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2025-12-01 21:01:58 Re: Is there value in having optimizer stats for joins/foreignkeys?
Previous Message Robert Haas 2025-12-01 20:31:06 Re: plan shape work