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

Commitb485ad7

Browse files
committed
Provide multi-block smgrprefetch().
Previously smgrprefetch() could issue POSIX_FADV_WILLNEED advice for asingle block at a time. Add an nblocks argument so that we can do thesame for a range of blocks. This usually produces a single system call,but might need to loop if it crosses a segment boundary. Initially itis only called with nblocks == 1, but proposed patches will make widercalls.Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi> (earlier version)Discussion:https://postgr.es/m/CA+hUKGJkOiOCa+mag4BF+zHo7qo=o9CFheB8=g6uT5TUm2gkvA@mail.gmail.com
1 parent59bd34c commitb485ad7

File tree

6 files changed

+35
-17
lines changed

6 files changed

+35
-17
lines changed

‎src/backend/storage/buffer/bufmgr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ PrefetchSharedBuffer(SMgrRelation smgr_reln,
569569
* recovery if the relation file doesn't exist.
570570
*/
571571
if ((io_direct_flags&IO_DIRECT_DATA)==0&&
572-
smgrprefetch(smgr_reln,forkNum,blockNum))
572+
smgrprefetch(smgr_reln,forkNum,blockNum,1))
573573
{
574574
result.initiated_io= true;
575575
}

‎src/backend/storage/buffer/localbuf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ PrefetchLocalBuffer(SMgrRelation smgr, ForkNumber forkNum,
9494
#ifdefUSE_PREFETCH
9595
/* Not in buffers, so initiate prefetch */
9696
if ((io_direct_flags&IO_DIRECT_DATA)==0&&
97-
smgrprefetch(smgr,forkNum,blockNum))
97+
smgrprefetch(smgr,forkNum,blockNum,1))
9898
{
9999
result.initiated_io= true;
100100
}

‎src/backend/storage/smgr/md.c

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -710,27 +710,44 @@ mdclose(SMgrRelation reln, ForkNumber forknum)
710710
}
711711

712712
/*
713-
* mdprefetch() -- Initiate asynchronous read of the specifiedblock of a relation
713+
* mdprefetch() -- Initiate asynchronous read of the specifiedblocks of a relation
714714
*/
715715
bool
716-
mdprefetch(SMgrRelationreln,ForkNumberforknum,BlockNumberblocknum)
716+
mdprefetch(SMgrRelationreln,ForkNumberforknum,BlockNumberblocknum,
717+
intnblocks)
717718
{
718719
#ifdefUSE_PREFETCH
719-
off_tseekpos;
720-
MdfdVec*v;
721720

722721
Assert((io_direct_flags&IO_DIRECT_DATA)==0);
723722

724-
v=_mdfd_getseg(reln,forknum,blocknum, false,
725-
InRecovery ?EXTENSION_RETURN_NULL :EXTENSION_FAIL);
726-
if (v==NULL)
723+
if ((uint64)blocknum+nblocks> (uint64)MaxBlockNumber+1)
727724
return false;
728725

729-
seekpos= (off_t)BLCKSZ* (blocknum % ((BlockNumber)RELSEG_SIZE));
726+
while (nblocks>0)
727+
{
728+
off_tseekpos;
729+
MdfdVec*v;
730+
intnblocks_this_segment;
730731

731-
Assert(seekpos< (off_t)BLCKSZ*RELSEG_SIZE);
732+
v=_mdfd_getseg(reln,forknum,blocknum, false,
733+
InRecovery ?EXTENSION_RETURN_NULL :EXTENSION_FAIL);
734+
if (v==NULL)
735+
return false;
736+
737+
seekpos= (off_t)BLCKSZ* (blocknum % ((BlockNumber)RELSEG_SIZE));
732738

733-
(void)FilePrefetch(v->mdfd_vfd,seekpos,BLCKSZ,WAIT_EVENT_DATA_FILE_PREFETCH);
739+
Assert(seekpos< (off_t)BLCKSZ*RELSEG_SIZE);
740+
741+
nblocks_this_segment=
742+
Min(nblocks,
743+
RELSEG_SIZE- (blocknum % ((BlockNumber)RELSEG_SIZE)));
744+
745+
(void)FilePrefetch(v->mdfd_vfd,seekpos,BLCKSZ*nblocks_this_segment,
746+
WAIT_EVENT_DATA_FILE_PREFETCH);
747+
748+
blocknum+=nblocks_this_segment;
749+
nblocks-=nblocks_this_segment;
750+
}
734751
#endif/* USE_PREFETCH */
735752

736753
return true;

‎src/backend/storage/smgr/smgr.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ typedef struct f_smgr
5454
void(*smgr_zeroextend) (SMgrRelationreln,ForkNumberforknum,
5555
BlockNumberblocknum,intnblocks,boolskipFsync);
5656
bool(*smgr_prefetch) (SMgrRelationreln,ForkNumberforknum,
57-
BlockNumberblocknum);
57+
BlockNumberblocknum,intnblocks);
5858
void(*smgr_read) (SMgrRelationreln,ForkNumberforknum,
5959
BlockNumberblocknum,void*buffer);
6060
void(*smgr_write) (SMgrRelationreln,ForkNumberforknum,
@@ -547,9 +547,10 @@ smgrzeroextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
547547
* record).
548548
*/
549549
bool
550-
smgrprefetch(SMgrRelationreln,ForkNumberforknum,BlockNumberblocknum)
550+
smgrprefetch(SMgrRelationreln,ForkNumberforknum,BlockNumberblocknum,
551+
intnblocks)
551552
{
552-
returnsmgrsw[reln->smgr_which].smgr_prefetch(reln,forknum,blocknum);
553+
returnsmgrsw[reln->smgr_which].smgr_prefetch(reln,forknum,blocknum,nblocks);
553554
}
554555

555556
/*

‎src/include/storage/md.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extern void mdextend(SMgrRelation reln, ForkNumber forknum,
3131
externvoidmdzeroextend(SMgrRelationreln,ForkNumberforknum,
3232
BlockNumberblocknum,intnblocks,boolskipFsync);
3333
externboolmdprefetch(SMgrRelationreln,ForkNumberforknum,
34-
BlockNumberblocknum);
34+
BlockNumberblocknum,intnblocks);
3535
externvoidmdread(SMgrRelationreln,ForkNumberforknum,BlockNumberblocknum,
3636
void*buffer);
3737
externvoidmdwrite(SMgrRelationreln,ForkNumberforknum,

‎src/include/storage/smgr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ extern void smgrextend(SMgrRelation reln, ForkNumber forknum,
9595
externvoidsmgrzeroextend(SMgrRelationreln,ForkNumberforknum,
9696
BlockNumberblocknum,intnblocks,boolskipFsync);
9797
externboolsmgrprefetch(SMgrRelationreln,ForkNumberforknum,
98-
BlockNumberblocknum);
98+
BlockNumberblocknum,intnblocks);
9999
externvoidsmgrread(SMgrRelationreln,ForkNumberforknum,
100100
BlockNumberblocknum,void*buffer);
101101
externvoidsmgrwrite(SMgrRelationreln,ForkNumberforknum,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp