@@ -258,7 +258,7 @@ ptrackMapReadFromFile(const char *ptrack_path)
258
258
* postmaster is the only user right now.
259
259
*/
260
260
elog (DEBUG1 , "ptrack read map: crc %u, file_crc %u, init_lsn %X/%X" ,
261
- crc , * file_crc , (uint32 ) (ptrack_map -> init_lsn .value >> 32 ), (uint32 ) ptrack_map -> init_lsn .value );
261
+ crc , * file_crc , (uint16 ) (ptrack_map -> init_lsn .value >> 16 ), (uint16 ) ptrack_map -> init_lsn .value );
262
262
263
263
if (!EQ_CRC32C (* file_crc , crc ))
264
264
{
@@ -330,7 +330,7 @@ ptrackMapInit(void)
330
330
* Fill entries with InvalidXLogRecPtr
331
331
* (InvalidXLogRecPtr is actually 0)
332
332
*/
333
- memset (ptrack_map -> entries , 0 , PtrackContentNblocks * sizeof (pg_atomic_uint64 ));
333
+ memset (ptrack_map -> entries , 0 , PtrackContentNblocks * sizeof (pg_atomic_uint32 ));
334
334
/*
335
335
* Last part of memory representation of ptrack_map (crc) is actually unused
336
336
* so leave it as it is
@@ -348,8 +348,8 @@ ptrackCheckpoint(void)
348
348
pg_crc32c crc ;
349
349
char ptrack_path [MAXPGPATH ];
350
350
char ptrack_path_tmp [MAXPGPATH ];
351
- XLogRecPtr init_lsn ;
352
- pg_atomic_uint64 buf [PTRACK_BUF_SIZE ];
351
+ uint32 init_lsn ;
352
+ pg_atomic_uint32 buf [PTRACK_BUF_SIZE ];
353
353
struct stat stat_buf ;
354
354
uint64 i = 0 ;
355
355
uint64 j = 0 ;
@@ -408,20 +408,23 @@ ptrackCheckpoint(void)
408
408
ptrack_write_chunk (ptrack_tmp_fd , & crc , (char * ) ptrack_map ,
409
409
offsetof(PtrackMapHdr , init_lsn ));
410
410
411
- init_lsn = pg_atomic_read_u64 (& ptrack_map -> init_lsn );
411
+ init_lsn = pg_atomic_read_u32 (& ptrack_map -> init_lsn );
412
412
413
413
/* Set init_lsn during checkpoint if it is not set yet */
414
414
if (init_lsn == InvalidXLogRecPtr )
415
415
{
416
416
XLogRecPtr new_init_lsn ;
417
+ uint32 new_init_lsn32 ;
417
418
418
419
if (RecoveryInProgress ())
419
420
new_init_lsn = GetXLogReplayRecPtr (NULL );
420
421
else
421
422
new_init_lsn = GetXLogInsertRecPtr ();
422
423
423
- pg_atomic_write_u64 (& ptrack_map -> init_lsn , new_init_lsn );
424
- init_lsn = new_init_lsn ;
424
+ new_init_lsn32 = (uint32 )(new_init_lsn >> 16 );
425
+
426
+ pg_atomic_write_u32 (& ptrack_map -> init_lsn , new_init_lsn32 );
427
+ init_lsn = new_init_lsn32 ;
425
428
}
426
429
427
430
/* Put init_lsn in the same buffer */
@@ -435,7 +438,7 @@ ptrackCheckpoint(void)
435
438
*/
436
439
while (i < PtrackContentNblocks )
437
440
{
438
- XLogRecPtr lsn ;
441
+ uint32 lsn ;
439
442
440
443
/*
441
444
* We store LSN values as pg_atomic_uint64 in the ptrack map, but
@@ -445,7 +448,7 @@ ptrackCheckpoint(void)
445
448
*
446
449
* TODO: is it safe and can we do any better?
447
450
*/
448
- lsn = pg_atomic_read_u64 (& ptrack_map -> entries [i ]);
451
+ lsn = pg_atomic_read_u32 (& ptrack_map -> entries [i ]);
449
452
buf [j ].value = lsn ;
450
453
451
454
i ++ ;
@@ -472,7 +475,7 @@ ptrackCheckpoint(void)
472
475
/* Write if anything left */
473
476
if ((i + 1 ) % PTRACK_BUF_SIZE != 0 )
474
477
{
475
- size_t writesz = sizeof (pg_atomic_uint64 ) * j ;
478
+ size_t writesz = sizeof (pg_atomic_uint32 ) * j ;
476
479
477
480
ptrack_write_chunk (ptrack_tmp_fd , & crc , (char * ) buf , writesz );
478
481
elog (DEBUG5 , "ptrack checkpoint: final i " UINT64_FORMAT ", j " UINT64_FORMAT ", writesz %zu PtrackContentNblocks " UINT64_FORMAT ,
@@ -684,12 +687,13 @@ ptrack_mark_block(RelFileNodeBackend smgr_rnode,
684
687
size_t slot1 ;
685
688
size_t slot2 ;
686
689
XLogRecPtr new_lsn ;
690
+ uint32 new_lsn32 ;
687
691
/*
688
692
* We use pg_atomic_uint64 here only for alignment purposes, because
689
693
* pg_atomic_uint64 is forcedly aligned on 8 bytes during the MSVC build.
690
694
*/
691
- pg_atomic_uint64 old_lsn ;
692
- pg_atomic_uint64 old_init_lsn ;
695
+ pg_atomic_uint32 old_lsn ;
696
+ pg_atomic_uint32 old_init_lsn ;
693
697
694
698
if (ptrack_map_size == 0
695
699
|| ptrack_map == NULL
@@ -710,25 +714,27 @@ ptrack_mark_block(RelFileNodeBackend smgr_rnode,
710
714
else
711
715
new_lsn = GetXLogInsertRecPtr ();
712
716
717
+ new_lsn32 = (uint32 )(new_lsn >> 16 );
718
+
713
719
/* Atomically assign new init LSN value */
714
- old_init_lsn .value = pg_atomic_read_u64 (& ptrack_map -> init_lsn );
720
+ old_init_lsn .value = pg_atomic_read_u32 (& ptrack_map -> init_lsn );
715
721
if (old_init_lsn .value == InvalidXLogRecPtr )
716
722
{
717
- elog (DEBUG1 , "ptrack_mark_block: init_lsn " UINT64_FORMAT " <- " UINT64_FORMAT , old_init_lsn .value , new_lsn );
723
+ elog (DEBUG1 , "ptrack_mark_block: init_lsn %u <- %u" , old_init_lsn .value , new_lsn32 );
718
724
719
- while (old_init_lsn .value < new_lsn &&
720
- !pg_atomic_compare_exchange_u64 (& ptrack_map -> init_lsn , (uint64 * ) & old_init_lsn .value , new_lsn ));
725
+ while (old_init_lsn .value < new_lsn32 &&
726
+ !pg_atomic_compare_exchange_u32 (& ptrack_map -> init_lsn , (uint32 * ) & old_init_lsn .value , new_lsn32 ));
721
727
}
722
728
723
729
/* Atomically assign new LSN value to the first slot */
724
- old_lsn .value = pg_atomic_read_u64 (& ptrack_map -> entries [slot1 ]);
725
- elog (DEBUG3 , "ptrack_mark_block: map[%zu]=" UINT64_FORMAT " <- " UINT64_FORMAT , slot1 , old_lsn .value , new_lsn );
726
- while (old_lsn .value < new_lsn &&
727
- !pg_atomic_compare_exchange_u64 (& ptrack_map -> entries [slot1 ], (uint64 * ) & old_lsn .value , new_lsn ));
730
+ old_lsn .value = pg_atomic_read_u32 (& ptrack_map -> entries [slot1 ]);
731
+ elog (DEBUG3 , "ptrack_mark_block: map[%zu]=%u <- %u" , slot1 , old_lsn .value , new_lsn32 );
732
+ while (old_lsn .value < new_lsn32 &&
733
+ !pg_atomic_compare_exchange_u32 (& ptrack_map -> entries [slot1 ], (uint32 * ) & old_lsn .value , new_lsn32 ));
728
734
729
735
/* And to the second */
730
- old_lsn .value = pg_atomic_read_u64 (& ptrack_map -> entries [slot2 ]);
731
- elog (DEBUG3 , "ptrack_mark_block: map[%zu]=" UINT64_FORMAT " <- " UINT64_FORMAT , slot2 , old_lsn .value , new_lsn );
732
- while (old_lsn .value < new_lsn &&
733
- !pg_atomic_compare_exchange_u64 (& ptrack_map -> entries [slot2 ], (uint64 * ) & old_lsn .value , new_lsn ));
736
+ old_lsn .value = pg_atomic_read_u32 (& ptrack_map -> entries [slot2 ]);
737
+ elog (DEBUG3 , "ptrack_mark_block: map[%zu]=%u <- %u" , slot2 , old_lsn .value , new_lsn32 );
738
+ while (old_lsn .value < new_lsn32 &&
739
+ !pg_atomic_compare_exchange_u32 (& ptrack_map -> entries [slot2 ], (uint32 * ) & old_lsn .value , new_lsn32 ));
734
740
}
0 commit comments