From 111d5892f076cc0504e9ec2866ac5297de1862df Mon Sep 17 00:00:00 2001 From: Takashi Menjo Date: Mon, 16 Mar 2020 11:14:03 +0900 Subject: [PATCH v2 4/5] Speculative-map WAL segments --- src/backend/access/transam/xlog.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index ff7d0b69bd..382256369d 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -993,6 +993,8 @@ XLogInsertRecord(XLogRecData *rdata, info == XLOG_SWITCH); XLogRecPtr StartPos; XLogRecPtr EndPos; + XLogRecPtr ProbablyInsertPos; + XLogSegNo ProbablyInsertSegNo; bool prevDoPageWrites = doPageWrites; /* we assume that all of the record header is in the first chunk */ @@ -1002,6 +1004,23 @@ XLogInsertRecord(XLogRecData *rdata, if (!XLogInsertAllowed()) elog(ERROR, "cannot make new WAL entries during recovery"); + /* Speculatively map a segment we probably need */ + ProbablyInsertPos = GetInsertRecPtr(); + XLByteToSeg(ProbablyInsertPos, ProbablyInsertSegNo, wal_segment_size); + if (ProbablyInsertSegNo != openLogSegNo) + { + if (mappedPages != NULL) + { + Assert(beingUnmappedPages == NULL); + Assert(beingClosedLogSegNo == 0); + beingUnmappedPages = mappedPages; + beingClosedLogSegNo = openLogSegNo; + } + mappedPages = XLogFileMap(ProbablyInsertSegNo, &pmemMapped); + Assert(mappedPages != NULL); + openLogSegNo = ProbablyInsertSegNo; + } + /*---------- * * We have now done all the preparatory work we can without holding a -- 2.17.1