From 990c33ec45c5b8080f89414102ddd8a725f206c3 Mon Sep 17 00:00:00 2001 From: Takashi Menjo Date: Mon, 16 Mar 2020 11:14:03 +0900 Subject: [PATCH v3 05/10] 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 7d9d2dc06a..825de800b7 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -1029,6 +1029,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 */ @@ -1038,6 +1040,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.25.1