postgresql/src
Tom Lane 643c27e36f Increase distance between flush requests during bulk file copies.
copy_file() reads and writes data 64KB at a time (with default BLCKSZ),
and historically has issued a pg_flush_data request after each write.
This turns out to interact really badly with macOS's new APFS file
system: a large file copy takes over 100X longer than it ought to on
APFS, as reported by Brent Dearth.  While that's arguably a macOS bug,
it's not clear whether Apple will do anything about it in the near
future, and in any case experimentation suggests that issuing flushes
a bit less often can be helpful on other platforms too.

Hence, rearrange the logic in copy_file() so that flush requests are
issued once per N writes rather than every time through the loop.
I set the FLUSH_DISTANCE to 32MB on macOS (any less than that still
results in a noticeable speed degradation on APFS), but 1MB elsewhere.
In limited testing on Linux and FreeBSD, this seems slightly faster
than the previous code, and certainly no worse.  It helps noticeably
on macOS even with the older HFS filesystem.

A simpler change would have been to just increase the size of the
copy buffer without changing the loop logic, but that seems likely
to trash the processor cache without really helping much.

Back-patch to 9.6 where we introduced msync() as an implementation
option for pg_flush_data().  The problem seems specific to APFS's
mmap/msync support, so I don't think we need to go further back.

Discussion: https://postgr.es/m/CADkxhTNv-j2jw2g8H57deMeAbfRgYBoLmVuXkC=YCFBXRuCOww@mail.gmail.com
2017-10-08 15:25:26 -04:00
..
backend Increase distance between flush requests during bulk file copies. 2017-10-08 15:25:26 -04:00
bin #ifdef out some dead code in psql/mainloop.c. 2017-10-06 11:35:55 -04:00
common Replace most usages of ntoh[ls] and hton[sl] with pg_bswap.h. 2017-10-01 15:36:14 -07:00
fe_utils Provide a test for variable existence in psql 2017-09-21 19:02:23 -04:00
include Reduce "X = X" to "X IS NOT NULL", if it's easy to do so. 2017-10-08 12:23:32 -04:00
interfaces Replace most usages of ntoh[ls] and hton[sl] with pg_bswap.h. 2017-10-01 15:36:14 -07:00
makefiles Always use -fPIC, not -fpic, when building shared libraries with gcc. 2017-06-01 13:32:55 -04:00
pl Use Py_RETURN_NONE where suitable 2017-09-29 16:51:39 -04:00
port Yet another pg_bswap typo in a windows only file. 2017-10-01 20:05:27 -07:00
template Remove "sco" and "unixware" ports. 2016-10-11 11:26:04 -04:00
test Reduce "X = X" to "X IS NOT NULL", if it's easy to do so. 2017-10-08 12:23:32 -04:00
timezone Sync our copy of the timezone library with IANA tzcode master. 2017-09-22 00:04:29 -04:00
tools Enforce our convention about max number of parallel regression tests. 2017-10-07 17:20:09 -04:00
tutorial Distinguish selectivity of < from <= and > from >=. 2017-09-13 11:12:39 -04:00
.gitignore Convert cvsignore to gitignore, and add .gitignore for build targets. 2010-09-22 12:57:04 +02:00
DEVELOPERS Replace a couple of references to files that no longer exist in the source 2009-05-04 08:08:47 +00:00
Makefile Remove redundant coverage target 2017-02-17 08:56:57 -05:00
Makefile.global.in Support coverage on vpath builds 2017-10-06 11:39:46 -04:00
Makefile.shlib Remove support for bcc and msvc standalone libpq builds 2017-04-11 15:22:21 +02:00
nls-global.mk nls-global.mk: search build dir for source files, too 2016-06-07 18:55:18 -04:00