Free WAL caches on switching segments

From: ITAGAKI Takahiro <itagaki(dot)takahiro(at)lab(dot)ntt(dot)co(dot)jp>
To: pgsql-patches(at)postgresql(dot)org
Subject: Free WAL caches on switching segments
Date: 2005-08-30 07:15:32
Message-ID: 20050830151029.4A59.ITAGAKI.TAKAHIRO@lab.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(),

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2005-08-30 07:25:27 Re: Free WAL caches on switching segments
Previous Message Allan Wang 2005-08-30 02:35:18 Re: Work-in-progress referential action trigger timing patch