From 7343bf48ed98d5435fb488904f573b315109beb5 Mon Sep 17 00:00:00 2001
From: Melanie Plageman <melanieplageman@gmail.com>
Date: Thu, 13 Aug 2026 16:49:13 -0400
Subject: [PATCH v17 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 4ce5b473437..29cf0b0aa4a 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -2692,7 +2692,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);
@@ -7053,7 +7053,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;
@@ -7084,7 +7084,7 @@ LockBufferForCleanup(Buffer buffer)
 		}
 
 		UnlockBufHdr(bufHdr);
-		LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
+		BufferLockUnlock(buffer, bufHdr);
 
 		/* Wait to be signaled by UnpinBuffer() */
 		if (InHotStandby)
@@ -7252,7 +7252,7 @@ ConditionalLockBufferForCleanup(Buffer buffer)
 
 	/* Failed, so release the lock */
 	UnlockBufHdr(bufHdr);
-	LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
+	BufferLockUnlock(buffer, bufHdr);
 	return false;
 }
 
-- 
2.43.0

