Re: initdb and fsync

From: Cédric Villemain <cedric(at)2ndquadrant(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Andres Freund <andres(at)anarazel(dot)de>, Robert Haas <robertmhaas(at)gmail(dot)com>, Jeff Davis <pgsql(at)j-davis(dot)com>, Noah Misch <noah(at)leadboat(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andrew Dunstan <andrew(at)dunslane(dot)net>
Subject: Re: initdb and fsync
Date: 2012-03-17 16:48:38
Message-ID: 201203171748.38738.cedric@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Le vendredi 16 mars 2012 16:51:04, Andres Freund a écrit :
> On Friday, March 16, 2012 04:47:06 PM Robert Haas wrote:
> > On Fri, Mar 16, 2012 at 6:25 AM, Andres Freund <andres(at)anarazel(dot)de> wrote:
> > >> > How are the results with sync_file_range(fd, 0, 0,
> > >> > SYNC_FILE_RANGE_WRITE)?
> > >>
> > >> That is much faster than using fadvise. It goes down to ~2s.
> > >>
> > >> Unfortunately, that's non-portable. Any other ideas? 6.5s a little on
> > >> the annoying side (and causes some disconcerting sounds to come from
> > >> my disk), especially when we _know_ it can be done in 2s.
> > >
> > > Its not like posix_fadvise is actually portable. So I personally don't
> > > see a problem with that, but...
> >
> > Well, sync_file_range only works on Linux, and will probably never
> > work anywhere else. posix_fadvise() at least has a chance of being
> > supported on other platforms, being a standard and all that. Though I
> > see that my Mac has neither. :-(
>
> I would suggest adding a wrapper function like:
> pg_hint_writeback_flush(fd, off, len);
>
> which then is something like
>
> #if HAVE_SYNC_FILE_RANGE
> sync_file_range(fd, off, len, SYNC_FILE_RANGE_WRITE);
> #elseif HAVE_POSIX_FADVISE
> posix_fadvise(fd, off, len, POSIX_FADV_DONTNEED);
> #else
> #endif
>
> To my knowledge posix_fadvise currently is only supported on linux btw...

I agree with Andres.

I believe we should use sync_file_range (_before?) with linux.
And we can use posix_fadvise_dontneed on other kernels.

FADVISE_DONTNEED does start a writeback (it may decide not to do it too), but
the primer objective of posix_fadvise_dontneed is not to make sync() faster.
We just have writeback and sync() calls challenged together and we can face
situation where linux does not handle that so well. (depends on linux 2.6.18
or 32 or 3.2 or ...)

--
Cédric Villemain +33 (0)6 20 30 22 52
http://2ndQuadrant.fr/
PostgreSQL: Support 24x7 - Développement, Expertise et Formation

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Atri Sharma 2012-03-17 17:13:10 Re: Regarding column reordering project for GSoc 2012
Previous Message Andrew Dunstan 2012-03-17 15:59:53 Re: Regarding column reordering project for GSoc 2012