about fsync in CLOG buffer write

From: 张广舟(明虚) <guangzhou(dot)zgz(at)alibaba-inc(dot)com>
To: <pgsql-hackers(at)postgresql(dot)org>
Cc: 周正中(德歌) <dege(dot)zzz(at)alibaba-inc(dot)com>, 范孝剑(康贤) <funnyxj(dot)fxj(at)alibaba-inc(dot)com>, 曾文旌(义从) <wenjing(dot)zwj(at)alibaba-inc(dot)com>, 窦贤明(执白) <xianming(dot)dxm(at)alibaba-inc(dot)com>, 萧少聪(铁庵) <shaocong(dot)xsc(at)alibaba-inc(dot)com>, 陈新坚(惧留孙) <xinjian(dot)chen(at)alibaba-inc(dot)com>
Subject: about fsync in CLOG buffer write
Date: 2015-09-10 11:39:59
Message-ID: D2178B3D.1B870%guangzhou.zgz@alibaba-inc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Hi Hackers,

We host many PG instances on each of our machines, and we want to minimize
the calls to fsync within each instance, in order to minimize possible
impact on other instances. We found there is a fsync call when CLOG buffer
is written out in SlruPhysicalWritePage(). It is often called when a backend
needs to check transaction status with SimpleLruReadPage().

The code is as follows (in src/backend/access/transam/slru.c line 837 in PG
9.4):
/*
* If not part of Flush, need to fsync now. We assume this happens
* infrequently enough that it's not a performance issue.
*/
if (!fdata)
{
if (ctl->do_fsync && pg_fsync(fd))
{
slru_errcause = SLRU_FSYNC_FAILED;
slru_errno = errno;
CloseTransientFile(fd);
return false;
}

if (CloseTransientFile(fd))
{
slru_errcause = SLRU_CLOSE_FAILED;
slru_errno = errno;
return false;
}

ctl->do_fsync is true for CLOG. Question is, could we just disable fsync
for CLOG buffer write out here? Is it safe to do so? I understand a
checkpoint will calls SimpleLruFlush to flush all CLOG buffer at once, and
the fsync call here (for buffer write out) is not necessary.

Thanks for your time!
Guangzhou

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jan Wieck 2015-09-10 12:57:34 Re: Small patch to fix an O(N^2) problem in foreign keys
Previous Message 张广舟 (明虚) 2015-09-10 11:11:15 about fsync in CLOG buffer write