1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-22 12:22:45 +03:00

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

Currently in pg_stat_io view, IOs are counted as blocks of size
BLCKSZ.  There are two limitations with this design:
* The actual number of I/O requests sent to the kernel is lower because
I/O requests may be merged before being sent.  Additionally, it gives
the impression that all I/Os are done in block size, which shadows the
benefits of merging I/O requests.
* Some patches are under work to extend pg_stat_io for the tracking of
operations that may not be linked to the block size.  For example, WAL
read IOs are done in variable bytes and it is not possible to correctly
show these IOs in pg_stat_io view, and we want to keep all this data in
a single system view rather than spread it across multiple relations to
ease monitoring.

WaitReadBuffers() can now be tracked as a single read operation
worth N blocks.  Same for ExtendBufferedRelShared() and
ExtendBufferedRelLocal() for extensions.

Three columns are added to pg_stat_io for reads, writes and extensions
for the byte calculations.  op_bytes, which was always hardcoded to
BLCKSZ, is removed.  IO backend statistics are updated to reflect these
changes.

Bump catalog version.

Author: Nazir Bilal Yavuz
Reviewed-by: Bertrand Drouvot, Melanie Plageman
Discussion: https://postgr.es/m/CAN55FZ0oqxBaaHAEsj=xFqkzE3n5P=3RA1V_igXwL-RV7QRzyw@mail.gmail.com
This commit is contained in:
Michael Paquier
2025-01-14 12:14:29 +09:00
parent b4a07f532b
commit f92c854cf4
12 changed files with 170 additions and 77 deletions

View File

@@ -65,6 +65,8 @@ pgstat_flush_backend_entry_io(PgStat_EntryRef *entry_ref)
bktype_shstats->counts[io_object][io_context][io_op] +=
pending_io->counts[io_object][io_context][io_op];
bktype_shstats->bytes[io_object][io_context][io_op] +=
pending_io->bytes[io_object][io_context][io_op];
time = pending_io->pending_times[io_object][io_context][io_op];

View File

@@ -23,6 +23,13 @@
static PgStat_PendingIO PendingIOStats;
static bool have_iostats = false;
/*
* Check if an IOOp is tracked in bytes. This relies on the ordering of IOOp
* defined in pgstat.h, so make sure to update this check when changing its
* elements.
*/
#define pgstat_is_ioop_tracked_in_bytes(io_op) \
((io_op) < IOOP_NUM_TYPES && (io_op) >= IOOP_EXTEND)
/*
* Check that stats have not been counted for any combination of IOObject,
@@ -66,11 +73,13 @@ pgstat_bktype_io_stats_valid(PgStat_BktypeIO *backend_io,
}
void
pgstat_count_io_op(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, uint64 bytes)
{
Assert((unsigned int) io_object < IOOBJECT_NUM_TYPES);
Assert((unsigned int) io_context < IOCONTEXT_NUM_TYPES);
Assert((unsigned int) io_op < IOOP_NUM_TYPES);
Assert(pgstat_is_ioop_tracked_in_bytes(io_op) || bytes == 0);
Assert(pgstat_tracks_io_op(MyBackendType, io_object, io_context, io_op));
if (pgstat_tracks_backend_bktype(MyBackendType))
@@ -79,9 +88,11 @@ pgstat_count_io_op(IOObject io_object, IOContext io_context, IOOp io_op, uint32
entry_ref = pgstat_prep_backend_pending(MyProcNumber);
entry_ref->pending_io.counts[io_object][io_context][io_op] += cnt;
entry_ref->pending_io.bytes[io_object][io_context][io_op] += bytes;
}
PendingIOStats.counts[io_object][io_context][io_op] += cnt;
PendingIOStats.bytes[io_object][io_context][io_op] += bytes;
have_iostats = true;
}
@@ -114,7 +125,7 @@ pgstat_prepare_io_time(bool track_io_guc)
*/
void
pgstat_count_io_op_time(IOObject io_object, IOContext io_context, IOOp io_op,
instr_time start_time, uint32 cnt)
instr_time start_time, uint32 cnt, uint64 bytes)
{
if (track_io_timing)
{
@@ -153,7 +164,7 @@ pgstat_count_io_op_time(IOObject io_object, IOContext io_context, IOOp io_op,
}
}
pgstat_count_io_op(io_object, io_context, io_op, cnt);
pgstat_count_io_op(io_object, io_context, io_op, cnt, bytes);
}
PgStat_IO *
@@ -219,6 +230,9 @@ pgstat_io_flush_cb(bool nowait)
bktype_shstats->counts[io_object][io_context][io_op] +=
PendingIOStats.counts[io_object][io_context][io_op];
bktype_shstats->bytes[io_object][io_context][io_op] +=
PendingIOStats.bytes[io_object][io_context][io_op];
time = PendingIOStats.pending_times[io_object][io_context][io_op];
bktype_shstats->times[io_object][io_context][io_op] +=