Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2d46a57

Browse files
committed
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 aswell save the kernel calls; (b) at least on Linux we know that thekernel might block us until it's scheduled the write.Also, avoid making a useless second traversal of the directory treeif we're not actually going to call fsync(2) after all.
1 parent2c4f5b4 commit2d46a57

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

‎src/backend/storage/file/copydir.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ copydir(char *fromdir, char *todir, bool recurse)
9898

9999
/*
100100
* Be paranoid here and fsync all files to ensure the copy is really done.
101+
* But if fsync is disabled, we're done.
101102
*/
103+
if (!enableFsync)
104+
return;
105+
102106
xldir=AllocateDir(todir);
103107
if (xldir==NULL)
104108
ereport(ERROR,
@@ -200,9 +204,9 @@ copy_file(char *fromfile, char *tofile)
200204
/*
201205
* We fsync the files later but first flush them to avoid spamming the
202206
* cache and hopefully get the kernel to start writing them out before
203-
* the fsync comes.
207+
* the fsync comes. Ignore any error, since it's only a hint.
204208
*/
205-
pg_flush_data(dstfd,offset,nbytes);
209+
(void)pg_flush_data(dstfd,offset,nbytes);
206210
}
207211

208212
if (close(dstfd))

‎src/backend/storage/file/fd.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,18 +337,22 @@ pg_fdatasync(int fd)
337337
* pg_flush_data --- advise OS that the data described won't be needed soon
338338
*
339339
* Not all platforms have sync_file_range or posix_fadvise; treat as no-op
340-
* if not available.
340+
* if not available. Also, treat as no-op if enableFsync is off; this is
341+
* because the call isn't free, and some platforms such as Linux will actually
342+
* block the requestor until the write is scheduled.
341343
*/
342344
int
343345
pg_flush_data(intfd,off_toffset,off_tamount)
344346
{
347+
if (enableFsync)
348+
{
345349
#if defined(HAVE_SYNC_FILE_RANGE)
346-
returnsync_file_range(fd,offset,amount,SYNC_FILE_RANGE_WRITE);
350+
returnsync_file_range(fd,offset,amount,SYNC_FILE_RANGE_WRITE);
347351
#elif defined(USE_POSIX_FADVISE)&& defined(POSIX_FADV_DONTNEED)
348-
returnposix_fadvise(fd,offset,amount,POSIX_FADV_DONTNEED);
349-
#else
350-
return0;
352+
returnposix_fadvise(fd,offset,amount,POSIX_FADV_DONTNEED);
351353
#endif
354+
}
355+
return0;
352356
}
353357

354358

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp