Re: Make pg_stat_io view count IOs as bytes instead of blocks

Michael Paquier <michael@paquier.xyz>

From: Michael Paquier <michael@paquier.xyz>
To: Nazir Bilal Yavuz <byavuz81@gmail.com>
Cc: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>, Melanie Plageman <melanieplageman@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2024-12-24T06:12:48Z
Lists: pgsql-hackers
On Fri, Dec 06, 2024 at 12:41:55PM +0300, Nazir Bilal Yavuz wrote:
> Thanks! I think 'track' is a better word in this context. I used
> 'tracked in ...', as it sounded more correct to me (I hope it is).

Splitting op_bytes into three fields sounds like a good idea.  Count
me in regarding the concept to depend less on BLCKSZ.

 typedef enum IOOp
 {
+	/* IOs not tracked in bytes */
 	IOOP_EVICT,
-	IOOP_EXTEND,
 	IOOP_FSYNC,
 	IOOP_HIT,
-	IOOP_READ,
 	IOOP_REUSE,
-	IOOP_WRITE,
 	IOOP_WRITEBACK,
+
+	/* IOs tracked in bytes */
+	IOOP_EXTEND,
+	IOOP_READ,
+	IOOP_WRITE,
 } IOOp;

pg_stat_io_build_tuples() is now the code path taken when building the
tuples returned by pg_stat_io, meaning that the new function called
pg_stat_get_backend_io() is also going to need an update in its list
of output parameters to accomodate with what you are changing here.
Calling your new pgstat_get_io_byte_index() in the new refactored
routine is also necessary.  Sorry about that.

Could you send a rebase, please?  I can promise to review this
thread's new patch, as that will also move the needle regarding your
work with pg_stat_io to track WAL activity.
--
Michael

Commits

  1. Rework macro pgstat_is_ioop_tracked_in_bytes()

  2. Remove assertion in pgstat_count_io_op()

  3. Make pg_stat_io count IOs as bytes instead of blocks for some operations

  4. Merge pgstat_count_io_op_n() and pgstat_count_io_op()