@@ -472,7 +472,7 @@ static BufferDesc *BufferAlloc(SMgrRelation smgr,
472472ForkNumber forkNum ,
473473BlockNumber blockNum ,
474474BufferAccessStrategy strategy ,
475- bool * foundPtr ,IOContext * io_context );
475+ bool * foundPtr ,IOContext io_context );
476476static void FlushBuffer (BufferDesc * buf ,SMgrRelation reln ,
477477IOObject io_object ,IOContext io_context );
478478static void FindAndDropRelationBuffers (RelFileLocator rlocator ,
@@ -850,13 +850,14 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
850850if (isLocalBuf )
851851{
852852/*
853- * LocalBufferAlloc() will set the io_context to IOCONTEXT_NORMAL. We
854- * do not use a BufferAccessStrategy for I/O of temporary tables.
853+ * We do not use a BufferAccessStrategy for I/O of temporary tables.
855854 * However, in some cases, the "strategy" may not be NULL, so we can't
856855 * rely on IOContextForStrategy() to set the right IOContext for us.
857856 * This may happen in cases like CREATE TEMPORARY TABLE AS...
858857 */
859- bufHdr = LocalBufferAlloc (smgr ,forkNum ,blockNum ,& found ,& io_context );
858+ io_context = IOCONTEXT_NORMAL ;
859+ io_object = IOOBJECT_TEMP_RELATION ;
860+ bufHdr = LocalBufferAlloc (smgr ,forkNum ,blockNum ,& found );
860861if (found )
861862pgBufferUsage .local_blks_hit ++ ;
862863else if (isExtend )
@@ -871,8 +872,10 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
871872 * lookup the buffer. IO_IN_PROGRESS is set if the requested block is
872873 * not currently in memory.
873874 */
875+ io_context = IOContextForStrategy (strategy );
876+ io_object = IOOBJECT_RELATION ;
874877bufHdr = BufferAlloc (smgr ,relpersistence ,forkNum ,blockNum ,
875- strategy ,& found ,& io_context );
878+ strategy ,& found ,io_context );
876879if (found )
877880pgBufferUsage .shared_blks_hit ++ ;
878881else if (isExtend )
@@ -892,6 +895,7 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
892895/* Just need to update stats before we exit */
893896* hit = true;
894897VacuumPageHit ++ ;
898+ pgstat_count_io_op (io_object ,io_context ,IOOP_HIT );
895899
896900if (VacuumCostActive )
897901VacuumCostBalance += VacuumCostPageHit ;
@@ -987,16 +991,7 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
987991 */
988992Assert (!(pg_atomic_read_u32 (& bufHdr -> state )& BM_VALID ));/* spinlock not needed */
989993
990- if (isLocalBuf )
991- {
992- bufBlock = LocalBufHdrGetBlock (bufHdr );
993- io_object = IOOBJECT_TEMP_RELATION ;
994- }
995- else
996- {
997- bufBlock = BufHdrGetBlock (bufHdr );
998- io_object = IOOBJECT_RELATION ;
999- }
994+ bufBlock = isLocalBuf ?LocalBufHdrGetBlock (bufHdr ) :BufHdrGetBlock (bufHdr );
1000995
1001996if (isExtend )
1002997{
@@ -1139,7 +1134,7 @@ static BufferDesc *
11391134BufferAlloc (SMgrRelation smgr ,char relpersistence ,ForkNumber forkNum ,
11401135BlockNumber blockNum ,
11411136BufferAccessStrategy strategy ,
1142- bool * foundPtr ,IOContext * io_context )
1137+ bool * foundPtr ,IOContext io_context )
11431138{
11441139bool from_ring ;
11451140BufferTag newTag ;/* identity of requested block */
@@ -1193,11 +1188,8 @@ BufferAlloc(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
11931188{
11941189/*
11951190 * If we get here, previous attempts to read the buffer must
1196- * have failed ... but we shall bravely try again. Set
1197- * io_context since we will in fact need to count an IO
1198- * Operation.
1191+ * have failed ... but we shall bravely try again.
11991192 */
1200- * io_context = IOContextForStrategy (strategy );
12011193* foundPtr = false;
12021194}
12031195}
@@ -1211,8 +1203,6 @@ BufferAlloc(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
12111203 */
12121204LWLockRelease (newPartitionLock );
12131205
1214- * io_context = IOContextForStrategy (strategy );
1215-
12161206/* Loop here in case we have to try another victim buffer */
12171207for (;;)
12181208{
@@ -1295,7 +1285,7 @@ BufferAlloc(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
12951285smgr -> smgr_rlocator .locator .dbOid ,
12961286smgr -> smgr_rlocator .locator .relNumber );
12971287
1298- FlushBuffer (buf ,NULL ,IOOBJECT_RELATION ,* io_context );
1288+ FlushBuffer (buf ,NULL ,IOOBJECT_RELATION ,io_context );
12991289LWLockRelease (BufferDescriptorGetContentLock (buf ));
13001290
13011291ScheduleBufferTagForWriteback (& BackendWritebackContext ,
@@ -1494,7 +1484,7 @@ BufferAlloc(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
14941484 * we may have been forced to release the buffer due to concurrent
14951485 * pinners or erroring out.
14961486 */
1497- pgstat_count_io_op (IOOBJECT_RELATION ,* io_context ,
1487+ pgstat_count_io_op (IOOBJECT_RELATION ,io_context ,
14981488from_ring ?IOOP_REUSE :IOOP_EVICT );
14991489}
15001490