Re: initdb and fsync - Mailing list pgsql-hackers

From Andres Freund
Subject Re: initdb and fsync
Date
Msg-id 201203161651.05074.andres@anarazel.de
Whole thread Raw
In response to Re: initdb and fsync  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: initdb and fsync  (Cédric Villemain <cedric@2ndquadrant.com>)
List pgsql-hackers
On Friday, March 16, 2012 04:47:06 PM Robert Haas wrote:
> On Fri, Mar 16, 2012 at 6:25 AM, Andres Freund <andres@anarazel.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...

Andres


pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: initdb and fsync
Next
From: Tom Lane
Date:
Subject: Re: Command Triggers, v16