From: Masahiko Sawada Date: Tue, 4 Nov 2025 23:47:22 +0000 (-0800) Subject: Add CHECK_FOR_INTERRUPTS in Evict{Rel,All}UnpinnedBuffers. X-Git-Tag: REL_18_1~25 X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=71aa2e1147b9ddae8e6e9717953c28075e287ad2;p=postgresql.git Add CHECK_FOR_INTERRUPTS in Evict{Rel,All}UnpinnedBuffers. This commit adds CHECK_FOR_INTERRUPTS to the shared buffer iteration loops in EvictRelUnpinnedBuffers and EvictAllUnpinnedBuffers. These functions, used by pg_buffercache's pg_buffercache_evict_relation and pg_buffercache_evict_all, can now be interrupted during long-running operations. Backpatch to version 18, where these functions and their corresponding pg_buffercache functions were introduced. Author: Yuhang Qiu Discussion: https://postgr.es/m/8DC280D4-94A2-4E7B-BAB9-C345891D0B78%40gmail.com Backpatch-through: 18 --- diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index c9fb14ddd16..6ba5e207534 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -6683,6 +6683,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; @@ -6733,6 +6735,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))