From 11c7123d48275cd94778d3070fcde45a66dbd501 Mon Sep 17 00:00:00 2001
From: Melanie Plageman <melanieplageman@gmail.com>
Date: Thu, 13 Aug 2026 16:49:13 -0400
Subject: [PATCH v16 08/21] Call BufferLockUnlock() directly where the buffer
 descriptor is already known

Use BufferLockUnlock() directly instead of going through LockBuffer(..,
BUFFER_LOCK_UNLOCK) when the buffer descriptor is already available
locally. It is cheaper, as it doesn't have to translate from Buffer to
BufferDescriptor.
---
 src/backend/storage/buffer/bufmgr.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index e14c5f9ba88..1a8cf4ddc30 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -2688,7 +2688,7 @@ GetVictimBuffer(BufferAccessStrategy strategy, IOContext io_context)
 
 		/* OK, do the I/O */
 		FlushBuffer(buf_hdr, NULL, IOOBJECT_RELATION, io_context);
-		LockBuffer(buf, BUFFER_LOCK_UNLOCK);
+		BufferLockUnlock(buf, buf_hdr);
 
 		ScheduleBufferTagForWriteback(&BackendWritebackContext, io_context,
 									  &buf_hdr->tag);
@@ -7034,7 +7034,7 @@ LockBufferForCleanup(Buffer buffer)
 		if (buf_state & BM_PIN_COUNT_WAITER)
 		{
 			UnlockBufHdr(bufHdr);
-			LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
+			BufferLockUnlock(buffer, bufHdr);
 			elog(ERROR, "multiple backends attempting to wait for pincount 1");
 		}
 		bufHdr->wait_backend_pgprocno = MyProcNumber;
@@ -7065,7 +7065,7 @@ LockBufferForCleanup(Buffer buffer)
 		}
 
 		UnlockBufHdr(bufHdr);
-		LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
+		BufferLockUnlock(buffer, bufHdr);
 
 		/* Wait to be signaled by UnpinBuffer() */
 		if (InHotStandby)
@@ -7233,7 +7233,7 @@ ConditionalLockBufferForCleanup(Buffer buffer)
 
 	/* Failed, so release the lock */
 	UnlockBufHdr(bufHdr);
-	LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
+	BufferLockUnlock(buffer, bufHdr);
 	return false;
 }
 
-- 
2.47.3

