Re: [PERFORM] Direct I/O issues - Mailing list pgsql-patches

From Bruce Momjian
Subject Re: [PERFORM] Direct I/O issues
Date
Msg-id 200702140501.l1E51Ro28045@momjian.us
Whole thread Raw
In response to Re: [PERFORM] Direct I/O issues  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-patches
Tom Lane wrote:
> Bruce Momjian <bruce@momjian.us> writes:
> > Not sure if people want this for 8.2.  I think we can modify
> > test_fsync.c anytime but the movement of the defines into an include
> > file is a backend code change.
>
> I think fooling with this on the day before RC1 is an unreasonable risk ...
> and I disapprove of moving this code into a widely-used include file
> like xlog.h, too.

fsync method defines moved to /include/access/xlogdefs.h so they can be
used by test_fsync.c.

--
  Bruce Momjian  <bruce@momjian.us>          http://momjian.us
  EnterpriseDB                               http://www.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +
Index: src/backend/access/transam/xlog.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v
retrieving revision 1.263
diff -c -c -r1.263 xlog.c
*** src/backend/access/transam/xlog.c    8 Feb 2007 11:10:27 -0000    1.263
--- src/backend/access/transam/xlog.c    14 Feb 2007 04:51:23 -0000
***************
*** 31,36 ****
--- 31,37 ----
  #include "access/twophase.h"
  #include "access/xact.h"
  #include "access/xlog_internal.h"
+ #include "access/xlogdefs.h"
  #include "access/xlogutils.h"
  #include "catalog/catversion.h"
  #include "catalog/pg_control.h"
***************
*** 49,126 ****
  #include "utils/pg_locale.h"


- /*
-  *    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
-

  /* File path names (all relative to $PGDATA) */
  #define BACKUP_LABEL_FILE        "backup_label"
--- 50,55 ----
Index: src/include/access/xlogdefs.h
===================================================================
RCS file: /cvsroot/pgsql/src/include/access/xlogdefs.h,v
retrieving revision 1.16
diff -c -c -r1.16 xlogdefs.h
*** src/include/access/xlogdefs.h    5 Jan 2007 22:19:51 -0000    1.16
--- src/include/access/xlogdefs.h    14 Feb 2007 04:51:24 -0000
***************
*** 63,66 ****
--- 63,137 ----
   */
  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 */
Index: src/tools/fsync/test_fsync.c
===================================================================
RCS file: /cvsroot/pgsql/src/tools/fsync/test_fsync.c,v
retrieving revision 1.17
diff -c -c -r1.17 test_fsync.c
*** src/tools/fsync/test_fsync.c    25 Nov 2006 01:22:28 -0000    1.17
--- src/tools/fsync/test_fsync.c    14 Feb 2007 04:51:26 -0000
***************
*** 7,12 ****
--- 7,13 ----

  #include "access/xlog_internal.h"
  #include "access/xlog.h"
+ #include "access/xlogdefs.h"

  #include <sys/types.h>
  #include <sys/stat.h>
***************
*** 18,100 ****
  #include <unistd.h>
  #include <string.h>

- /* ---------------------------------------------------------------
-  *    Copied from xlog.c.  Some day this should be moved an include file.
-  */
-
- /*
-  *    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
-
- /* ------------ from xlog.c --------------- */

  #ifdef WIN32
  #define FSYNC_FILENAME    "./test_fsync.out"
--- 19,24 ----

pgsql-patches by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Avg performance for int8/numeric
Next
From: Bruce Momjian
Date:
Subject: Re: [HACKERS] Error in from_char() for field 'D'?