mirror of
https://github.com/postgres/postgres.git
synced 2025-09-05 02:22:28 +03:00
Track shared buffer hits in pg_stat_io
Among other things, this should make it easier to calculate a useful cache hit ratio by excluding buffer reads via buffer access strategies. As buffer access strategies reuse buffers (and thus evict the prior buffer contents), it is normal to see reads on repeated scans of the same data. Author: Melanie Plageman <melanieplageman@gmail.com> Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com> Reviewed-by: Andres Freund <andres@anarazel.de> Discussion: https://postgr.es/m/CAAKRu_beMa9Hzih40%3DXPYqhDVz6tsgUGTrhZXRo%3Dunp%2Bszb%3DUA%40mail.gmail.com
This commit is contained in:
@@ -108,7 +108,7 @@ PrefetchLocalBuffer(SMgrRelation smgr, ForkNumber forkNum,
|
||||
*/
|
||||
BufferDesc *
|
||||
LocalBufferAlloc(SMgrRelation smgr, ForkNumber forkNum, BlockNumber blockNum,
|
||||
bool *foundPtr, IOContext *io_context)
|
||||
bool *foundPtr)
|
||||
{
|
||||
BufferTag newTag; /* identity of requested block */
|
||||
LocalBufferLookupEnt *hresult;
|
||||
@@ -128,14 +128,6 @@ 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;
|
||||
@@ -239,6 +231,7 @@ LocalBufferAlloc(SMgrRelation smgr, ForkNumber forkNum, BlockNumber blockNum,
|
||||
buf_state &= ~BM_DIRTY;
|
||||
pg_atomic_unlocked_write_u32(&bufHdr->state, buf_state);
|
||||
|
||||
/* Temporary table I/O does not use Buffer Access Strategies */
|
||||
pgstat_count_io_op(IOOBJECT_TEMP_RELATION, IOCONTEXT_NORMAL, IOOP_WRITE);
|
||||
pgBufferUsage.local_blks_written++;
|
||||
}
|
||||
|
Reference in New Issue
Block a user