Merge pgstat_count_io_op_n() and pgstat_count_io_op()
authorMichael Paquier <[email protected]>
Fri, 10 Jan 2025 00:57:27 +0000 (09:57 +0900)
committerMichael Paquier <[email protected]>
Fri, 10 Jan 2025 00:57:27 +0000 (09:57 +0900)
The pgstat_count_io_op() function, which counts a single I/O operation,
wraps pgstat_count_io_op_n() with a counter value of 1.  The latter is
declared in pgstat.h and used nowhere in the code, so let's remove it in
favor of the former.

This change makes also the code more symmetric with
pgstat_count_io_op_time(), that already uses a similar set of arguments,
except that it counts also the I/O time.  This will ease a bit the
integration of a follow-up patch that adds byte-level tracking in
pg_stat_io for some of its attributes, lifting the current restriction
based on BLCKSZ as all I/O operations are assumed to be block-based.

Author: Nazir Bilal Yavuz
Reviewed-by: Bertrand Drouvot
Discussion: https://postgr.es/m/CAN55FZ32ze812=yjyZg1QeXhKvACUM_Nu0_gyPQcUKKuVHL5xA@mail.gmail.com

src/backend/storage/buffer/bufmgr.c
src/backend/storage/buffer/localbuf.c
src/backend/utils/activity/pgstat_io.c
src/include/pgstat.h

index 5008641baff29527266607f18153fe921d43b0e5..7a07c9c1ebd8936e713262b1767e5c1db6fafec8 100644 (file)
@@ -1165,7 +1165,7 @@ PinBufferForBlock(Relation rel,
        }
        if (*foundPtr)
        {
-               pgstat_count_io_op(io_object, io_context, IOOP_HIT);
+               pgstat_count_io_op(io_object, io_context, IOOP_HIT, 1);
                if (VacuumCostActive)
                        VacuumCostBalance += VacuumCostPageHit;
 
@@ -2073,7 +2073,7 @@ again:
                 * pinners or erroring out.
                 */
                pgstat_count_io_op(IOOBJECT_RELATION, io_context,
-                                                  from_ring ? IOOP_REUSE : IOOP_EVICT);
+                                                  from_ring ? IOOP_REUSE : IOOP_EVICT, 1);
        }
 
        /*
index 80b7fc7efcc8d5daf7530bf46db4cd7cfa9a396a..cdb9da7e65108e78dabd8e01740bd5fac8eae988 100644 (file)
@@ -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);
+               pgstat_count_io_op(IOOBJECT_TEMP_RELATION, IOCONTEXT_NORMAL, IOOP_EVICT, 1);
        }
 
        return BufferDescriptorGetBuffer(bufHdr);
index a7445995d32262aa021315e91fc861085e6a0752..b16f57ebeabd58db93fc5d9c3191da16723c57df 100644 (file)
@@ -66,13 +66,7 @@ pgstat_bktype_io_stats_valid(PgStat_BktypeIO *backend_io,
 }
 
 void
-pgstat_count_io_op(IOObject io_object, IOContext io_context, IOOp io_op)
-{
-       pgstat_count_io_op_n(io_object, io_context, io_op, 1);
-}
-
-void
-pgstat_count_io_op_n(IOObject io_object, IOContext io_context, IOOp io_op, uint32 cnt)
+pgstat_count_io_op(IOObject io_object, IOContext io_context, IOOp io_op, uint32 cnt)
 {
        Assert((unsigned int) io_object < IOOBJECT_NUM_TYPES);
        Assert((unsigned int) io_context < IOCONTEXT_NUM_TYPES);
@@ -116,7 +110,7 @@ pgstat_prepare_io_time(bool track_io_guc)
 }
 
 /*
- * Like pgstat_count_io_op_n() except it also accumulates time.
+ * Like pgstat_count_io_op() except it also accumulates time.
  */
 void
 pgstat_count_io_op_time(IOObject io_object, IOContext io_context, IOOp io_op,
@@ -159,7 +153,7 @@ pgstat_count_io_op_time(IOObject io_object, IOContext io_context, IOOp io_op,
                }
        }
 
-       pgstat_count_io_op_n(io_object, io_context, io_op, cnt);
+       pgstat_count_io_op(io_object, io_context, io_op, cnt);
 }
 
 PgStat_IO *
index f1dfe2b5e91045dba1aeed47884f71d1ec5c48d3..6475889c58c3b54a8bd3ed55bc00a9467ddd97ac 100644 (file)
@@ -603,8 +603,8 @@ 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);
-extern void pgstat_count_io_op_n(IOObject io_object, IOContext io_context, IOOp io_op, uint32 cnt);
+extern void pgstat_count_io_op(IOObject io_object, IOContext io_context,
+                                                          IOOp io_op, uint32 cnt);
 extern instr_time pgstat_prepare_io_time(bool track_io_guc);
 extern void pgstat_count_io_op_time(IOObject io_object, IOContext io_context,
                                                                        IOOp io_op, instr_time start_time, uint32 cnt);