diff options
author | Bruce Momjian <bruce@momjian.us> | 2007-02-14 05:00:40 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2007-02-14 05:00:40 +0000 |
commit | a9eb53969abc27f17f13c9d19eeb2621ecd57961 (patch) | |
tree | d2058be330814eb006878385bcd64e7a26cf3cda /src/include/access/xlogdefs.h | |
parent | 5c63829f2f581f7508b08b21274f062f9ef013ea (diff) | |
download | postgresql-a9eb53969abc27f17f13c9d19eeb2621ecd57961.tar.gz postgresql-a9eb53969abc27f17f13c9d19eeb2621ecd57961.zip |
Move fsync method macro defines into /include/access/xlogdefs.h so they
can be used by src/tools/fsync/test_fsync.c.
Diffstat (limited to 'src/include/access/xlogdefs.h')
-rw-r--r-- | src/include/access/xlogdefs.h | 73 |
1 files changed, 72 insertions, 1 deletions
diff --git a/src/include/access/xlogdefs.h b/src/include/access/xlogdefs.h index 6926bd792ac..ceca7794325 100644 --- a/src/include/access/xlogdefs.h +++ b/src/include/access/xlogdefs.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/access/xlogdefs.h,v 1.16 2007/01/05 22:19:51 momjian Exp $ + * $PostgreSQL: pgsql/src/include/access/xlogdefs.h,v 1.17 2007/02/14 05:00:40 momjian Exp $ */ #ifndef XLOG_DEFS_H #define XLOG_DEFS_H @@ -63,4 +63,75 @@ typedef struct XLogRecPtr */ typedef uint32 TimeLineID; +/* + * Because O_DIRECT bypasses the kernel buffers, and because we never + * read those buffers except during crash recovery, it is a win to use + * it in all cases where we sync on each write(). We could allow O_DIRECT + * with fsync(), but because skipping the kernel buffer forces writes out + * quickly, it seems best just to use it for O_SYNC. It is hard to imagine + * how fsync() could be a win for O_DIRECT compared to O_SYNC and O_DIRECT. + * 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 or fsync(). + */ +#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 + * configure determined whether fdatasync() is. + */ +#if defined(O_SYNC) +#define BARE_OPEN_SYNC_FLAG O_SYNC +#elif defined(O_FSYNC) +#define BARE_OPEN_SYNC_FLAG O_FSYNC +#endif +#ifdef BARE_OPEN_SYNC_FLAG +#define OPEN_SYNC_FLAG (BARE_OPEN_SYNC_FLAG | PG_O_DIRECT) +#endif + +#if defined(O_DSYNC) +#if defined(OPEN_SYNC_FLAG) +/* O_DSYNC is distinct? */ +#if O_DSYNC != BARE_OPEN_SYNC_FLAG +#define OPEN_DATASYNC_FLAG (O_DSYNC | PG_O_DIRECT) +#endif +#else /* !defined(OPEN_SYNC_FLAG) */ +/* Win32 only has O_DSYNC */ +#define OPEN_DATASYNC_FLAG (O_DSYNC | PG_O_DIRECT) +#endif +#endif + +#if defined(OPEN_DATASYNC_FLAG) +#define DEFAULT_SYNC_METHOD_STR "open_datasync" +#define DEFAULT_SYNC_METHOD SYNC_METHOD_OPEN +#define DEFAULT_SYNC_FLAGBIT OPEN_DATASYNC_FLAG +#elif defined(HAVE_FDATASYNC) +#define DEFAULT_SYNC_METHOD_STR "fdatasync" +#define DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC +#define DEFAULT_SYNC_FLAGBIT 0 +#elif defined(HAVE_FSYNC_WRITETHROUGH_ONLY) +#define DEFAULT_SYNC_METHOD_STR "fsync_writethrough" +#define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC_WRITETHROUGH +#define DEFAULT_SYNC_FLAGBIT 0 +#else +#define DEFAULT_SYNC_METHOD_STR "fsync" +#define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC +#define DEFAULT_SYNC_FLAGBIT 0 +#endif + +/* + * Limitation of buffer-alignment for direct IO depends on OS and filesystem, + * but XLOG_BLCKSZ is assumed to be enough for it. + */ +#ifdef O_DIRECT +#define ALIGNOF_XLOG_BUFFER XLOG_BLCKSZ +#else +#define ALIGNOF_XLOG_BUFFER ALIGNOF_BUFFER +#endif + #endif /* XLOG_DEFS_H */ |