Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vFk6U-0002Ge-6k for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Nov 2025 02:15:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1vFk6T-00GArt-5E for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Nov 2025 02:15:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vFk6S-00GArk-QQ for pgsql-hackers@lists.postgresql.org; Mon, 03 Nov 2025 02:15:27 +0000 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vFk6P-005fW8-1y for pgsql-hackers@postgresql.org; Mon, 03 Nov 2025 02:15:27 +0000 Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-33e27a3b153so3810693a91.3 for ; Sun, 02 Nov 2025 18:15:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762136123; x=1762740923; darn=postgresql.org; h=to:date:message-id:subject:mime-version:from:from:to:cc:subject :date:message-id:reply-to; bh=pZ1fWbnfeOe7KY09BpES+rcf8V7X1jGACiOcT6UC/OI=; b=UGp2NdIwc/tMgbCjULypEuMtj1bXZkoXn+w2ZaIHFbPfRvDKcsZTQv4YFMsvucZm+n jIqsB2vyLtLQcdqdfYKexPooeZpRIxnjaqPSquWFj6dXv67rKChyb63JXOqtt17NxSCK kDBCRtsaL7E7gZCIqd9BDMU/c4DElhCb2yXz8oQtA2LcOa2a22P5Sv7guHJVr+WZ7X6e ciA/myfEZPK5ZVUlMwnnjw6/gtXr9mO/rsDkEZXxlUg0swBmhIRnmh4rjyU/5AD189Cm iRB3heYSHxxjVn3DLgo1M8BiMcTZsrlg27v/yBYp/h3ETqoQM4E1beg+BROossks2h2f 64Gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762136123; x=1762740923; h=to:date:message-id:subject:mime-version:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=pZ1fWbnfeOe7KY09BpES+rcf8V7X1jGACiOcT6UC/OI=; b=SnGvemovax9dWTHQUp2gACRXzairux1PJWoPEiQ/vyjRbmYtsjFdJ8eLZng4Rj9486 9/1/ZQ/9K9VVXCs82ng/IqYf5fwo0lfYAsSp8MBmNvLYI/uSPWvEdFc/C6HDWgP5sBn9 SUN9O7mM4O42kdBn8s4O9j8TyiaXU4ZSw7caVIHLFNlA32/PnY0No45IaI6lmSVdoQ1T +/zfUC1IlvkW0ry4VJiZJznL/yFxjs3UPNRVtq9vMw3vVWQxR+nrnB+dkCSApye+ip68 770rc77b5HaMTNMpA80CuF8n+Ky5F2T828EglT2ltiWYDa44Lr1I5dztFoXr813RFEiz tgSg== X-Gm-Message-State: AOJu0Yysai9PAgP3PyBm+Ob8QA1OeNbcRcXJI25Q9R1/fuUSJ+kYYacG AG4ym8fGOpD7NyUQ1JXVOdufXxulWnptESZQY6+2Q7yVLUlNlECtzi/8rSEdNIgj X-Gm-Gg: ASbGncvgNw5r2v3ShMtfWccCMHzecVcIypq+/yVimNVPxESVqprS5Qi0YO9YzFcNGJD u+fHNMmPlgL8T9kPy851zPxUHm2cAeQtVho0kzsS4L35ajkquMalA8TMu1peSRi3EY4MuHsnuBs LeyhxvJnwYOtyQoR6ZX/oLSMr7bmFspKme88KM9yLi1zTdcItbIHIZGmXH0w3D3E7dPtQtHz8+a IdPV6uktC70uGY20Rvgg04xnHk+K7ow3cidSTauI45NRPTv0XBWBDzGZ3t0WjF29z1HRE7rl4r0 Li/ft/JEe99swpJ/TL/+aH/hfHm/9Cabj8ONOwl/IhsyjTeVIeegMMs6FZrUPkdC2uAv7sKxef/ dxY4A+ltrhqYrgDA3er+8SOiNACB5LgY1mH6goFraJosp5PwyneMee8LD3FR3sh0hUccmVEPPb5 H1Tr4CsEqEtdSSngRPDA6g4tOdfZ0cASQ= X-Google-Smtp-Source: AGHT+IH6kC2UtOYWCuuGJjT0hmrN/hMbOmGtowHpDQ7lNI5mWVz9Eg2T4eoMegS/s0Af3deUWO6VNg== X-Received: by 2002:a17:90b:2249:b0:340:f05a:3ec3 with SMTP id 98e67ed59e1d1-340f05a4045mr5345355a91.33.1762136122675; Sun, 02 Nov 2025 18:15:22 -0800 (PST) Received: from smtpclient.apple ([2404:2280:2000:10:6607:44bf:6607:44bf]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-340c242b1fdsm5743749a91.17.2025.11.02.18.15.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 02 Nov 2025 18:15:22 -0800 (PST) From: =?utf-8?B?6YKx5a6H6Iiq?= Content-Type: multipart/mixed; boundary="Apple-Mail=_C5E41FD3-A08F-4C08-B037-3A71993FC823" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Add CHECK_FOR_INTERRUPTS in Evict{Rel,All}UnpinnedBuffers Message-Id: <8DC280D4-94A2-4E7B-BAB9-C345891D0B78@gmail.com> Date: Mon, 3 Nov 2025 10:15:09 +0800 To: PostgreSQL-development X-Mailer: Apple Mail (2.3826.700.81) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_C5E41FD3-A08F-4C08-B037-3A71993FC823 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii 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. --Apple-Mail=_C5E41FD3-A08F-4C08-B037-3A71993FC823 Content-Disposition: attachment; filename=0001-Add-CHECK_FOR_INTERRUPTS-in-Evict-Rel-All-UnpinnedBu.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-Add-CHECK_FOR_INTERRUPTS-in-Evict-Rel-All-UnpinnedBu.patch" Content-Transfer-Encoding: quoted-printable =46rom=2013c18cda92f396f36c9383dfb062e184d2dbcd0a=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Yuhang=20Qiu=20=0ADate:=20= Mon,=203=20Nov=202025=2009:57:02=20+0800=0ASubject:=20[PATCH]=20Add=20= CHECK_FOR_INTERRUPTS=20in=20Evict{Rel,All}UnpinnedBuffers=0A=0AThe=20= pg_buffercache_evict_{relation,all}=20operations=20can=20become=20= extremely=0Aslow=20when=20dealing=20with=20large=20buffer=20pool=20= containing=20many=20dirty=20buffers.=0AThis=20commit=20adds=20= CHECK_FOR_INTERRUPTS=20calls=20within=20the=20underlying=0A= Evict{Rel,All}UnpinnedBuffers=20functions=20to=20ensure=20these=20= operations=0Acancellable.=0A---=0A=20src/backend/storage/buffer/bufmgr.c=20= |=204=20++++=0A=201=20file=20changed,=204=20insertions(+)=0A=0Adiff=20= --git=20a/src/backend/storage/buffer/bufmgr.c=20= b/src/backend/storage/buffer/bufmgr.c=0Aindex=20e8544acb784..00719c7aea2=20= 100644=0A---=20a/src/backend/storage/buffer/bufmgr.c=0A+++=20= b/src/backend/storage/buffer/bufmgr.c=0A@@=20-6685,6=20+6685,8=20@@=20= EvictAllUnpinnedBuffers(int32=20*buffers_evicted,=20int32=20= *buffers_flushed,=0A=20=09=09uint32=09=09buf_state;=0A=20=09=09bool=09=09= buffer_flushed;=0A=0A+=09=09CHECK_FOR_INTERRUPTS();=0A+=0A=20=09=09= buf_state=20=3D=20pg_atomic_read_u32(&desc->state);=0A=20=09=09if=20= (!(buf_state=20&=20BM_VALID))=0A=20=09=09=09continue;=0A@@=20-6735,6=20= +6737,8=20@@=20EvictRelUnpinnedBuffers(Relation=20rel,=20int32=20= *buffers_evicted,=0A=20=09=09uint32=09=09buf_state=20=3D=20= pg_atomic_read_u32(&(desc->state));=0A=20=09=09bool=09=09buffer_flushed;=0A= =0A+=09=09CHECK_FOR_INTERRUPTS();=0A+=0A=20=09=09/*=20An=20unlocked=20= precheck=20should=20be=20safe=20and=20saves=20some=20cycles.=20*/=0A=20=09= =09if=20((buf_state=20&=20BM_VALID)=20=3D=3D=200=20||=0A=20=09=09=09= !BufTagMatchesRelFileLocator(&desc->tag,=20&rel->rd_locator))=0A--=0A= 2.43.5=0A=0A= --Apple-Mail=_C5E41FD3-A08F-4C08-B037-3A71993FC823 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii --Apple-Mail=_C5E41FD3-A08F-4C08-B037-3A71993FC823--