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

Commit7e26e02

Browse files
committed
Prefetch blocks during lazy vacuum's truncation scan
Vacuum truncation scan can be sped up on rotating media by prefetchingblocks in forward direction. That makes the blocks already present inmemory by the time they are needed, while also letting OS read-aheadkick in.The truncate scan has been measured to be five times faster than withoutthis patch (that was on a slow disk, but it shouldn't hurt on fastdisks.)Author: Álvaro Herrera, loosely based on a submission by Claudio FreireDiscussion:https://postgr.es/m/CAGTBQpa6NFGO_6g_y_7zQx8L9GcHDSQKYdo1tGuh791z6PYgEg@mail.gmail.com
1 parent3c82146 commit7e26e02

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

‎src/backend/commands/vacuumlazy.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@
9898
*/
9999
#defineSKIP_PAGES_THRESHOLD((BlockNumber) 32)
100100

101+
/*
102+
* Size of the prefetch window for lazy vacuum backwards truncation scan.
103+
* Needs to be a power of 2.
104+
*/
105+
#definePREFETCH_SIZE((BlockNumber) 32)
106+
101107
typedefstructLVRelStats
102108
{
103109
/* hasindex = true means two-pass strategy; false means one-pass */
@@ -1826,13 +1832,22 @@ static BlockNumber
18261832
count_nondeletable_pages(Relationonerel,LVRelStats*vacrelstats)
18271833
{
18281834
BlockNumberblkno;
1835+
BlockNumberprefetchedUntil;
18291836
instr_timestarttime;
18301837

18311838
/* Initialize the starttime if we check for conflicting lock requests */
18321839
INSTR_TIME_SET_CURRENT(starttime);
18331840

1834-
/* Strange coding of loop control is needed because blkno is unsigned */
1841+
/*
1842+
* Start checking blocks at what we believe relation end to be and move
1843+
* backwards. (Strange coding of loop control is needed because blkno is
1844+
* unsigned.) To make the scan faster, we prefetch a few blocks at a time
1845+
* in forward direction, so that OS-level readahead can kick in.
1846+
*/
18351847
blkno=vacrelstats->rel_pages;
1848+
StaticAssertStmt((PREFETCH_SIZE& (PREFETCH_SIZE-1))==0,
1849+
"prefetch size must be power of 2");
1850+
prefetchedUntil=InvalidBlockNumber;
18361851
while (blkno>vacrelstats->nonempty_pages)
18371852
{
18381853
Bufferbuf;
@@ -1882,6 +1897,21 @@ count_nondeletable_pages(Relation onerel, LVRelStats *vacrelstats)
18821897

18831898
blkno--;
18841899

1900+
/* If we haven't prefetched this lot yet, do so now. */
1901+
if (prefetchedUntil>blkno)
1902+
{
1903+
BlockNumberprefetchStart;
1904+
BlockNumberpblkno;
1905+
1906+
prefetchStart=blkno& ~(PREFETCH_SIZE-1);
1907+
for (pblkno=prefetchStart;pblkno <=blkno;pblkno++)
1908+
{
1909+
PrefetchBuffer(onerel,MAIN_FORKNUM,pblkno);
1910+
CHECK_FOR_INTERRUPTS();
1911+
}
1912+
prefetchedUntil=prefetchStart;
1913+
}
1914+
18851915
buf=ReadBufferExtended(onerel,MAIN_FORKNUM,blkno,
18861916
RBM_NORMAL,vac_strategy);
18871917

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp