@@ -248,6 +248,13 @@ typedef enum
248248 */
249249#define EAGER_SCAN_REGION_SIZE 4096
250250
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+
251258typedef struct LVRelState
252259{
253260 /* Target heap relation and its indexes */
@@ -417,8 +424,7 @@ static void lazy_scan_heap(LVRelState *vacrel);
417424static void heap_vacuum_eager_scan_setup (LVRelState * vacrel ,
418425 VacuumParams * params );
419426static 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 );
422428static void find_next_unskippable_block (LVRelState * vacrel , bool * skipsallvis );
423429static bool lazy_scan_new_or_empty (LVRelState * vacrel , Buffer buf ,
424430 BlockNumber blkno , Page page ,
@@ -1171,8 +1177,7 @@ lazy_scan_heap(LVRelState *vacrel)
11711177 BlockNumber rel_pages = vacrel -> rel_pages ,
11721178 blkno ,
11731179 next_fsm_block_to_vacuum = 0 ;
1174- bool all_visible_according_to_vm ,
1175- was_eager_scanned = false;
1180+ uint8 blk_info = 0 ;
11761181 BlockNumber orig_eager_scan_success_limit =
11771182 vacrel -> eager_scan_remaining_successes ; /* for logging */
11781183 Buffer vmbuffer = InvalidBuffer ;
@@ -1196,8 +1201,7 @@ lazy_scan_heap(LVRelState *vacrel)
11961201 vacrel -> next_unskippable_eager_scanned = false;
11971202 vacrel -> next_unskippable_vmbuffer = InvalidBuffer ;
11981203
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 ))
12011205 {
12021206 Buffer buf ;
12031207 Page page ;
@@ -1206,7 +1210,7 @@ lazy_scan_heap(LVRelState *vacrel)
12061210 bool got_cleanup_lock = false;
12071211
12081212 vacrel -> scanned_pages ++ ;
1209- if (was_eager_scanned )
1213+ if (blk_info & VAC_BLK_WAS_EAGER_SCANNED )
12101214 vacrel -> eager_scanned_pages ++ ;
12111215
12121216 /* Report as block scanned, update error traceback information */
@@ -1331,7 +1335,8 @@ lazy_scan_heap(LVRelState *vacrel)
13311335 */
13321336 if (got_cleanup_lock )
13331337 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 ,
13351340 & has_lpdead_items , & vm_page_frozen );
13361341
13371342 /*
@@ -1348,7 +1353,8 @@ lazy_scan_heap(LVRelState *vacrel)
13481353 * exclude pages skipped due to cleanup lock contention from eager
13491354 * freeze algorithm caps.
13501355 */
1351- if (got_cleanup_lock && was_eager_scanned )
1356+ if (got_cleanup_lock &&
1357+ (blk_info & VAC_BLK_WAS_EAGER_SCANNED ))
13521358 {
13531359 /* Aggressive vacuums do not eager scan. */
13541360 Assert (!vacrel -> aggressive );
@@ -1479,11 +1485,11 @@ lazy_scan_heap(LVRelState *vacrel)
14791485 * and various thresholds to skip blocks which do not need to be processed and
14801486 * sets blkno to the next block to process.
14811487 *
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 .
14871493 *
14881494 * vacrel is an in/out parameter here. Vacuum options and information about
14891495 * the relation are read. vacrel->skippedallvis is set if we skip a block
@@ -1493,15 +1499,14 @@ lazy_scan_heap(LVRelState *vacrel)
14931499 */
14941500static bool
14951501heap_vac_scan_next_block (LVRelState * vacrel , BlockNumber * blkno ,
1496- bool * all_visible_according_to_vm ,
1497- bool * was_eager_scanned )
1502+ uint8 * blk_info )
14981503{
14991504 BlockNumber next_block ;
15001505
15011506 /* relies on InvalidBlockNumber + 1 overflowing to 0 on first call */
15021507 next_block = vacrel -> current_block + 1 ;
15031508
1504- * was_eager_scanned = false ;
1509+ * blk_info = 0 ;
15051510
15061511 /* Have we reached the end of the relation? */
15071512 if (next_block >= vacrel -> rel_pages )
@@ -1562,7 +1567,7 @@ heap_vac_scan_next_block(LVRelState *vacrel, BlockNumber *blkno,
15621567 * otherwise they would've been unskippable.
15631568 */
15641569 * blkno = vacrel -> current_block = next_block ;
1565- * all_visible_according_to_vm = true ;
1570+ * blk_info |= VAC_BLK_ALL_VISIBLE_ACCORDING_TO_VM ;
15661571 return true;
15671572 }
15681573 else
@@ -1574,8 +1579,10 @@ heap_vac_scan_next_block(LVRelState *vacrel, BlockNumber *blkno,
15741579 Assert (next_block == vacrel -> next_unskippable_block );
15751580
15761581 * 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 ;
15791586 return true;
15801587 }
15811588}
0 commit comments