Revert WAL posix_fallocate() patches.

This reverts commit 269e780822
and commit 5b571bb8c8.

Unfortunately, the initial patch had insufficient performance testing,
and resulted in a regression.

Per report by Thom Brown.
This commit is contained in:
Jeff Davis 2013-09-04 23:43:41 -07:00
parent be6fcb671e
commit b1892aaeaa
5 changed files with 36 additions and 60 deletions

3
configure vendored
View File

@ -19763,8 +19763,7 @@ LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'`
for ac_func in cbrt dlopen fdatasync getifaddrs getpeerucred getrlimit mbstowcs_l memmove poll pstat readlink setproctitle setsid sigprocmask symlink sync_file_range towlower utime utimes wcstombs wcstombs_l
for ac_func in cbrt dlopen fdatasync getifaddrs getpeerucred getrlimit mbstowcs_l memmove poll posix_fallocate pstat readlink setproctitle setsid sigprocmask symlink sync_file_range towlower utime utimes wcstombs wcstombs_l
do do
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 { $as_echo "$as_me:$LINENO: checking for $ac_func" >&5

View File

@ -1230,7 +1230,7 @@ PGAC_FUNC_GETTIMEOFDAY_1ARG
LIBS_including_readline="$LIBS" LIBS_including_readline="$LIBS"
LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'` LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'`
AC_CHECK_FUNCS([cbrt dlopen fdatasync getifaddrs getpeerucred getrlimit mbstowcs_l memmove poll posix_fallocate pstat readlink setproctitle setsid sigprocmask symlink sync_file_range towlower utime utimes wcstombs wcstombs_l]) AC_CHECK_FUNCS([cbrt dlopen fdatasync getifaddrs getpeerucred getrlimit mbstowcs_l memmove poll pstat readlink setproctitle setsid sigprocmask symlink sync_file_range towlower utime utimes wcstombs wcstombs_l])
AC_REPLACE_FUNCS(fseeko) AC_REPLACE_FUNCS(fseeko)
case $host_os in case $host_os in

View File

@ -3353,10 +3353,11 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent, bool use_lock)
{ {
char path[MAXPGPATH]; char path[MAXPGPATH];
char tmppath[MAXPGPATH]; char tmppath[MAXPGPATH];
char *zbuffer;
XLogSegNo installed_segno; XLogSegNo installed_segno;
int max_advance; int max_advance;
int fd; int fd;
bool zero_fill = true; int nbytes;
XLogFilePath(path, ThisTimeLineID, logsegno); XLogFilePath(path, ThisTimeLineID, logsegno);
@ -3390,6 +3391,16 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent, bool use_lock)
unlink(tmppath); unlink(tmppath);
/*
* Allocate a buffer full of zeros. This is done before opening the file
* so that we don't leak the file descriptor if palloc fails.
*
* Note: palloc zbuffer, instead of just using a local char array, to
* ensure it is reasonably well-aligned; this may save a few cycles
* transferring data to the kernel.
*/
zbuffer = (char *) palloc0(XLOG_BLCKSZ);
/* do not use get_sync_bit() here --- want to fsync only at end of fill */ /* do not use get_sync_bit() here --- want to fsync only at end of fill */
fd = BasicOpenFile(tmppath, O_RDWR | O_CREAT | O_EXCL | PG_BINARY, fd = BasicOpenFile(tmppath, O_RDWR | O_CREAT | O_EXCL | PG_BINARY,
S_IRUSR | S_IWUSR); S_IRUSR | S_IWUSR);
@ -3398,40 +3409,14 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent, bool use_lock)
(errcode_for_file_access(), (errcode_for_file_access(),
errmsg("could not create file \"%s\": %m", tmppath))); errmsg("could not create file \"%s\": %m", tmppath)));
#ifdef HAVE_POSIX_FALLOCATE
/* /*
* If posix_fallocate() is available and succeeds, then the file is * Zero-fill the file. We have to do this the hard way to ensure that all
* properly allocated and we don't need to zero-fill it (which is less * the file space has really been allocated --- on platforms that allow
* efficient). In case of an error, fall back to writing zeros, because on * "holes" in files, just seeking to the end doesn't allocate intermediate
* some platforms posix_fallocate() is available but will not always * space. This way, we know that we have all the space and (after the
* succeed in cases where zero-filling will. * fsync below) that all the indirect blocks are down on disk. Therefore,
*/ * fdatasync(2) or O_DSYNC will be sufficient to sync future writes to the
if (posix_fallocate(fd, 0, XLogSegSize) == 0) * log file.
zero_fill = false;
#endif /* HAVE_POSIX_FALLOCATE */
if (zero_fill)
{
/*
* Allocate a buffer full of zeros. This is done before opening the
* file so that we don't leak the file descriptor if palloc fails.
*
* Note: palloc zbuffer, instead of just using a local char array, to
* ensure it is reasonably well-aligned; this may save a few cycles
* transferring data to the kernel.
*/
char *zbuffer = (char *) palloc0(XLOG_BLCKSZ);
int nbytes;
/*
* Zero-fill the file. We have to do this the hard way to ensure that
* all the file space has really been allocated --- on platforms that
* allow "holes" in files, just seeking to the end doesn't allocate
* intermediate space. This way, we know that we have all the space
* and (after the fsync below) that all the indirect blocks are down on
* disk. Therefore, fdatasync(2) or O_DSYNC will be sufficient to sync
* future writes to the log file.
*/ */
for (nbytes = 0; nbytes < XLogSegSize; nbytes += XLOG_BLCKSZ) for (nbytes = 0; nbytes < XLogSegSize; nbytes += XLOG_BLCKSZ)
{ {
@ -3447,17 +3432,15 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent, bool use_lock)
close(fd); close(fd);
/* if write didn't set errno, assume no disk space */ /* if write didn't set errno, assume problem is no disk space */
errno = save_errno ? save_errno : ENOSPC; errno = save_errno ? save_errno : ENOSPC;
ereport(ERROR, ereport(ERROR,
(errcode_for_file_access(), (errcode_for_file_access(),
errmsg("could not write to file \"%s\": %m", errmsg("could not write to file \"%s\": %m", tmppath)));
tmppath)));
} }
} }
pfree(zbuffer); pfree(zbuffer);
}
if (pg_fsync(fd) != 0) if (pg_fsync(fd) != 0)
{ {

View File

@ -369,9 +369,6 @@
/* Define to 1 if you have the `posix_fadvise' function. */ /* Define to 1 if you have the `posix_fadvise' function. */
#undef HAVE_POSIX_FADVISE #undef HAVE_POSIX_FADVISE
/* Define to 1 if you have the `posix_fallocate' function. */
#undef HAVE_POSIX_FALLOCATE
/* Define to 1 if you have the POSIX signal interface. */ /* Define to 1 if you have the POSIX signal interface. */
#undef HAVE_POSIX_SIGNALS #undef HAVE_POSIX_SIGNALS

View File

@ -276,9 +276,6 @@
/* Define to 1 if you have the <poll.h> header file. */ /* Define to 1 if you have the <poll.h> header file. */
/* #undef HAVE_POLL_H */ /* #undef HAVE_POLL_H */
/* Define to 1 if you have the `posix_fallocate' function. */
/* #undef HAVE_POSIX_FALLOCATE */
/* Define to 1 if you have the POSIX signal interface. */ /* Define to 1 if you have the POSIX signal interface. */
/* #undef HAVE_POSIX_SIGNALS */ /* #undef HAVE_POSIX_SIGNALS */