@@ -472,7 +472,7 @@ static BufferDesc *BufferAlloc(SMgrRelation smgr,
472472 ForkNumber forkNum ,
473473 BlockNumber blockNum ,
474474 BufferAccessStrategy strategy ,
475- bool * foundPtr , IOContext * io_context );
475+ bool * foundPtr , IOContext io_context );
476476static void FlushBuffer (BufferDesc * buf , SMgrRelation reln ,
477477 IOObject io_object , IOContext io_context );
478478static void FindAndDropRelationBuffers (RelFileLocator rlocator ,
@@ -850,13 +850,14 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
850850 if (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 );
860861 if (found )
861862 pgBufferUsage .local_blks_hit ++ ;
862863 else 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 ;
874877 bufHdr = BufferAlloc (smgr , relpersistence , forkNum , blockNum ,
875- strategy , & found , & io_context );
878+ strategy , & found , io_context );
876879 if (found )
877880 pgBufferUsage .shared_blks_hit ++ ;
878881 else 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;
894897 VacuumPageHit ++ ;
898+ pgstat_count_io_op (io_object , io_context , IOOP_HIT );
895899
896900 if (VacuumCostActive )
897901 VacuumCostBalance += VacuumCostPageHit ;
@@ -987,16 +991,7 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
987991 */
988992 Assert (!(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
1001996 if (isExtend )
1002997 {
@@ -1139,7 +1134,7 @@ static BufferDesc *
11391134BufferAlloc (SMgrRelation smgr , char relpersistence , ForkNumber forkNum ,
11401135 BlockNumber blockNum ,
11411136 BufferAccessStrategy strategy ,
1142- bool * foundPtr , IOContext * io_context )
1137+ bool * foundPtr , IOContext io_context )
11431138{
11441139 bool from_ring ;
11451140 BufferTag 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 */
12121204 LWLockRelease (newPartitionLock );
12131205
1214- * io_context = IOContextForStrategy (strategy );
1215-
12161206 /* Loop here in case we have to try another victim buffer */
12171207 for (;;)
12181208 {
@@ -1295,7 +1285,7 @@ BufferAlloc(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
12951285 smgr -> smgr_rlocator .locator .dbOid ,
12961286 smgr -> smgr_rlocator .locator .relNumber );
12971287
1298- FlushBuffer (buf , NULL , IOOBJECT_RELATION , * io_context );
1288+ FlushBuffer (buf , NULL , IOOBJECT_RELATION , io_context );
12991289 LWLockRelease (BufferDescriptorGetContentLock (buf ));
13001290
13011291 ScheduleBufferTagForWriteback (& 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 ,
14981488 from_ring ? IOOP_REUSE : IOOP_EVICT );
14991489 }
15001490
0 commit comments