Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit79e3bda

Browse files
author
Daniel Shelepanov
committed
intermediate
1 parent33a3f33 commit79e3bda

File tree

2 files changed

+17
-31
lines changed

2 files changed

+17
-31
lines changed

‎engine.c

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,9 @@ ptrackCheckpoint(void)
449449
uint32lsn;
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

556556
elog(DEBUG1,"assign_ptrack_map_size: ptrack_map_size set to "UINT64_FORMAT,
557557
ptrack_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_tslot1,uint64hash) {
695-
size_tmemory_page_ep;// ending point of a cache line
696-
size_tmemory_page_sp;// starting point of a cache line
697-
size_tmemory_page_interval;
698-
size_tslot2;
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+
inlinesize_t
694+
get_slot2(size_tslot1,uint32hash) {
695+
size_tslot2;
696+
slot2=TYPEALIGN_DOWN(ENTRIES_PER_PAGE,slot1)+ ((hash <<16) | (hash >>16)) %ENTRIES_PER_PAGE;
697+
slot2=slot1==slot2 ?slot2+1 :slot2;
715698
returnslot2;
716699
}
717700

‎engine.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@
4444
* A reasonable assumption for most systems. Postgres core
4545
* leverages the same value for this purpose.
4646
*/
47-
#defineMEMORY_PAGE_SIZE4096
48-
#defineMEMORY_PAGE_ALIGN(LEN)TYPEALIGN(MEMORY_PAGE_SIZE, (LEN))
49-
#defineENTRIES_PER_PAGE(MEMORY_PAGE_SIZE/sizeof(XLogRecPtr))
47+
#defineMEMORY_PAGE_SIZE4096
48+
#defineMEMORY_PAGE_ALIGN(LEN)TYPEALIGN(MEMORY_PAGE_SIZE, (LEN))
49+
#defineMEMORY_PAGE_ALIGN_DOWN(LEN)TYPEALIGN_DOWN(MEMORY_PAGE_SIZE, (LEN))
50+
#defineENTRIES_PER_PAGE(MEMORY_PAGE_SIZE/sizeof(uint32))
5051

5152
/* Ptrack magic bytes */
5253
#definePTRACK_MAGIC "ptk"
@@ -73,6 +74,8 @@ typedef struct PtrackMapHdr
7374
*/
7475
uint32version_num;
7576

77+
/* Padding needed to align entries[] by the page boundary */
78+
charpadding[4096-PTRACK_MAGIC_SIZE-sizeof(uint32)-2*sizeof(pg_atomic_uint32)];
7679
/* LSN of current writing position */
7780
pg_atomic_uint32latest_lsn;
7881
/* LSN of the moment, when map was last enabled. */
@@ -130,7 +133,7 @@ extern XLogRecPtr ptrack_read_file_maxlsn(RelFileNode smgr_rnode,
130133
ForkNumberforknum);
131134

132135
externboolis_cfm_file_path(constchar*path);
133-
externsize_tget_slot2(size_tslot1,uint64hash);
136+
externsize_tget_slot2(size_tslot1,uint32hash);
134137
#ifdefPGPRO_EE
135138
externoff_tget_cfs_relation_file_decompressed_size(RelFileNodeBackendrnode,
136139
constchar*fullpath,ForkNumberforknum);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp