pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: 邱宇航 <iamqyh@gmail.com>
To: PostgreSQL-development <pgsql-hackers@postgresql.org>
Subject: Add CHECK_FOR_INTERRUPTS in Evict{Rel,All}UnpinnedBuffers
Date: Mon, 3 Nov 2025 10:15:09 +0800
Message-ID: <8DC280D4-94A2-4E7B-BAB9-C345891D0B78@gmail.com> (raw)

The pg_buffercache_evict_{relation,all} operations can become extremely
slow when dealing with large buffer pools containing many dirty buffers.
This commit adds CHECK_FOR_INTERRUPTS calls within the underlying
Evict{Rel,All}UnpinnedBuffers functions to ensure these operations
cancellable.

And this should be backpatched through v18 where
pg_buffercache_evict_{relation,all} operations are introduced.


Attachments:

0001-Add-CHECK_FOR_INTERRUPTS-in-Evict-Rel-All-UnpinnedBu.patch (application/octet-stream, 1.4K) download From 13c18cda92f396f36c9383dfb062e184d2dbcd0a Mon Sep 17 00:00:00 2001 From: Yuhang Qiu <iamqyh@gmail.com> Date: Mon, 3 Nov 2025 09:57:02 +0800 Subject: [PATCH] Add CHECK_FOR_INTERRUPTS in Evict{Rel,All}UnpinnedBuffers The pg_buffercache_evict_{relation,all} operations can become extremely slow when dealing with large buffer pool containing many dirty buffers. This commit adds CHECK_FOR_INTERRUPTS calls within the underlying Evict{Rel,All}UnpinnedBuffers functions to ensure these operations cancellable. --- src/backend/storage/buffer/bufmgr.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index e8544acb784..00719c7aea2 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6685,6 +6685,8 @@ EvictAllUnpinnedBuffers(int32 *buffers_evicted, int32 *buffers_flushed, uint32 buf_state; bool buffer_flushed; + CHECK_FOR_INTERRUPTS(); + buf_state = pg_atomic_read_u32(&desc->state); if (!(buf_state & BM_VALID)) continue; @@ -6735,6 +6737,8 @@ EvictRelUnpinnedBuffers(Relation rel, int32 *buffers_evicted, uint32 buf_state = pg_atomic_read_u32(&(desc->state)); bool buffer_flushed; + CHECK_FOR_INTERRUPTS(); + /* An unlocked precheck should be safe and saves some cycles. */ if ((buf_state & BM_VALID) == 0 || !BufTagMatchesRelFileLocator(&desc->tag, &rel->rd_locator)) -- 2.43.5 =

view thread (3+ messages)  latest in thread

Message-ID: <8DC280D4-94A2-4E7B-BAB9-C345891D0B78@gmail.com>
Permalink:  ../8DC280D4-94A2-4E7B-BAB9-C345891D0B78@gmail.com/
Also on:    postgresql.org/message-id/8DC280D4-94A2-4E7B-BAB9-C345891D0B78@gmail.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: iamqyh@gmail.com
  Subject: Re: Add CHECK_FOR_INTERRUPTS in Evict{Rel,All}UnpinnedBuffers
  In-Reply-To: <8DC280D4-94A2-4E7B-BAB9-C345891D0B78@gmail.com>
  References: <8DC280D4-94A2-4E7B-BAB9-C345891D0B78@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox