mirror of
https://github.com/postgres/postgres.git
synced 2025-06-30 21:42:05 +03:00
pgstat: Track more detailed relation IO statistics
Commit 28e626bde0
introduced the infrastructure for tracking more detailed IO
statistics. This commit adds the actual collection of the new IO statistics
for relations and temporary relations. See aforementioned commit for goals and
high-level design.
The changes in this commit are fairly straight-forward. The bulk of the change
is to passing sufficient information to the callsites of pgstat_count_io_op().
A somewhat unsightly detail is that it currently is hard to find a better
place to count fsyncs than in md.c, whereas the other pgstat_count_io_op()
calls are in bufmgr.c/localbuf.c. As the number of fsyncs is tied to md.c
implementation details, it's not obvious there is a better answer.
Author: Melanie Plageman <melanieplageman@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/20200124195226.lth52iydq2n2uilq@alap3.anarazel.de
This commit is contained in:
@ -18,6 +18,7 @@
|
||||
#include "access/parallel.h"
|
||||
#include "catalog/catalog.h"
|
||||
#include "executor/instrument.h"
|
||||
#include "pgstat.h"
|
||||
#include "storage/buf_internals.h"
|
||||
#include "storage/bufmgr.h"
|
||||
#include "utils/guc_hooks.h"
|
||||
@ -107,7 +108,7 @@ PrefetchLocalBuffer(SMgrRelation smgr, ForkNumber forkNum,
|
||||
*/
|
||||
BufferDesc *
|
||||
LocalBufferAlloc(SMgrRelation smgr, ForkNumber forkNum, BlockNumber blockNum,
|
||||
bool *foundPtr)
|
||||
bool *foundPtr, IOContext *io_context)
|
||||
{
|
||||
BufferTag newTag; /* identity of requested block */
|
||||
LocalBufferLookupEnt *hresult;
|
||||
@ -127,6 +128,14 @@ LocalBufferAlloc(SMgrRelation smgr, ForkNumber forkNum, BlockNumber blockNum,
|
||||
hresult = (LocalBufferLookupEnt *)
|
||||
hash_search(LocalBufHash, &newTag, HASH_FIND, NULL);
|
||||
|
||||
/*
|
||||
* IO Operations on local buffers are only done in IOCONTEXT_NORMAL. Set
|
||||
* io_context here (instead of after a buffer hit would have returned) for
|
||||
* convenience since we don't have to worry about the overhead of calling
|
||||
* IOContextForStrategy().
|
||||
*/
|
||||
*io_context = IOCONTEXT_NORMAL;
|
||||
|
||||
if (hresult)
|
||||
{
|
||||
b = hresult->id;
|
||||
@ -230,6 +239,7 @@ LocalBufferAlloc(SMgrRelation smgr, ForkNumber forkNum, BlockNumber blockNum,
|
||||
buf_state &= ~BM_DIRTY;
|
||||
pg_atomic_unlocked_write_u32(&bufHdr->state, buf_state);
|
||||
|
||||
pgstat_count_io_op(IOOBJECT_TEMP_RELATION, IOCONTEXT_NORMAL, IOOP_WRITE);
|
||||
pgBufferUsage.local_blks_written++;
|
||||
}
|
||||
|
||||
@ -255,6 +265,7 @@ LocalBufferAlloc(SMgrRelation smgr, ForkNumber forkNum, BlockNumber blockNum,
|
||||
ClearBufferTag(&bufHdr->tag);
|
||||
buf_state &= ~(BM_VALID | BM_TAG_VALID);
|
||||
pg_atomic_unlocked_write_u32(&bufHdr->state, buf_state);
|
||||
pgstat_count_io_op(IOOBJECT_TEMP_RELATION, IOCONTEXT_NORMAL, IOOP_EVICT);
|
||||
}
|
||||
|
||||
hresult = (LocalBufferLookupEnt *)
|
||||
|
Reference in New Issue
Block a user