@@ -472,7 +472,7 @@ static BufferDesc *BufferAlloc(SMgrRelation smgr,
472
472
ForkNumber forkNum ,
473
473
BlockNumber blockNum ,
474
474
BufferAccessStrategy strategy ,
475
- bool * foundPtr , IOContext * io_context );
475
+ bool * foundPtr , IOContext io_context );
476
476
static void FlushBuffer (BufferDesc * buf , SMgrRelation reln ,
477
477
IOObject io_object , IOContext io_context );
478
478
static void FindAndDropRelationBuffers (RelFileLocator rlocator ,
@@ -850,13 +850,14 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
850
850
if (isLocalBuf )
851
851
{
852
852
/*
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.
855
854
* However, in some cases, the "strategy" may not be NULL, so we can't
856
855
* rely on IOContextForStrategy() to set the right IOContext for us.
857
856
* This may happen in cases like CREATE TEMPORARY TABLE AS...
858
857
*/
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 );
860
861
if (found )
861
862
pgBufferUsage .local_blks_hit ++ ;
862
863
else if (isExtend )
@@ -871,8 +872,10 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
871
872
* lookup the buffer. IO_IN_PROGRESS is set if the requested block is
872
873
* not currently in memory.
873
874
*/
875
+ io_context = IOContextForStrategy (strategy );
876
+ io_object = IOOBJECT_RELATION ;
874
877
bufHdr = BufferAlloc (smgr , relpersistence , forkNum , blockNum ,
875
- strategy , & found , & io_context );
878
+ strategy , & found , io_context );
876
879
if (found )
877
880
pgBufferUsage .shared_blks_hit ++ ;
878
881
else if (isExtend )
@@ -892,6 +895,7 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
892
895
/* Just need to update stats before we exit */
893
896
* hit = true;
894
897
VacuumPageHit ++ ;
898
+ pgstat_count_io_op (io_object , io_context , IOOP_HIT );
895
899
896
900
if (VacuumCostActive )
897
901
VacuumCostBalance += VacuumCostPageHit ;
@@ -987,16 +991,7 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
987
991
*/
988
992
Assert (!(pg_atomic_read_u32 (& bufHdr -> state ) & BM_VALID )); /* spinlock not needed */
989
993
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 );
1000
995
1001
996
if (isExtend )
1002
997
{
@@ -1139,7 +1134,7 @@ static BufferDesc *
1139
1134
BufferAlloc (SMgrRelation smgr , char relpersistence , ForkNumber forkNum ,
1140
1135
BlockNumber blockNum ,
1141
1136
BufferAccessStrategy strategy ,
1142
- bool * foundPtr , IOContext * io_context )
1137
+ bool * foundPtr , IOContext io_context )
1143
1138
{
1144
1139
bool from_ring ;
1145
1140
BufferTag newTag ; /* identity of requested block */
@@ -1193,11 +1188,8 @@ BufferAlloc(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
1193
1188
{
1194
1189
/*
1195
1190
* 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.
1199
1192
*/
1200
- * io_context = IOContextForStrategy (strategy );
1201
1193
* foundPtr = false;
1202
1194
}
1203
1195
}
@@ -1211,8 +1203,6 @@ BufferAlloc(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
1211
1203
*/
1212
1204
LWLockRelease (newPartitionLock );
1213
1205
1214
- * io_context = IOContextForStrategy (strategy );
1215
-
1216
1206
/* Loop here in case we have to try another victim buffer */
1217
1207
for (;;)
1218
1208
{
@@ -1295,7 +1285,7 @@ BufferAlloc(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
1295
1285
smgr -> smgr_rlocator .locator .dbOid ,
1296
1286
smgr -> smgr_rlocator .locator .relNumber );
1297
1287
1298
- FlushBuffer (buf , NULL , IOOBJECT_RELATION , * io_context );
1288
+ FlushBuffer (buf , NULL , IOOBJECT_RELATION , io_context );
1299
1289
LWLockRelease (BufferDescriptorGetContentLock (buf ));
1300
1290
1301
1291
ScheduleBufferTagForWriteback (& BackendWritebackContext ,
@@ -1494,7 +1484,7 @@ BufferAlloc(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
1494
1484
* we may have been forced to release the buffer due to concurrent
1495
1485
* pinners or erroring out.
1496
1486
*/
1497
- pgstat_count_io_op (IOOBJECT_RELATION , * io_context ,
1487
+ pgstat_count_io_op (IOOBJECT_RELATION , io_context ,
1498
1488
from_ring ? IOOP_REUSE : IOOP_EVICT );
1499
1489
}
1500
1490
0 commit comments