@@ -248,6 +248,13 @@ typedef enum
248
248
*/
249
249
#define EAGER_SCAN_REGION_SIZE 4096
250
250
251
+ /*
252
+ * heap_vac_scan_next_block() sets these flags to communicate information
253
+ * about the block it read to the caller.
254
+ */
255
+ #define VAC_BLK_WAS_EAGER_SCANNED (1 << 0)
256
+ #define VAC_BLK_ALL_VISIBLE_ACCORDING_TO_VM (1 << 1)
257
+
251
258
typedef struct LVRelState
252
259
{
253
260
/* Target heap relation and its indexes */
@@ -417,8 +424,7 @@ static void lazy_scan_heap(LVRelState *vacrel);
417
424
static void heap_vacuum_eager_scan_setup (LVRelState * vacrel ,
418
425
VacuumParams * params );
419
426
static bool heap_vac_scan_next_block (LVRelState * vacrel , BlockNumber * blkno ,
420
- bool * all_visible_according_to_vm ,
421
- bool * was_eager_scanned );
427
+ uint8 * blk_info );
422
428
static void find_next_unskippable_block (LVRelState * vacrel , bool * skipsallvis );
423
429
static bool lazy_scan_new_or_empty (LVRelState * vacrel , Buffer buf ,
424
430
BlockNumber blkno , Page page ,
@@ -1171,8 +1177,7 @@ lazy_scan_heap(LVRelState *vacrel)
1171
1177
BlockNumber rel_pages = vacrel -> rel_pages ,
1172
1178
blkno ,
1173
1179
next_fsm_block_to_vacuum = 0 ;
1174
- bool all_visible_according_to_vm ,
1175
- was_eager_scanned = false;
1180
+ uint8 blk_info = 0 ;
1176
1181
BlockNumber orig_eager_scan_success_limit =
1177
1182
vacrel -> eager_scan_remaining_successes ; /* for logging */
1178
1183
Buffer vmbuffer = InvalidBuffer ;
@@ -1196,8 +1201,7 @@ lazy_scan_heap(LVRelState *vacrel)
1196
1201
vacrel -> next_unskippable_eager_scanned = false;
1197
1202
vacrel -> next_unskippable_vmbuffer = InvalidBuffer ;
1198
1203
1199
- while (heap_vac_scan_next_block (vacrel , & blkno , & all_visible_according_to_vm ,
1200
- & was_eager_scanned ))
1204
+ while (heap_vac_scan_next_block (vacrel , & blkno , & blk_info ))
1201
1205
{
1202
1206
Buffer buf ;
1203
1207
Page page ;
@@ -1206,7 +1210,7 @@ lazy_scan_heap(LVRelState *vacrel)
1206
1210
bool got_cleanup_lock = false;
1207
1211
1208
1212
vacrel -> scanned_pages ++ ;
1209
- if (was_eager_scanned )
1213
+ if (blk_info & VAC_BLK_WAS_EAGER_SCANNED )
1210
1214
vacrel -> eager_scanned_pages ++ ;
1211
1215
1212
1216
/* Report as block scanned, update error traceback information */
@@ -1331,7 +1335,8 @@ lazy_scan_heap(LVRelState *vacrel)
1331
1335
*/
1332
1336
if (got_cleanup_lock )
1333
1337
lazy_scan_prune (vacrel , buf , blkno , page ,
1334
- vmbuffer , all_visible_according_to_vm ,
1338
+ vmbuffer ,
1339
+ blk_info & VAC_BLK_ALL_VISIBLE_ACCORDING_TO_VM ,
1335
1340
& has_lpdead_items , & vm_page_frozen );
1336
1341
1337
1342
/*
@@ -1348,7 +1353,8 @@ lazy_scan_heap(LVRelState *vacrel)
1348
1353
* exclude pages skipped due to cleanup lock contention from eager
1349
1354
* freeze algorithm caps.
1350
1355
*/
1351
- if (got_cleanup_lock && was_eager_scanned )
1356
+ if (got_cleanup_lock &&
1357
+ (blk_info & VAC_BLK_WAS_EAGER_SCANNED ))
1352
1358
{
1353
1359
/* Aggressive vacuums do not eager scan. */
1354
1360
Assert (!vacrel -> aggressive );
@@ -1479,11 +1485,11 @@ lazy_scan_heap(LVRelState *vacrel)
1479
1485
* and various thresholds to skip blocks which do not need to be processed and
1480
1486
* sets blkno to the next block to process.
1481
1487
*
1482
- * The block number and visibility status of the next block to process are set
1483
- * in *blkno and *all_visible_according_to_vm. The return value is false if
1484
- * there are no further blocks to process. If the block is being eagerly
1485
- * scanned, was_eager_scanned is set so that the caller can count whether or
1486
- * not an eagerly scanned page is successfully frozen .
1488
+ * The block number of the next block to process is set in *blkno and its
1489
+ * visibility status and whether or not it was eager scanned is set in
1490
+ * *blk_info.
1491
+ *
1492
+ * The return value is false if there are no further blocks to process .
1487
1493
*
1488
1494
* vacrel is an in/out parameter here. Vacuum options and information about
1489
1495
* the relation are read. vacrel->skippedallvis is set if we skip a block
@@ -1493,15 +1499,14 @@ lazy_scan_heap(LVRelState *vacrel)
1493
1499
*/
1494
1500
static bool
1495
1501
heap_vac_scan_next_block (LVRelState * vacrel , BlockNumber * blkno ,
1496
- bool * all_visible_according_to_vm ,
1497
- bool * was_eager_scanned )
1502
+ uint8 * blk_info )
1498
1503
{
1499
1504
BlockNumber next_block ;
1500
1505
1501
1506
/* relies on InvalidBlockNumber + 1 overflowing to 0 on first call */
1502
1507
next_block = vacrel -> current_block + 1 ;
1503
1508
1504
- * was_eager_scanned = false ;
1509
+ * blk_info = 0 ;
1505
1510
1506
1511
/* Have we reached the end of the relation? */
1507
1512
if (next_block >= vacrel -> rel_pages )
@@ -1562,7 +1567,7 @@ heap_vac_scan_next_block(LVRelState *vacrel, BlockNumber *blkno,
1562
1567
* otherwise they would've been unskippable.
1563
1568
*/
1564
1569
* blkno = vacrel -> current_block = next_block ;
1565
- * all_visible_according_to_vm = true ;
1570
+ * blk_info |= VAC_BLK_ALL_VISIBLE_ACCORDING_TO_VM ;
1566
1571
return true;
1567
1572
}
1568
1573
else
@@ -1574,8 +1579,10 @@ heap_vac_scan_next_block(LVRelState *vacrel, BlockNumber *blkno,
1574
1579
Assert (next_block == vacrel -> next_unskippable_block );
1575
1580
1576
1581
* blkno = vacrel -> current_block = next_block ;
1577
- * all_visible_according_to_vm = vacrel -> next_unskippable_allvis ;
1578
- * was_eager_scanned = vacrel -> next_unskippable_eager_scanned ;
1582
+ if (vacrel -> next_unskippable_allvis )
1583
+ * blk_info |= VAC_BLK_ALL_VISIBLE_ACCORDING_TO_VM ;
1584
+ if (vacrel -> next_unskippable_eager_scanned )
1585
+ * blk_info |= VAC_BLK_WAS_EAGER_SCANNED ;
1579
1586
return true;
1580
1587
}
1581
1588
}
0 commit comments