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

Commitdf955c6

Browse files
author
Daniel Shelepanov
committed
memory page locality
1 parent6a8d748 commitdf955c6

File tree

3 files changed

+44
-7
lines changed

3 files changed

+44
-7
lines changed

‎engine.c

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,35 @@ ptrack_walkdir(const char *path, Oid tablespaceOid, Oid dbOid)
686686
FreeDir(dir);/* we ignore any error here */
687687
}
688688

689+
/*
690+
* Get a second position within ptrack map so that it fits
691+
* within the same cache line.
692+
*/
693+
size_t
694+
get_slot2(size_tslot1,uint64hash) {
695+
size_tcache_line_ep;// ending point of a cache line
696+
size_tcache_line_sp;// starting point of a cache line
697+
size_tcache_line_interval;
698+
size_tslot2;
699+
700+
/* Get the ending point of a cache line within entries[]. */
701+
cache_line_ep= (CACHE_LINE_ALIGN(offsetof(PtrackMapHdr,entries)+slot1*sizeof(XLogRecPtr))
702+
- offsetof(PtrackMapHdr,entries)) /sizeof(XLogRecPtr);
703+
/* handling an overflow beyond the entries boundary */
704+
cache_line_ep=cache_line_ep>PtrackContentNblocks ?PtrackContentNblocks :cache_line_ep;
705+
706+
/* Get the starting point of a cache line within entries[]. */
707+
cache_line_sp=cache_line_ep-ENTRIES_PER_LINE;
708+
709+
/* Handling overflow below zero (sp then must be larger than ep) */
710+
cache_line_sp=cache_line_sp>cache_line_ep ?0 :cache_line_sp;
711+
712+
cache_line_interval=cache_line_ep-cache_line_sp;
713+
slot2= (size_t)(cache_line_sp+ (((hash <<32) | (hash >>32)) %cache_line_interval));
714+
slot2= (slot1==slot2) ? ((slot1+1) %cache_line_interval) :slot2;
715+
returnslot2;
716+
}
717+
689718
/*
690719
* Mark modified block in ptrack_map.
691720
*/
@@ -738,7 +767,6 @@ ptrack_mark_block(RelFileNodeBackend smgr_rnode,
738767
* We use pg_atomic_uint64 here only for alignment purposes, because
739768
* pg_atomic_uint64 is forcedly aligned on 8 bytes during the MSVC build.
740769
*/
741-
pg_atomic_uint32old_lsn;
742770
pg_atomic_uint32old_init_lsn;
743771

744772
if (ptrack_map_size==0
@@ -753,7 +781,7 @@ ptrack_mark_block(RelFileNodeBackend smgr_rnode,
753781

754782
hash=BID_HASH_FUNC(bid);
755783
slot1= (size_t)(hash %PtrackContentNblocks);
756-
slot2=(size_t)(((hash <<32) | (hash >>32)) %PtrackContentNblocks);
784+
slot2=get_slot2(slot1,hash);
757785

758786
bid.blocknum=InvalidBlockNumber;
759787
hash=BID_HASH_FUNC(bid);
@@ -807,8 +835,8 @@ XLogRecPtr ptrack_read_file_maxlsn(RelFileNode rnode, ForkNumber forknum)
807835
if (slot2<slot1)
808836
swap_slots(&slot1,&slot2);
809837

810-
update_lsn1=pg_atomic_read_u64(&ptrack_map->entries[slot1]);
811-
update_lsn2=pg_atomic_read_u64(&ptrack_map->entries[slot2]);
838+
update_lsn1=pg_atomic_read_u32(&ptrack_map->entries[slot1]);
839+
update_lsn2=pg_atomic_read_u32(&ptrack_map->entries[slot2]);
812840

813841
returnupdate_lsn1==update_lsn2 ?update_lsn1 :InvalidXLogRecPtr;
814842
}

‎engine.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@
4040
*/
4141
#definePTRACK_BUF_SIZE ((uint64) 8000)
4242

43+
/*
44+
* A reasonable assumption for most systems. Postgres core
45+
* leverages the same value for this purpose.
46+
*/
47+
#defineCACHE_LINE_SIZE64
48+
#defineCACHE_LINE_ALIGN(LEN)TYPEALIGN(CACHE_LINE_SIZE, (LEN))
49+
#defineENTRIES_PER_LINE(CACHE_LINE_SIZE/sizeof(XLogRecPtr))
50+
4351
/* Ptrack magic bytes */
4452
#definePTRACK_MAGIC "ptk"
4553
#definePTRACK_MAGIC_SIZE 4
@@ -122,6 +130,7 @@ extern XLogRecPtr ptrack_read_file_maxlsn(RelFileNode smgr_rnode,
122130
ForkNumberforknum);
123131

124132
externboolis_cfm_file_path(constchar*path);
133+
externsize_tget_slot2(size_tslot1,uint64hash);
125134
#ifdefPGPRO_EE
126135
externoff_tget_cfs_relation_file_decompressed_size(RelFileNodeBackendrnode,
127136
constchar*fullpath,ForkNumberforknum);

‎ptrack.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,8 @@ ptrack_filelist_getnext(PtScanCtx * ctx)
467467
if (maxlsn<ctx->lsn)
468468
{
469469
elog(DEBUG3,"ptrack: skip file %s: maxlsn is %X/%X, expected %X/%X",
470-
fullpath, (uint32) (maxlsn >>32), (uint32)maxlsn,
471-
(uint32) (ctx->lsn >>32), (uint32)ctx->lsn);
470+
fullpath, (uint16) (maxlsn >>16), (uint16)maxlsn,
471+
(uint16) (ctx->lsn >>16), (uint16)ctx->lsn);
472472

473473
/* Try the next one */
474474
gotoget_next;
@@ -671,7 +671,7 @@ ptrack_get_pagemapset(PG_FUNCTION_ARGS)
671671
/* Only probe the second slot if the first one is marked */
672672
if (within_ptrack_map&&lsn_diff(ctx->lsn,update_lsn1) <=0)
673673
{
674-
slot2=(size_t)(((hash <<32) | (hash >>32)) %PtrackContentNblocks);
674+
slot2=get_slot2(slot1,hash);
675675
update_lsn2=pg_atomic_read_u32(&ptrack_map->entries[slot2]);
676676

677677
if (update_lsn2!=InvalidXLogRecPtr)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp