Re: ReadRecentBuffer() doesn't scale well

From: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: Peter Geoghegan <pg(at)bowt(dot)ie>, pgsql-hackers(at)postgresql(dot)org, Ants Aasma <ants(at)cybertec(dot)at>
Subject: Re: ReadRecentBuffer() doesn't scale well
Date: 2023-06-30 02:13:11
Message-ID: CA+hUKGJ8N_DRSB0YioinWjS2ycMpmOLy32mbBqVVztwBvXgyJA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Jun 30, 2023 at 3:39 AM Andres Freund <andres(at)anarazel(dot)de> wrote:
> I am wondering if we don't want something more generic than stashing this in
> rd_amcache. Don't want to end up duplicating relevant code across the uses of
> rd_amcache in every AM.

I suppose we could try to track hot pages automatically. Ants Aasma
mentioned that he was working on a tiny SIMD-based LRU that could be
useful for something like that, without being too slow. Just for
fun/experimentation, here's a simple attempt to use a very stupid
stand-in LRU to cache the most recent 8 lookups for each fork of each
relation. Obviously that will miss every time for many workloads so
it'd have to be pretty close to free and this code probably isn't good
enough, but perhaps Ants knows how to sprinkle the right magic fairy
dust on it. It should automatically discover things like root pages,
the heap target block during repeat inserts etc, and visibility map
pages would stick around, and perhaps a few more pages of btrees that
have a very hot key range (but not pgbench).

> I do wonder if we should have an unlocked pre-check for a) the buffer being
> valid and b) BufferTagsEqual() matching. With such a pre-check the race for
> increasing the usage count of the wrong buffer is quite small, without the
> pre-check it doesn't seem that small anymore.

Yeah, that makes sense. Done in this version.

Attachment Content-Type Size
v2-0001-Improve-ReadRecentBuffer-scalability.patch text/x-patch 6.1 KB
v2-0002-Introduce-a-tiny-LRU-cache-for-buffer-mapping.patch text/x-patch 6.3 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tristan Partin 2023-06-30 02:13:26 Re: BUG #17946: LC_MONETARY & DO LANGUAGE plperl - BUG
Previous Message Yuya Watari 2023-06-30 02:10:25 Re: Making empty Bitmapsets always be NULL