Add pg_buffercache_evict_all() and pg_buffercache_mark_dirty[_all]() functions

From: Nazir Bilal Yavuz <byavuz81(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Andres Freund <andres(at)anarazel(dot)de>
Subject: Add pg_buffercache_evict_all() and pg_buffercache_mark_dirty[_all]() functions
Date: 2024-12-25 12:57:34
Message-ID: CAN55FZ0h_YoSqqutxV6DES1RW8ig6wcA8CR9rJk358YRMxZFmw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Andres off-list mentioned that:

1- It is time consuming to evict all shared buffers one by one using
the pg_buffercache_evict() function.
2- It would be good to have a function to mark buffers as dirty to
test different scenarios.

So, this patchset extends pg_buffercache with 3 functions:

1- pg_buffercache_evict_all(): This is very similar to the already
existing pg_buffercache_evict() function. The difference is
pg_buffercache_evict_all() does not take an argument. Instead it just
loops over the shared buffers and tries to evict all of them. It
returns the number of buffers evicted and flushed.

2- pg_buffercache_mark_dirty(): This function takes a buffer id as an
argument and tries to mark this buffer as dirty. Returns true on
success. This returns false if the buffer is already dirty. Do you
think this makes sense or do you prefer it to return true if the
buffer is already dirty?

3- pg_buffercache_mark_dirty_all(): This is very similar to the
pg_buffercache_mark_dirty() function. The difference is
pg_buffercache_mark_dirty_all() does not take an argument. Instead it
just loops over the shared buffers and tries to mark all of them as
dirty. It returns the number of buffers marked as dirty.

I tested these functions with 16GB shared buffers.

pg_buffercache_evict() -> 790ms
pg_buffercache_evict_all() -> 270ms

pg_buffercache_mark_dirty() -> 550ms
pg_buffercache_mark_dirty_all() -> 70ms

Any feedback would be appreciated.

--
Regards,
Nazir Bilal Yavuz
Microsoft

Attachment Content-Type Size
v1-0001-Add-pg_buffercache_evict_all-function-for-testing.patch text/x-patch 8.7 KB
v1-0002-Add-pg_buffercache_mark_dirty-_all-functions-for-.patch text/x-patch 8.7 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message vignesh C 2024-12-25 14:37:26 Documentation update of wal_retrieve_retry_interval to mention table sync worker
Previous Message Daniil Davydov 2024-12-25 12:44:03 Improve consistency checks in tbm_prepare_shared_iterate