diff options
author | Bruce Momjian <bruce@momjian.us> | 2006-06-15 19:15:00 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2006-06-15 19:15:00 +0000 |
commit | 94a5c4a01b1ec699419b7c663bf4cd0cb3e6ac96 (patch) | |
tree | 36aa0245e262cae3decb254223129523e8230f5e /src/backend | |
parent | a584c12426ae07d6d765c0c321ced5726e497044 (diff) | |
download | postgresql-94a5c4a01b1ec699419b7c663bf4cd0cb3e6ac96.tar.gz |
Use posix_fadvise() to avoid kernel caching of WAL contents on WAL file
close.
ITAGAKI Takahiro
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/access/transam/xlog.c | 58 |
1 files changed, 33 insertions, 25 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index ad6767e92f..49e71aa12a 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.237 2006/04/20 04:07:38 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.238 2006/06/15 19:15:00 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -478,6 +478,7 @@ static bool InstallXLogFileSegment(uint32 *log, uint32 *seg, char *tmppath, bool use_lock); static int XLogFileOpen(uint32 log, uint32 seg); static int XLogFileRead(uint32 log, uint32 seg, int emode); +static void XLogFileClose(void); static bool RestoreArchivedFile(char *path, const char *xlogfname, const char *recovername, off_t expectedSize); static int PreallocXlogFiles(XLogRecPtr endptr); @@ -1384,14 +1385,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible) */ Assert(npages == 0); if (openLogFile >= 0) - { - if (close(openLogFile)) - ereport(PANIC, - (errcode_for_file_access(), - errmsg("could not close log file %u, segment %u: %m", - openLogId, openLogSeg))); - openLogFile = -1; - } + XLogFileClose(); XLByteToPrevSeg(LogwrtResult.Write, openLogId, openLogSeg); /* create/use new log file */ @@ -1567,14 +1561,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible) { if (openLogFile >= 0 && !XLByteInPrevSeg(LogwrtResult.Write, openLogId, openLogSeg)) - { - if (close(openLogFile)) - ereport(PANIC, - (errcode_for_file_access(), - errmsg("could not close log file %u, segment %u: %m", - openLogId, openLogSeg))); - openLogFile = -1; - } + XLogFileClose(); if (openLogFile < 0) { XLByteToPrevSeg(LogwrtResult.Write, openLogId, openLogSeg); @@ -2153,6 +2140,34 @@ XLogFileRead(uint32 log, uint32 seg, int emode) } /* + * Close the current logfile segment for writing. + */ +static void +XLogFileClose(void) +{ + Assert(openLogFile >= 0); + +#ifdef _POSIX_ADVISORY_INFO + /* + * WAL caches will not be accessed in the future, so we advise OS to + * free them. But we will not do so if WAL archiving is active, + * because archivers might use the caches to read the WAL segment. + * While O_DIRECT works for O_SYNC, posix_fadvise() works for fsync() + * and O_SYNC, and some platforms only have posix_fadvise(). + */ + if (!XLogArchivingActive()) + posix_fadvise(openLogFile, 0, 0, POSIX_FADV_DONTNEED); +#endif + + if (close(openLogFile)) + ereport(PANIC, + (errcode_for_file_access(), + errmsg("could not close log file %u, segment %u: %m", + openLogId, openLogSeg))); + openLogFile = -1; +} + +/* * Attempt to retrieve the specified file from off-line archival storage. * If successful, fill "path" with its complete path (note that this will be * a temp file name that doesn't follow the normal naming convention), and @@ -5609,14 +5624,7 @@ assign_xlog_sync_method(const char *method, bool doit, GucSource source) errmsg("could not fsync log file %u, segment %u: %m", openLogId, openLogSeg))); if (open_sync_bit != new_sync_bit) - { - if (close(openLogFile)) - ereport(PANIC, - (errcode_for_file_access(), - errmsg("could not close log file %u, segment %u: %m", - openLogId, openLogSeg))); - openLogFile = -1; - } + XLogFileClose(); } sync_method = new_sync_method; open_sync_bit = new_sync_bit; |