diff options
author | Andres Freund <andres@anarazel.de> | 2023-04-07 13:24:26 -0700 |
---|---|---|
committer | Andres Freund <andres@anarazel.de> | 2023-04-07 13:24:26 -0700 |
commit | 704261ecc694db11d9b5feb4f05f57778214ba2f (patch) | |
tree | 469ca2e5673804e1ecf360166e8ac41ba85b1591 /src/backend | |
parent | bf5a894c557179b85500a307104b36e846e24f48 (diff) | |
download | postgresql-704261ecc694db11d9b5feb4f05f57778214ba2f.tar.gz |
Improve IO accounting for temp relation writes
Both pgstat_database and pgBufferUsage count IO timing for reads of temporary
relation blocks into local buffers. However, both failed to count write IO
timing for flushes of dirty local buffers. Fix.
Additionally, FlushRelationBuffers() seems to have omitted counting write
IO (both count and timing) stats for both pgstat_database and
pgBufferUsage. Fix.
Author: Melanie Plageman <melanieplageman@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/20230321023451.7rzy4kjj2iktrg2r%40awork3.anarazel.de
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/storage/buffer/bufmgr.c | 17 | ||||
-rw-r--r-- | src/backend/storage/buffer/localbuf.c | 16 |
2 files changed, 33 insertions, 0 deletions
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 908a8934bd..ef69f21adf 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -4062,6 +4062,8 @@ FlushRelationBuffers(Relation rel) { int i; BufferDesc *bufHdr; + instr_time io_start, + io_time; if (RelationUsesLocalBuffers(rel)) { @@ -4087,6 +4089,11 @@ FlushRelationBuffers(Relation rel) PageSetChecksumInplace(localpage, bufHdr->tag.blockNum); + if (track_io_timing) + INSTR_TIME_SET_CURRENT(io_start); + else + INSTR_TIME_SET_ZERO(io_start); + smgrwrite(RelationGetSmgr(rel), BufTagGetForkNum(&bufHdr->tag), bufHdr->tag.blockNum, @@ -4098,6 +4105,16 @@ FlushRelationBuffers(Relation rel) pgstat_count_io_op(IOOBJECT_TEMP_RELATION, IOCONTEXT_NORMAL, IOOP_WRITE); + if (track_io_timing) + { + INSTR_TIME_SET_CURRENT(io_time); + INSTR_TIME_SUBTRACT(io_time, io_start); + pgstat_count_buffer_write_time(INSTR_TIME_GET_MICROSEC(io_time)); + INSTR_TIME_ADD(pgBufferUsage.blk_write_time, io_time); + } + + pgBufferUsage.local_blks_written++; + /* Pop the error context stack */ error_context_stack = errcallback.previous; } diff --git a/src/backend/storage/buffer/localbuf.c b/src/backend/storage/buffer/localbuf.c index 3846d3eaca..3639296bc1 100644 --- a/src/backend/storage/buffer/localbuf.c +++ b/src/backend/storage/buffer/localbuf.c @@ -176,6 +176,8 @@ GetLocalVictimBuffer(void) int trycounter; uint32 buf_state; BufferDesc *bufHdr; + instr_time io_start, + io_time; ResourceOwnerEnlargeBuffers(CurrentResourceOwner); @@ -239,6 +241,11 @@ GetLocalVictimBuffer(void) PageSetChecksumInplace(localpage, bufHdr->tag.blockNum); + if (track_io_timing) + INSTR_TIME_SET_CURRENT(io_start); + else + INSTR_TIME_SET_ZERO(io_start); + /* And write... */ smgrwrite(oreln, BufTagGetForkNum(&bufHdr->tag), @@ -252,6 +259,15 @@ GetLocalVictimBuffer(void) /* Temporary table I/O does not use Buffer Access Strategies */ pgstat_count_io_op(IOOBJECT_TEMP_RELATION, IOCONTEXT_NORMAL, IOOP_WRITE); + + if (track_io_timing) + { + INSTR_TIME_SET_CURRENT(io_time); + INSTR_TIME_SUBTRACT(io_time, io_start); + pgstat_count_buffer_write_time(INSTR_TIME_GET_MICROSEC(io_time)); + INSTR_TIME_ADD(pgBufferUsage.blk_write_time, io_time); + } + pgBufferUsage.local_blks_written++; } |