diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c index d6a8cf390c..2921092b6b 100644 --- a/src/backend/access/heap/vacuumlazy.c +++ b/src/backend/access/heap/vacuumlazy.c @@ -237,6 +237,10 @@ typedef struct LVShared */ pg_atomic_uint32 active_nworkers; + /* Variables to indicate buffer access strategy. */ + BufferAccessStrategyType btype; + int ring_size; + /* * Variables to control parallel vacuum. We have a bitmap to indicate * which index has stats in shared memory. The set bit in the map @@ -3311,6 +3315,8 @@ begin_parallel_vacuum(Oid relid, Relation *Irel, LVRelStats *vacrelstats, pg_atomic_init_u32(&(shared->cost_balance), 0); pg_atomic_init_u32(&(shared->active_nworkers), 0); + shared->btype = GetAccessStrategyType(vac_strategy); + shared->ring_size = GetAccessStrategyRingSize(vac_strategy); pg_atomic_init_u32(&(shared->idx), 0); shared->offset = MAXALIGN(add_size(SizeOfLVShared, BITMAPLEN(nindexes))); prepare_index_statistics(shared, can_parallel_vacuum, nindexes); @@ -3510,6 +3516,9 @@ parallel_vacuum_main(dsm_segment *seg, shm_toc *toc) vac_open_indexes(onerel, RowExclusiveLock, &nindexes, &indrels); Assert(nindexes > 0); + /* Set vacuum access strategy */ + vac_strategy = FormAccessStrategy(lvshared->btype, lvshared->ring_size); + /* Set dead tuple space */ dead_tuples = (LVDeadTuples *) shm_toc_lookup(toc, PARALLEL_VACUUM_KEY_DEAD_TUPLES, @@ -3564,6 +3573,7 @@ parallel_vacuum_main(dsm_segment *seg, shm_toc *toc) vac_close_indexes(nindexes, indrels, RowExclusiveLock); table_close(onerel, ShareUpdateExclusiveLock); + FreeAccessStrategy(vac_strategy); pfree(stats); } diff --git a/src/backend/storage/buffer/freelist.c b/src/backend/storage/buffer/freelist.c index 942f8d4edd..ece0bb0774 100644 --- a/src/backend/storage/buffer/freelist.c +++ b/src/backend/storage/buffer/freelist.c @@ -587,6 +587,44 @@ GetAccessStrategy(BufferAccessStrategyType btype) return strategy; } +/* Get buffer access strategy type */ +BufferAccessStrategyType +GetAccessStrategyType(BufferAccessStrategy strategy) +{ + Assert(strategy); + return strategy->btype; +} + +/* Get buffer access strategy ring size */ +int +GetAccessStrategyRingSize(BufferAccessStrategy strategy) +{ + Assert(strategy); + return strategy->ring_size; +} + +/* + * This allocates and prepares the access strategy based on input parameters. + * + * The object is allocated in the current memory context. + */ +BufferAccessStrategy +FormAccessStrategy(BufferAccessStrategyType btype, int ring_size) +{ + BufferAccessStrategy strategy; + + /* Allocate the object and initialize all elements to zeroes */ + strategy = (BufferAccessStrategy) + palloc0(offsetof(BufferAccessStrategyData, buffers) + + ring_size * sizeof(Buffer)); + + /* Set fields that don't start out zero */ + strategy->btype = btype; + strategy->ring_size = ring_size; + + return strategy; +} + /* * FreeAccessStrategy -- release a BufferAccessStrategy object * diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index ee91b8fa26..3e65716b60 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -242,6 +242,9 @@ extern void TestForOldSnapshot_impl(Snapshot snapshot, Relation relation); /* in freelist.c */ extern BufferAccessStrategy GetAccessStrategy(BufferAccessStrategyType btype); +extern BufferAccessStrategyType GetAccessStrategyType(BufferAccessStrategy strategy); +extern int GetAccessStrategyRingSize(BufferAccessStrategy strategy); +extern BufferAccessStrategy FormAccessStrategy(BufferAccessStrategyType btype, int ring_size); extern void FreeAccessStrategy(BufferAccessStrategy strategy);