Improve buffer manager API for backend pin limits.
authorThomas Munro <tmunro@postgresql.org>
Fri, 14 Mar 2025 02:10:43 +0000 (15:10 +1300)
committerThomas Munro <tmunro@postgresql.org>
Fri, 14 Mar 2025 04:13:09 +0000 (17:13 +1300)
commit01261fb07888642efa98ba8d4117654bfd2a413d
treea7fb87d483db2ba42f2f2226f3283982fc6d48d8
parent7c99dc587a010a0c40d72a0e435111ca7a371c02
Improve buffer manager API for backend pin limits.

Previously the support functions assumed that the caller needed one pin
to make progress, and could optionally use some more, allowing enough
for every connection to do the same.  Add a couple more functions for
callers that want to know:

* what the maximum possible number could be, irrespective of currently
  held pins, for space planning purposes

* how many additional pins they could acquire right now, without the
  special case allowing one pin, for callers that already hold pins and
  could already make progress even if no extra pins are available

The pin limit logic began in commit 31966b15.  This refactoring is
better suited to read_stream.c, which will be adjusted to respect the
remaining limit as it changes over time in a follow-up commit.  It also
computes MaxProportionalPins up front, to avoid performing divisions
whenever a caller needs to check the balance.

Reviewed-by: Andres Freund <andres@anarazel.de> (earlier versions)
Discussion: https://postgr.es/m/CA%2BhUKGK_%3D4CVmMHvsHjOVrK6t4F%3DLBpFzsrr3R%2BaJYN8kcTfWg%40mail.gmail.com
src/backend/storage/buffer/bufmgr.c
src/backend/storage/buffer/localbuf.c
src/include/storage/bufmgr.h