Skip to content

Commit 5cf4f31

Browse files
Jakub Wartakreshke
authored andcommitted
Use fadvise to prefetch WAL in xlogrecovery
1 parent 45f6f07 commit 5cf4f31

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/backend/access/transam/xlogrecovery.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3344,6 +3344,18 @@ XLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, int reqLen,
33443344
Assert(targetPageOff == readOff);
33453345
Assert(reqLen <= readLen);
33463346

3347+
#if defined(USE_POSIX_FADVISE) && defined(POSIX_FADV_WILLNEED)
3348+
/*
3349+
* Prefetch next wal blocks to avoid page misses on next read iterations.
3350+
*/
3351+
#define RACHUNK (128*1024)
3352+
if (readOff % RACHUNK == 0) {
3353+
pgstat_report_wait_start(WAIT_EVENT_WAL_PREFETCH);
3354+
posix_fadvise(readFile, readOff + RACHUNK, RACHUNK, POSIX_FADV_WILLNEED);
3355+
pgstat_report_wait_end();
3356+
}
3357+
#endif
3358+
33473359
xlogreader->seg.ws_tli = curFileTLI;
33483360

33493361
/*

src/backend/utils/activity/wait_event.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,9 @@ pgstat_get_wait_io(WaitEventIO w)
747747
case WAIT_EVENT_WAL_READ:
748748
event_name = "WALRead";
749749
break;
750+
case WAIT_EVENT_WAL_PREFETCH:
751+
event_name = "WALPrefetch";
752+
break;
750753
case WAIT_EVENT_WAL_SYNC:
751754
event_name = "WALSync";
752755
break;

src/include/utils/wait_event.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ typedef enum
232232
WAIT_EVENT_WAL_INIT_SYNC,
233233
WAIT_EVENT_WAL_INIT_WRITE,
234234
WAIT_EVENT_WAL_READ,
235+
WAIT_EVENT_WAL_PREFETCH,
235236
WAIT_EVENT_WAL_SYNC,
236237
WAIT_EVENT_WAL_SYNC_METHOD_ASSIGN,
237238
WAIT_EVENT_WAL_WRITE

0 commit comments

Comments
 (0)