summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorThomas Munro2021-07-18 20:52:00 +0000
committerThomas Munro2021-07-18 23:01:01 +0000
commit2dbe8905711ba09a2214b6e835f8f0c2c4981cb3 (patch)
tree775e44cb05c4dfa8f12e68eb388f04e9aa252c96 /src/include
parentf157db862225a7bfe041ca3f7b73e913e2a8d8d6 (diff)
Support direct I/O on macOS.
Macs don't understand O_DIRECT, but they can disable caching with a separate fcntl() call. Extend the file opening functions in fd.c to handle this for us if the caller passes in PG_O_DIRECT. For now, this affects only WAL data and even then only if you set: max_wal_senders=0 wal_level=minimal This is not expected to be very useful on its own, but later proposed patches will make greater use of direct I/O, and it'll be useful for testing if developers on Macs can see the effects. Reviewed-by: Andres Freund <andres@anarazel.de> Discussion: https://postgr.es/m/CA%2BhUKG%2BADiyyHe0cun2wfT%2BSVnFVqNYPxoO6J9zcZkVO7%2BNGig%40mail.gmail.com
Diffstat (limited to 'src/include')
-rw-r--r--src/include/access/xlogdefs.h15
-rw-r--r--src/include/storage/fd.h16
2 files changed, 16 insertions, 15 deletions
diff --git a/src/include/access/xlogdefs.h b/src/include/access/xlogdefs.h
index 0940b64ca6b..60348d18509 100644
--- a/src/include/access/xlogdefs.h
+++ b/src/include/access/xlogdefs.h
@@ -65,21 +65,6 @@ typedef uint32 TimeLineID;
typedef uint16 RepOriginId;
/*
- * Because O_DIRECT bypasses the kernel buffers, and because we never
- * read those buffers except during crash recovery or if wal_level != minimal,
- * it is a win to use it in all cases where we sync on each write(). We could
- * allow O_DIRECT with fsync(), but it is unclear if fsync() could process
- * writes not buffered in the kernel. Also, O_DIRECT is never enough to force
- * data to the drives, it merely tries to bypass the kernel cache, so we still
- * need O_SYNC/O_DSYNC.
- */
-#ifdef O_DIRECT
-#define PG_O_DIRECT O_DIRECT
-#else
-#define PG_O_DIRECT 0
-#endif
-
-/*
* This chunk of hackery attempts to determine which file sync methods
* are available on the current platform, and to choose an appropriate
* default method. We assume that fsync() is always available, and that
diff --git a/src/include/storage/fd.h b/src/include/storage/fd.h
index 5b3c280dd7a..2d843eb9929 100644
--- a/src/include/storage/fd.h
+++ b/src/include/storage/fd.h
@@ -80,6 +80,22 @@ extern int max_safe_fds;
#endif
/*
+ * O_DIRECT is not standard, but almost every Unix has it. We translate it
+ * to the appropriate Windows flag in src/port/open.c. We simulate it with
+ * fcntl(F_NOCACHE) on macOS inside fd.c's open() wrapper. We use the name
+ * PG_O_DIRECT rather than defining O_DIRECT in that case (probably not a good
+ * idea on a Unix).
+ */
+#if defined(O_DIRECT)
+#define PG_O_DIRECT O_DIRECT
+#elif defined(F_NOCACHE)
+#define PG_O_DIRECT 0x80000000
+#define PG_O_DIRECT_USE_F_NOCACHE
+#else
+#define PG_O_DIRECT 0
+#endif
+
+/*
* prototypes for functions in fd.c
*/