diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2012-07-21 20:10:29 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2012-07-21 20:10:29 -0400 |
commit | 2d46a57ddcad394e514bbefb193a4a03e766f163 (patch) | |
tree | a6f4cb51623dc770e284d127986bf37f14f5744b /src/backend/storage/file/fd.c | |
parent | 2c4f5b4bc5385b37d062451642abd384536eeeb3 (diff) | |
download | postgresql-2d46a57ddcad394e514bbefb193a4a03e766f163.tar.gz postgresql-2d46a57ddcad394e514bbefb193a4a03e766f163.zip |
Improve copydir() code for the case that fsync is off.
We should avoid calling sync_file_range or posix_fadvise in this case,
since (a) we don't really care if the data gets synced, and might as
well save the kernel calls; (b) at least on Linux we know that the
kernel might block us until it's scheduled the write.
Also, avoid making a useless second traversal of the directory tree
if we're not actually going to call fsync(2) after all.
Diffstat (limited to 'src/backend/storage/file/fd.c')
-rw-r--r-- | src/backend/storage/file/fd.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index 9724f481dc0..1e54715056c 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -337,18 +337,22 @@ pg_fdatasync(int fd) * pg_flush_data --- advise OS that the data described won't be needed soon * * Not all platforms have sync_file_range or posix_fadvise; treat as no-op - * if not available. + * if not available. Also, treat as no-op if enableFsync is off; this is + * because the call isn't free, and some platforms such as Linux will actually + * block the requestor until the write is scheduled. */ int pg_flush_data(int fd, off_t offset, off_t amount) { + if (enableFsync) + { #if defined(HAVE_SYNC_FILE_RANGE) - return sync_file_range(fd, offset, amount, SYNC_FILE_RANGE_WRITE); + return sync_file_range(fd, offset, amount, SYNC_FILE_RANGE_WRITE); #elif defined(USE_POSIX_FADVISE) && defined(POSIX_FADV_DONTNEED) - return posix_fadvise(fd, offset, amount, POSIX_FADV_DONTNEED); -#else - return 0; + return posix_fadvise(fd, offset, amount, POSIX_FADV_DONTNEED); #endif + } + return 0; } |