Skip to content

Commit a1b5609

Browse files
committed
Remove O_FSYNC and associated macros.
O_FSYNC was a pre-POSIX way of spelling O_SYNC, supported since commit 9d645fd for non-conforming operating systems of the time. It's not needed on any modern system. We can just use standard O_SYNC directly if it exists (= all targeted systems except Windows), and get rid of our OPEN_SYNC_FLAG macro. Similarly for standard O_DSYNC, we can just use that directly if it exists (= all targeted systems except DragonFlyBSD), and get rid of our OPEN_DATASYNC_FLAG macro. We still avoid choosing open_datasync as a default value for wal_sync_method if O_DSYNC has the same value as O_SYNC (= only OpenBSD), so there is no change in default behavior. Discussion: https://postgr.es/m/CA%2BhUKGJE7y92NY7FG2ftUbZUaqohBU65_Ys_7xF5mUHo4wirTQ%40mail.gmail.com
1 parent 4f1f5a7 commit a1b5609

File tree

3 files changed

+19
-35
lines changed

3 files changed

+19
-35
lines changed

src/backend/access/transam/xlog.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,10 @@ const struct config_enum_entry sync_method_options[] = {
171171
#ifdef HAVE_FDATASYNC
172172
{"fdatasync", SYNC_METHOD_FDATASYNC, false},
173173
#endif
174-
#ifdef OPEN_SYNC_FLAG
174+
#ifdef O_SYNC
175175
{"open_sync", SYNC_METHOD_OPEN, false},
176176
#endif
177-
#ifdef OPEN_DATASYNC_FLAG
177+
#ifdef O_DSYNC
178178
{"open_datasync", SYNC_METHOD_OPEN_DSYNC, false},
179179
#endif
180180
{NULL, 0, false}
@@ -7894,10 +7894,10 @@ get_sync_bit(int method)
78947894

78957895
/*
78967896
* Optimize writes by bypassing kernel cache with O_DIRECT when using
7897-
* O_SYNC/O_FSYNC and O_DSYNC. But only if archiving and streaming are
7898-
* disabled, otherwise the archive command or walsender process will read
7899-
* the WAL soon after writing it, which is guaranteed to cause a physical
7900-
* read if we bypassed the kernel cache. We also skip the
7897+
* O_SYNC and O_DSYNC. But only if archiving and streaming are disabled,
7898+
* otherwise the archive command or walsender process will read the WAL
7899+
* soon after writing it, which is guaranteed to cause a physical read if
7900+
* we bypassed the kernel cache. We also skip the
79017901
* posix_fadvise(POSIX_FADV_DONTNEED) call in XLogFileClose() for the same
79027902
* reason.
79037903
*
@@ -7921,13 +7921,13 @@ get_sync_bit(int method)
79217921
case SYNC_METHOD_FSYNC_WRITETHROUGH:
79227922
case SYNC_METHOD_FDATASYNC:
79237923
return 0;
7924-
#ifdef OPEN_SYNC_FLAG
7924+
#ifdef O_SYNC
79257925
case SYNC_METHOD_OPEN:
7926-
return OPEN_SYNC_FLAG | o_direct_flag;
7926+
return O_SYNC | o_direct_flag;
79277927
#endif
7928-
#ifdef OPEN_DATASYNC_FLAG
7928+
#ifdef O_DSYNC
79297929
case SYNC_METHOD_OPEN_DSYNC:
7930-
return OPEN_DATASYNC_FLAG | o_direct_flag;
7930+
return O_DSYNC | o_direct_flag;
79317931
#endif
79327932
default:
79337933
/* can't happen (unless we are out of sync with option array) */

src/bin/pg_test_fsync/pg_test_fsync.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ test_sync(int writes_per_op)
300300
printf(LABEL_FORMAT, "open_datasync");
301301
fflush(stdout);
302302

303-
#ifdef OPEN_DATASYNC_FLAG
303+
#ifdef O_DSYNC
304304
if ((tmpfile = open_direct(filename, O_RDWR | O_DSYNC | PG_BINARY, 0)) == -1)
305305
{
306306
printf(NA_FORMAT, _("n/a*"));
@@ -407,8 +407,8 @@ test_sync(int writes_per_op)
407407
printf(LABEL_FORMAT, "open_sync");
408408
fflush(stdout);
409409

410-
#ifdef OPEN_SYNC_FLAG
411-
if ((tmpfile = open_direct(filename, O_RDWR | OPEN_SYNC_FLAG | PG_BINARY, 0)) == -1)
410+
#ifdef O_SYNC
411+
if ((tmpfile = open_direct(filename, O_RDWR | O_SYNC | PG_BINARY, 0)) == -1)
412412
{
413413
printf(NA_FORMAT, _("n/a*"));
414414
fs_warning = true;
@@ -466,7 +466,7 @@ test_open_syncs(void)
466466
static void
467467
test_open_sync(const char *msg, int writes_size)
468468
{
469-
#ifdef OPEN_SYNC_FLAG
469+
#ifdef O_SYNC
470470
int tmpfile,
471471
ops,
472472
writes;
@@ -475,8 +475,8 @@ test_open_sync(const char *msg, int writes_size)
475475
printf(LABEL_FORMAT, msg);
476476
fflush(stdout);
477477

478-
#ifdef OPEN_SYNC_FLAG
479-
if ((tmpfile = open_direct(filename, O_RDWR | OPEN_SYNC_FLAG | PG_BINARY, 0)) == -1)
478+
#ifdef O_SYNC
479+
if ((tmpfile = open_direct(filename, O_RDWR | O_SYNC | PG_BINARY, 0)) == -1)
480480
printf(NA_FORMAT, _("n/a*"));
481481
else
482482
{

src/include/access/xlogdefs.h

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,28 +69,12 @@ typedef uint16 RepOriginId;
6969
* are available on the current platform, and to choose an appropriate
7070
* default method. We assume that fsync() is always available, and that
7171
* configure determined whether fdatasync() is.
72+
*
73+
* Note that we define our own O_DSYNC on Windows, but not O_SYNC.
7274
*/
73-
#if defined(O_SYNC)
74-
#define OPEN_SYNC_FLAG O_SYNC
75-
#elif defined(O_FSYNC)
76-
#define OPEN_SYNC_FLAG O_FSYNC
77-
#endif
78-
79-
#if defined(O_DSYNC)
80-
#if defined(OPEN_SYNC_FLAG)
81-
/* O_DSYNC is distinct? */
82-
#if O_DSYNC != OPEN_SYNC_FLAG
83-
#define OPEN_DATASYNC_FLAG O_DSYNC
84-
#endif
85-
#else /* !defined(OPEN_SYNC_FLAG) */
86-
/* Win32 only has O_DSYNC */
87-
#define OPEN_DATASYNC_FLAG O_DSYNC
88-
#endif
89-
#endif
90-
9175
#if defined(PLATFORM_DEFAULT_SYNC_METHOD)
9276
#define DEFAULT_SYNC_METHOD PLATFORM_DEFAULT_SYNC_METHOD
93-
#elif defined(OPEN_DATASYNC_FLAG)
77+
#elif defined(O_DSYNC) && (!defined(O_SYNC) || O_DSYNC != O_SYNC)
9478
#define DEFAULT_SYNC_METHOD SYNC_METHOD_OPEN_DSYNC
9579
#elif defined(HAVE_FDATASYNC)
9680
#define DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy