Free WAL caches on switching segments - Mailing list pgsql-patches

From ITAGAKI Takahiro
Subject Free WAL caches on switching segments
Date
Msg-id 20050830151029.4A59.ITAGAKI.TAKAHIRO@lab.ntt.co.jp
Whole thread Raw
Responses Re: Free WAL caches on switching segments  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-patches
Hi,

Here is a small patch to prevent undesired WAL file caching by kernel.
posix_fadvise(POSIX_FADV_DONTNEED) attempts to free cached pages and
the kernel will discard them in preference to other data caches.

I think it works just like as O_DIRECT in terms of cache control.
O_DIRECT may be a better solution than posix_fadvise, but
posix_fadvise may be used on platforms where O_DIRECT is not supported.

pgbench results are as follows:
  wal_sync_method
  - open_sync         : 156.0 tps
  - fdatasync         : 126.3 tps
  - fdatasync+fadvise : 161.2 tps
 (8.1beta1 on Linux 2.6.8-24)

I'll appreciate any comments and advices,
Takahiro



*** xlog.c    Mon Aug 29 11:51:19 2005
--- xlog-with-fadvise.c    Tue Aug 30 15:08:24 2005
***************
*** 1352,1357 ****
--- 1352,1358 ----
              Assert(npages == 0);
              if (openLogFile >= 0)
              {
+                 posix_fadvise(openLogFile, 0, 0, POSIX_FADV_DONTNEED);
                  if (close(openLogFile))
                      ereport(PANIC,
                              (errcode_for_file_access(),
***************
*** 1535,1540 ****
--- 1536,1542 ----
              if (openLogFile >= 0 &&
               !XLByteInPrevSeg(LogwrtResult.Write, openLogId, openLogSeg))
              {
+                 posix_fadvise(openLogFile, 0, 0, POSIX_FADV_DONTNEED);
                  if (close(openLogFile))
                      ereport(PANIC,
                              (errcode_for_file_access(),


pgsql-patches by date:

Previous
From: Allan Wang
Date:
Subject: Re: Work-in-progress referential action trigger timing patch
Next
From: Tom Lane
Date:
Subject: Re: Free WAL caches on switching segments