@@ -449,9 +449,9 @@ ptrackCheckpoint(void)
449449uint32 lsn ;
450450
451451/*
452- * We store LSN values aspg_atomic_uint64 in the ptrack map, but
453- *pg_atomic_read_u64 () returnsuint64 . That way, we have to put this
454- * lsn into the buffer array ofpg_atomic_uint64 's. We are the only
452+ * We store LSN values aspg_atomic_uint32 in the ptrack map, but
453+ *pg_atomic_read_u32 () returnsuint32 . That way, we have to put this
454+ * lsn into the buffer array ofpg_atomic_uint32 's. We are the only
455455 * one who write into this buffer, so we do it without locks.
456456 *
457457 * TODO: is it safe and can we do any better?
@@ -551,7 +551,7 @@ assign_ptrack_map_size(int newval, void *extra)
551551!InitializingParallelWorker )
552552{
553553/* Cast to uint64 in order to avoid int32 overflow */
554- ptrack_map_size = (uint64 )1024 * 1024 * newval ;
554+ ptrack_map_size = (uint64 )( 1024 * 1024 * newval ) ;
555555
556556elog (DEBUG1 ,"assign_ptrack_map_size: ptrack_map_size set to " UINT64_FORMAT ,
557557ptrack_map_size );
@@ -688,30 +688,13 @@ ptrack_walkdir(const char *path, Oid tablespaceOid, Oid dbOid)
688688
689689/*
690690 * Get a second position within ptrack map so that it fits
691- * within the samecache line .
691+ * within the samememory page .
692692 */
693- size_t
694- get_slot2 (size_t slot1 ,uint64 hash ) {
695- size_t memory_page_ep ;// ending point of a cache line
696- size_t memory_page_sp ;// starting point of a cache line
697- size_t memory_page_interval ;
698- size_t slot2 ;
699-
700- /* Get the ending point of a memory page within entries[]. */
701- memory_page_ep = (MEMORY_PAGE_ALIGN (offsetof(PtrackMapHdr ,entries )+ slot1 * sizeof (uint32 ))
702- - offsetof(PtrackMapHdr ,entries )) /sizeof (uint32 );
703- /* handling an overflow beyond the entries boundary */
704- memory_page_ep = memory_page_ep > PtrackContentNblocks ?PtrackContentNblocks :memory_page_ep ;
705-
706- /* Get the starting point of a cache line within entries[]. */
707- memory_page_sp = memory_page_ep - ENTRIES_PER_PAGE ;
708-
709- /* Handling overflow below zero (sp then must be larger than ep) */
710- memory_page_sp = memory_page_sp > memory_page_ep ?0 :memory_page_sp ;
711-
712- memory_page_interval = memory_page_ep - memory_page_sp ;
713- slot2 = (size_t )(memory_page_sp + (((hash <<32 ) | (hash >>32 )) %memory_page_interval ));
714- slot2 = (slot1 == slot2 ) ? ((slot1 + 1 ) %memory_page_interval ) :slot2 ;
693+ inline size_t
694+ get_slot2 (size_t slot1 ,uint32 hash ) {
695+ size_t slot2 ;
696+ slot2 = TYPEALIGN_DOWN (ENTRIES_PER_PAGE ,slot1 )+ ((hash <<16 ) | (hash >>16 )) %ENTRIES_PER_PAGE ;
697+ slot2 = slot1 == slot2 ?slot2 + 1 :slot2 ;
715698return slot2 ;
716699}
717700