From 2e4e137dc1d50e65069d353ffebec6ea35e006e9 Mon Sep 17 00:00:00 2001
From: Nazir Bilal Yavuz <byavuz81@gmail.com>
Date: Thu, 9 Jan 2025 13:59:13 +0300
Subject: [PATCH v7 2/2] Replace pgstat_count_io_op() with
 pgstat_count_io_op_n()

The pgstat_count_io_op() function, which counts a single IO operation,
wraps pgstat_count_io_op_n() with a counter value of 1. To streamline
the code, all uses of pgstat_count_io_op() are replaced with
pgstat_count_io_op_n() and the former is removed.

This change ensures symmetry with pgstat_count_io_op_time(), which
already uses a similar approach.
---
 src/include/pgstat.h                   | 1 -
 src/backend/storage/buffer/bufmgr.c    | 6 +++---
 src/backend/storage/buffer/localbuf.c  | 2 +-
 src/backend/utils/activity/pgstat_io.c | 6 ------
 4 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index 8c4fa74103f..90959d18ebe 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -609,7 +609,6 @@ extern PgStat_CheckpointerStats *pgstat_fetch_stat_checkpointer(void);
 
 extern bool pgstat_bktype_io_stats_valid(PgStat_BktypeIO *backend_io,
 										 BackendType bktype);
-extern void pgstat_count_io_op(IOObject io_object, IOContext io_context, IOOp io_op, uint64 bytes);
 extern void pgstat_count_io_op_n(IOObject io_object, IOContext io_context,
 								 IOOp io_op, uint32 cnt, uint64 bytes);
 extern instr_time pgstat_prepare_io_time(bool track_io_guc);
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index fea70278f07..5251eca204f 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -1165,7 +1165,7 @@ PinBufferForBlock(Relation rel,
 	}
 	if (*foundPtr)
 	{
-		pgstat_count_io_op(io_object, io_context, IOOP_HIT, 0);
+		pgstat_count_io_op_n(io_object, io_context, IOOP_HIT, 1, 0);
 		if (VacuumCostActive)
 			VacuumCostBalance += VacuumCostPageHit;
 
@@ -2072,8 +2072,8 @@ again:
 		 * we may have been forced to release the buffer due to concurrent
 		 * pinners or erroring out.
 		 */
-		pgstat_count_io_op(IOOBJECT_RELATION, io_context,
-						   from_ring ? IOOP_REUSE : IOOP_EVICT, 0);
+		pgstat_count_io_op_n(IOOBJECT_RELATION, io_context,
+							 from_ring ? IOOP_REUSE : IOOP_EVICT, 1, 0);
 	}
 
 	/*
diff --git a/src/backend/storage/buffer/localbuf.c b/src/backend/storage/buffer/localbuf.c
index 96aa167656d..e870376eab8 100644
--- a/src/backend/storage/buffer/localbuf.c
+++ b/src/backend/storage/buffer/localbuf.c
@@ -279,7 +279,7 @@ GetLocalVictimBuffer(void)
 		ClearBufferTag(&bufHdr->tag);
 		buf_state &= ~(BUF_FLAG_MASK | BUF_USAGECOUNT_MASK);
 		pg_atomic_unlocked_write_u32(&bufHdr->state, buf_state);
-		pgstat_count_io_op(IOOBJECT_TEMP_RELATION, IOCONTEXT_NORMAL, IOOP_EVICT, 0);
+		pgstat_count_io_op_n(IOOBJECT_TEMP_RELATION, IOCONTEXT_NORMAL, IOOP_EVICT, 1, 0);
 	}
 
 	return BufferDescriptorGetBuffer(bufHdr);
diff --git a/src/backend/utils/activity/pgstat_io.c b/src/backend/utils/activity/pgstat_io.c
index f8c42001cb5..c966928b3c6 100644
--- a/src/backend/utils/activity/pgstat_io.c
+++ b/src/backend/utils/activity/pgstat_io.c
@@ -73,12 +73,6 @@ pgstat_bktype_io_stats_valid(PgStat_BktypeIO *backend_io,
 	return true;
 }
 
-void
-pgstat_count_io_op(IOObject io_object, IOContext io_context, IOOp io_op, uint64 bytes)
-{
-	pgstat_count_io_op_n(io_object, io_context, io_op, 1, bytes);
-}
-
 void
 pgstat_count_io_op_n(IOObject io_object, IOContext io_context, IOOp io_op, uint32 cnt, uint64 bytes)
 {
-- 
2.47.1

