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

Commit94a5c4a

Browse files
committed
Use posix_fadvise() to avoid kernel caching of WAL contents on WAL file
close.ITAGAKI Takahiro
1 parenta584c12 commit94a5c4a

File tree

1 file changed

+33
-25
lines changed
  • src/backend/access/transam

1 file changed

+33
-25
lines changed

‎src/backend/access/transam/xlog.c

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.237 2006/04/20 04:07:38 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.238 2006/06/15 19:15:00 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -478,6 +478,7 @@ static bool InstallXLogFileSegment(uint32 *log, uint32 *seg, char *tmppath,
478478
booluse_lock);
479479
staticintXLogFileOpen(uint32log,uint32seg);
480480
staticintXLogFileRead(uint32log,uint32seg,intemode);
481+
staticvoidXLogFileClose(void);
481482
staticboolRestoreArchivedFile(char*path,constchar*xlogfname,
482483
constchar*recovername,off_texpectedSize);
483484
staticintPreallocXlogFiles(XLogRecPtrendptr);
@@ -1384,14 +1385,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
13841385
*/
13851386
Assert(npages==0);
13861387
if (openLogFile >=0)
1387-
{
1388-
if (close(openLogFile))
1389-
ereport(PANIC,
1390-
(errcode_for_file_access(),
1391-
errmsg("could not close log file %u, segment %u: %m",
1392-
openLogId,openLogSeg)));
1393-
openLogFile=-1;
1394-
}
1388+
XLogFileClose();
13951389
XLByteToPrevSeg(LogwrtResult.Write,openLogId,openLogSeg);
13961390

13971391
/* create/use new log file */
@@ -1567,14 +1561,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
15671561
{
15681562
if (openLogFile >=0&&
15691563
!XLByteInPrevSeg(LogwrtResult.Write,openLogId,openLogSeg))
1570-
{
1571-
if (close(openLogFile))
1572-
ereport(PANIC,
1573-
(errcode_for_file_access(),
1574-
errmsg("could not close log file %u, segment %u: %m",
1575-
openLogId,openLogSeg)));
1576-
openLogFile=-1;
1577-
}
1564+
XLogFileClose();
15781565
if (openLogFile<0)
15791566
{
15801567
XLByteToPrevSeg(LogwrtResult.Write,openLogId,openLogSeg);
@@ -2152,6 +2139,34 @@ XLogFileRead(uint32 log, uint32 seg, int emode)
21522139
return-1;
21532140
}
21542141

2142+
/*
2143+
* Close the current logfile segment for writing.
2144+
*/
2145+
staticvoid
2146+
XLogFileClose(void)
2147+
{
2148+
Assert(openLogFile >=0);
2149+
2150+
#ifdef_POSIX_ADVISORY_INFO
2151+
/*
2152+
* WAL caches will not be accessed in the future, so we advise OS to
2153+
* free them. But we will not do so if WAL archiving is active,
2154+
* because archivers might use the caches to read the WAL segment.
2155+
* While O_DIRECT works for O_SYNC, posix_fadvise() works for fsync()
2156+
* and O_SYNC, and some platforms only have posix_fadvise().
2157+
*/
2158+
if (!XLogArchivingActive())
2159+
posix_fadvise(openLogFile,0,0,POSIX_FADV_DONTNEED);
2160+
#endif
2161+
2162+
if (close(openLogFile))
2163+
ereport(PANIC,
2164+
(errcode_for_file_access(),
2165+
errmsg("could not close log file %u, segment %u: %m",
2166+
openLogId,openLogSeg)));
2167+
openLogFile=-1;
2168+
}
2169+
21552170
/*
21562171
* Attempt to retrieve the specified file from off-line archival storage.
21572172
* If successful, fill "path" with its complete path (note that this will be
@@ -5609,14 +5624,7 @@ assign_xlog_sync_method(const char *method, bool doit, GucSource source)
56095624
errmsg("could not fsync log file %u, segment %u: %m",
56105625
openLogId,openLogSeg)));
56115626
if (open_sync_bit!=new_sync_bit)
5612-
{
5613-
if (close(openLogFile))
5614-
ereport(PANIC,
5615-
(errcode_for_file_access(),
5616-
errmsg("could not close log file %u, segment %u: %m",
5617-
openLogId,openLogSeg)));
5618-
openLogFile=-1;
5619-
}
5627+
XLogFileClose();
56205628
}
56215629
sync_method=new_sync_method;
56225630
open_sync_bit=new_sync_bit;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp