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
7272 buf = (char * ) TYPEALIGN (ALIGNOF_XLOG_BUFFER , full_buf );
7373
74+ /*
75+ * Simple write
76+ */
7477 printf ("Simple write timing:\n" );
7578 /* write only */
7679 gettimeofday (& start_t , NULL );
@@ -87,8 +90,11 @@ main(int argc, char *argv[])
8790 print_elapse (start_t , elapse_t );
8891 printf ("\n" );
8992
93+ /*
94+ * Fsync another file descriptor?
95+ */
9096 printf ("\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 */
94100 gettimeofday (& start_t , NULL );
@@ -132,6 +138,9 @@ main(int argc, char *argv[])
132138 print_elapse (start_t , elapse_t );
133139 printf ("\n" );
134140
141+ /*
142+ * Compare 1 to 2 writes
143+ */
135144 printf ("\nCompare one o_sync write to two:\n" );
136145
137146#ifdef OPEN_SYNC_FLAG
@@ -148,7 +157,7 @@ main(int argc, char *argv[])
148157 print_elapse (start_t , elapse_t );
149158 printf ("\n" );
150159
151- /* 2* 8k o_sync writes */
160+ /* Two 8k o_sync writes */
152161 if ((tmpfile = open (filename , O_RDWR | OPEN_SYNC_FLAG , 0 )) == -1 )
153162 die ("Cannot open output file." );
154163 gettimeofday (& start_t , NULL );
@@ -163,14 +172,16 @@ main(int argc, char *argv[])
163172 close (tmpfile );
164173 printf ("\ttwo 8k o_sync writes " );
165174 print_elapse (start_t , elapse_t );
166- printf ("\n" );
167-
168- printf ("\nCompare file sync methods with one 8k write:\n" );
169175#else
170176 printf ("\t(o_sync unavailable) " );
171177#endif
172178 printf ("\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 */
176187 if ((tmpfile = open (filename , O_RDWR | O_DSYNC , 0 )) == -1 )
@@ -183,7 +194,11 @@ main(int argc, char *argv[])
183194 close (tmpfile );
184195 printf ("\topen o_dsync, write " );
185196 print_elapse (start_t , elapse_t );
197+ #else
198+ printf ("\t(o_dsync unavailable) " );
199+ #endif
186200 printf ("\n" );
201+
187202#ifdef OPEN_SYNC_FLAG
188203 /* open_fsync, write */
189204 if ((tmpfile = open (filename , O_RDWR | OPEN_SYNC_FLAG , 0 )) == -1 )
@@ -196,9 +211,8 @@ main(int argc, char *argv[])
196211 close (tmpfile );
197212 printf ("\topen o_sync, write " );
198213 print_elapse (start_t , elapse_t );
199- #endif
200214#else
201- printf ("\t(o_dsync unavailable) " );
215+ printf ("\t(o_sync unavailable) " );
202216#endif
203217 printf ("\n" );
204218
@@ -235,11 +249,14 @@ main(int argc, char *argv[])
235249 }
236250 gettimeofday (& elapse_t , NULL );
237251 close (tmpfile );
238- printf ("\twrite, fsync, " );
252+ printf ("\twrite, fsync " );
239253 print_elapse (start_t , elapse_t );
240254 printf ("\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 }
319336 gettimeofday (& elapse_t , NULL );
320337 close (tmpfile );
321- printf ("\twrite, fsync, " );
338+ printf ("\twrite, fsync " );
322339 print_elapse (start_t , elapse_t );
323340 printf ("\n" );
324341
0 commit comments