11/*
2- * $PostgreSQL: pgsql/src/tools/fsync/test_fsync.c,v 1.23 2009/06/11 14:49:15 momjian Exp $
2+ * $PostgreSQL: pgsql/src/tools/fsync/test_fsync.c,v 1.24 2009/08/10 18:19:06 momjian Exp $
33 *
44 *
55 *test_fsync.c
3030#define FSYNC_FILENAME "/var/tmp/test_fsync.out"
3131#endif
3232
33- #define WRITE_SIZE (16 * 1024)
33+ #define WRITE_SIZE (16 * 1024)/* 16k */
3434
3535void die (char * str );
3636void print_elapse (struct timeval start_t ,struct timeval elapse_t );
@@ -71,6 +71,9 @@ main(int argc, char *argv[])
7171
7272buf = (char * )TYPEALIGN (ALIGNOF_XLOG_BUFFER ,full_buf );
7373
74+ /*
75+ *Simple write
76+ */
7477printf ("Simple write timing:\n" );
7578/* write only */
7679gettimeofday (& start_t ,NULL );
@@ -87,8 +90,11 @@ main(int argc, char *argv[])
8790print_elapse (start_t ,elapse_t );
8891printf ("\n" );
8992
93+ /*
94+ *Fsync another file descriptor?
95+ */
9096printf ("\nCompare fsync times on write() and non-write() descriptor:\n" );
91- printf ("( If the times are similar, fsync() can sync data written\n on a different descriptor.) \n" );
97+ printf ("If the times are similar, fsync() can sync data written\non a different descriptor.\n" );
9298
9399/* write, fsync, close */
94100gettimeofday (& start_t ,NULL );
@@ -132,6 +138,9 @@ main(int argc, char *argv[])
132138print_elapse (start_t ,elapse_t );
133139printf ("\n" );
134140
141+ /*
142+ *Compare 1 to 2 writes
143+ */
135144printf ("\nCompare one o_sync write to two:\n" );
136145
137146#ifdef OPEN_SYNC_FLAG
@@ -148,7 +157,7 @@ main(int argc, char *argv[])
148157print_elapse (start_t ,elapse_t );
149158printf ("\n" );
150159
151- /*2* 8k o_sync writes */
160+ /*Two 8k o_sync writes */
152161if ((tmpfile = open (filename ,O_RDWR |OPEN_SYNC_FLAG ,0 ))== -1 )
153162die ("Cannot open output file." );
154163gettimeofday (& start_t ,NULL );
@@ -163,14 +172,16 @@ main(int argc, char *argv[])
163172close (tmpfile );
164173printf ("\ttwo 8k o_sync writes " );
165174print_elapse (start_t ,elapse_t );
166- printf ("\n" );
167-
168- printf ("\nCompare file sync methods with one 8k write:\n" );
169175#else
170176printf ("\t(o_sync unavailable) " );
171177#endif
172178printf ("\n" );
173179
180+ /*
181+ *Compare file sync methods with one 8k write
182+ */
183+ printf ("\nCompare file sync methods with one 8k write:\n" );
184+
174185#ifdef OPEN_DATASYNC_FLAG
175186/* open_dsync, write */
176187if ((tmpfile = open (filename ,O_RDWR |O_DSYNC ,0 ))== -1 )
@@ -183,7 +194,11 @@ main(int argc, char *argv[])
183194close (tmpfile );
184195printf ("\topen o_dsync, write " );
185196print_elapse (start_t ,elapse_t );
197+ #else
198+ printf ("\t(o_dsync unavailable) " );
199+ #endif
186200printf ("\n" );
201+
187202#ifdef OPEN_SYNC_FLAG
188203/* open_fsync, write */
189204if ((tmpfile = open (filename ,O_RDWR |OPEN_SYNC_FLAG ,0 ))== -1 )
@@ -196,9 +211,8 @@ main(int argc, char *argv[])
196211close (tmpfile );
197212printf ("\topen o_sync, write " );
198213print_elapse (start_t ,elapse_t );
199- #endif
200214#else
201- printf ("\t(o_dsync unavailable) " );
215+ printf ("\t(o_sync unavailable) " );
202216#endif
203217printf ("\n" );
204218
@@ -235,11 +249,14 @@ main(int argc, char *argv[])
235249}
236250gettimeofday (& elapse_t ,NULL );
237251close (tmpfile );
238- printf ("\twrite, fsync, " );
252+ printf ("\twrite, fsync " );
239253print_elapse (start_t ,elapse_t );
240254printf ("\n" );
241255
242- printf ("\nCompare file sync methods with 2 8k writes:\n" );
256+ /*
257+ *Compare file sync methods with two 8k write
258+ */
259+ printf ("\nCompare file sync methods with two 8k writes:\n" );
243260
244261#ifdef OPEN_DATASYNC_FLAG
245262/* open_dsync, write */
@@ -318,7 +335,7 @@ main(int argc, char *argv[])
318335}
319336gettimeofday (& elapse_t ,NULL );
320337close (tmpfile );
321- printf ("\twrite, fsync, " );
338+ printf ("\twrite, fsync " );
322339print_elapse (start_t ,elapse_t );
323340printf ("\n" );
324341