PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pg_test_fsync.c File Reference
#include "postgres_fe.h"
#include <sys/stat.h>
#include <sys/time.h>
#include <unistd.h>
#include <signal.h>
#include "getopt_long.h"
#include "access/xlogdefs.h"
Include dependency graph for pg_test_fsync.c:

Go to the source code of this file.

Macros

#define FSYNC_FILENAME   "./pg_test_fsync.out"
 
#define XLOG_BLCKSZ_K   (XLOG_BLCKSZ / 1024)
 
#define LABEL_FORMAT   " %-30s"
 
#define NA_FORMAT   "%20s"
 
#define OPS_FORMAT   "%13.3f ops/sec %6.0f usecs/op"
 
#define USECS_SEC   1000000
 
#define START_TIMER
 
#define STOP_TIMER
 

Functions

static void handle_args (int argc, char *argv[])
 
static void prepare_buf (void)
 
static void test_open (void)
 
static void test_non_sync (void)
 
static void test_sync (int writes_per_op)
 
static void test_open_syncs (void)
 
static void test_open_sync (const char *msg, int writes_size)
 
static void test_file_descriptor_sync (void)
 
static void process_alarm (int sig)
 
static void signal_cleanup (int sig)
 
static void print_elapse (struct timeval start_t, struct timeval stop_t, int ops)
 
static void die (const char *str)
 
int main (int argc, char *argv[])
 

Variables

static const char * progname
 
static int secs_per_test = 5
 
static int needs_unlink = 0
 
static char full_buf [XLOG_SEG_SIZE]
 
static char * buf
 
static char * filename = FSYNC_FILENAME
 
static struct timeval start_t stop_t
 
static bool alarm_triggered = false
 

Macro Definition Documentation

#define FSYNC_FILENAME   "./pg_test_fsync.out"

Definition at line 22 of file pg_test_fsync.c.

#define LABEL_FORMAT   " %-30s"
#define NA_FORMAT   "%20s"

Definition at line 27 of file pg_test_fsync.c.

Referenced by test_open_sync(), and test_sync().

#define OPS_FORMAT   "%13.3f ops/sec %6.0f usecs/op"

Definition at line 28 of file pg_test_fsync.c.

Referenced by print_elapse().

#define START_TIMER
Value:
do { \
alarm_triggered = false; \
alarm(secs_per_test); \
gettimeofday(&start_t, NULL); \
} while (0)
int gettimeofday(struct timeval *tp, struct timezone *tzp)
Definition: gettimeofday.c:105
static int secs_per_test
Definition: pg_test_fsync.c:63
static bool alarm_triggered
Definition: pg_test_fsync.c:70
#define NULL
Definition: c.h:229

Definition at line 33 of file pg_test_fsync.c.

Referenced by test_file_descriptor_sync(), test_non_sync(), test_open_sync(), and test_sync().

#define STOP_TIMER
Value:
do { \
print_elapse(start_t, stop_t, ops); \
} while (0)
int gettimeofday(struct timeval *tp, struct timezone *tzp)
Definition: gettimeofday.c:105
static void print_elapse(struct timeval start_t, struct timeval stop_t, int ops)
static struct timeval start_t stop_t
Definition: pg_test_fsync.c:68
#define NULL
Definition: c.h:229

Definition at line 54 of file pg_test_fsync.c.

Referenced by test_file_descriptor_sync(), test_non_sync(), test_open_sync(), and test_sync().

#define USECS_SEC   1000000

Definition at line 29 of file pg_test_fsync.c.

Referenced by print_elapse().

#define XLOG_BLCKSZ_K   (XLOG_BLCKSZ / 1024)

Definition at line 24 of file pg_test_fsync.c.

Referenced by test_non_sync(), and test_sync().

Function Documentation

static void die ( const char *  str)
static

Definition at line 600 of file pg_test_fsync.c.

References _, and strerror().

Referenced by test_file_descriptor_sync(), test_non_sync(), test_open(), test_open_sync(), and test_sync().

601 {
602  fprintf(stderr, _("%s: %s\n"), _(str), strerror(errno));
603  exit(1);
604 }
const char * strerror(int errnum)
Definition: strerror.c:19
#define _(x)
Definition: elog.c:84
static void handle_args ( int  argc,
char *  argv[] 
)
static

Definition at line 137 of file pg_test_fsync.c.

References _, filename, getopt_long(), NULL, optarg, optind, progname, required_argument, and secs_per_test.

Referenced by main().

138 {
139  static struct option long_options[] = {
140  {"filename", required_argument, NULL, 'f'},
141  {"secs-per-test", required_argument, NULL, 's'},
142  {NULL, 0, NULL, 0}
143  };
144 
145  int option; /* Command line option */
146  int optindex = 0; /* used by getopt_long */
147 
148  if (argc > 1)
149  {
150  if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
151  {
152  printf(_("Usage: %s [-f FILENAME] [-s SECS-PER-TEST]\n"), progname);
153  exit(0);
154  }
155  if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
156  {
157  puts("pg_test_fsync (PostgreSQL) " PG_VERSION);
158  exit(0);
159  }
160  }
161 
162  while ((option = getopt_long(argc, argv, "f:s:",
163  long_options, &optindex)) != -1)
164  {
165  switch (option)
166  {
167  case 'f':
168  filename = strdup(optarg);
169  break;
170 
171  case 's':
172  secs_per_test = atoi(optarg);
173  break;
174 
175  default:
176  fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
177  progname);
178  exit(1);
179  break;
180  }
181  }
182 
183  if (argc > optind)
184  {
185  fprintf(stderr,
186  _("%s: too many command-line arguments (first is \"%s\")\n"),
187  progname, argv[optind]);
188  fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
189  progname);
190  exit(1);
191  }
192 
193  printf(_("%d seconds per test\n"), secs_per_test);
194 #if PG_O_DIRECT != 0
195  printf(_("O_DIRECT supported on this platform for open_datasync and open_sync.\n"));
196 #else
197  printf(_("Direct I/O is not supported on this platform.\n"));
198 #endif
199 }
static int secs_per_test
Definition: pg_test_fsync.c:63
static char * filename
Definition: pg_test_fsync.c:67
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
Definition: getopt_long.c:57
#define required_argument
Definition: getopt_long.h:25
int optind
Definition: getopt.c:51
static const char * progname
Definition: pg_test_fsync.c:61
#define NULL
Definition: c.h:229
char * optarg
Definition: getopt.c:53
#define _(x)
Definition: elog.c:84
int main ( int  argc,
char *  argv[] 
)

Definition at line 97 of file pg_test_fsync.c.

References filename, get_progname(), handle_args(), PG_TEXTDOMAIN, pqsignal(), prepare_buf(), process_alarm(), progname, set_pglocale_pgservice(), SIGALRM, SIGHUP, signal_cleanup(), test_file_descriptor_sync(), test_non_sync(), test_open(), test_open_syncs(), test_sync(), and unlink().

98 {
99  set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_test_fsync"));
100  progname = get_progname(argv[0]);
101 
102  handle_args(argc, argv);
103 
104  /* Prevent leaving behind the test file */
105  pqsignal(SIGINT, signal_cleanup);
106  pqsignal(SIGTERM, signal_cleanup);
107 #ifndef WIN32
109 #endif
110 #ifdef SIGHUP
111  /* Not defined on win32 */
113 #endif
114 
115  prepare_buf();
116 
117  test_open();
118 
119  /* Test using 1 XLOG_BLCKSZ write */
120  test_sync(1);
121 
122  /* Test using 2 XLOG_BLCKSZ writes */
123  test_sync(2);
124 
125  test_open_syncs();
126 
128 
129  test_non_sync();
130 
131  unlink(filename);
132 
133  return 0;
134 }
static void test_sync(int writes_per_op)
static char * filename
Definition: pg_test_fsync.c:67
const char * get_progname(const char *argv0)
Definition: path.c:453
static void test_open(void)
static void prepare_buf(void)
static const char * progname
Definition: pg_test_fsync.c:61
int unlink(const char *filename)
#define PG_TEXTDOMAIN(domain)
Definition: c.h:1012
static void test_open_syncs(void)
static void test_non_sync(void)
#define SIGHUP
Definition: win32.h:196
static void process_alarm(int sig)
pqsigfunc pqsignal(int signum, pqsigfunc handler)
Definition: signal.c:168
static void signal_cleanup(int sig)
void set_pglocale_pgservice(const char *argv0, const char *app)
Definition: exec.c:550
static void test_file_descriptor_sync(void)
#define SIGALRM
Definition: win32.h:202
static void handle_args(int argc, char *argv[])
static void prepare_buf ( void  )
static

Definition at line 202 of file pg_test_fsync.c.

References buf, full_buf, random(), and TYPEALIGN.

Referenced by main().

203 {
204  int ops;
205 
206  /* write random data into buffer */
207  for (ops = 0; ops < XLOG_SEG_SIZE; ops++)
208  full_buf[ops] = random();
209 
210  buf = (char *) TYPEALIGN(XLOG_BLCKSZ, full_buf);
211 }
static char full_buf[XLOG_SEG_SIZE]
Definition: pg_test_fsync.c:65
long random(void)
Definition: random.c:22
static char * buf
Definition: pg_test_fsync.c:65
#define TYPEALIGN(ALIGNVAL, LEN)
Definition: c.h:581
static void print_elapse ( struct timeval  start_t,
struct timeval  stop_t,
int  ops 
)
static

Definition at line 572 of file pg_test_fsync.c.

References OPS_FORMAT, and USECS_SEC.

573 {
574  double total_time = (stop_t.tv_sec - start_t.tv_sec) +
575  (stop_t.tv_usec - start_t.tv_usec) * 0.000001;
576  double per_second = ops / total_time;
577  double avg_op_time_us = (total_time / ops) * USECS_SEC;
578 
579  printf(OPS_FORMAT "\n", per_second, avg_op_time_us);
580 }
#define USECS_SEC
Definition: pg_test_fsync.c:29
static struct timeval start_t stop_t
Definition: pg_test_fsync.c:68
#define OPS_FORMAT
Definition: pg_test_fsync.c:28
static void process_alarm ( int  sig)
static

Definition at line 584 of file pg_test_fsync.c.

References alarm_triggered.

Referenced by main().

585 {
586  alarm_triggered = true;
587 }
static bool alarm_triggered
Definition: pg_test_fsync.c:70
static void signal_cleanup ( int  sig)
static

Definition at line 542 of file pg_test_fsync.c.

References filename, needs_unlink, and unlink().

Referenced by main().

543 {
544  /* Delete the file if it exists. Ignore errors */
545  if (needs_unlink)
546  unlink(filename);
547  /* Finish incomplete line on stdout */
548  puts("");
549  exit(signum);
550 }
static char * filename
Definition: pg_test_fsync.c:67
int unlink(const char *filename)
static int needs_unlink
Definition: pg_test_fsync.c:64
static void test_file_descriptor_sync ( void  )
static

Definition at line 448 of file pg_test_fsync.c.

References _, alarm_triggered, buf, close, die(), filename, fsync, LABEL_FORMAT, START_TIMER, STOP_TIMER, and write.

Referenced by main().

449 {
450  int tmpfile,
451  ops;
452 
453  /*
454  * Test whether fsync can sync data written on a different descriptor for
455  * the same file. This checks the efficiency of multi-process fsyncs
456  * against the same file. Possibly this should be done with writethrough
457  * on platforms which support it.
458  */
459  printf(_("\nTest if fsync on non-write file descriptor is honored:\n"));
460  printf(_("(If the times are similar, fsync() can sync data written on a different\n"
461  "descriptor.)\n"));
462 
463  /*
464  * first write, fsync and close, which is the normal behavior without
465  * multiple descriptors
466  */
467  printf(LABEL_FORMAT, "write, fsync, close");
468  fflush(stdout);
469 
470  START_TIMER;
471  for (ops = 0; alarm_triggered == false; ops++)
472  {
473  if ((tmpfile = open(filename, O_RDWR, 0)) == -1)
474  die("could not open output file");
475  if (write(tmpfile, buf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
476  die("write failed");
477  if (fsync(tmpfile) != 0)
478  die("fsync failed");
479  close(tmpfile);
480 
481  /*
482  * open and close the file again to be consistent with the following
483  * test
484  */
485  if ((tmpfile = open(filename, O_RDWR, 0)) == -1)
486  die("could not open output file");
487  close(tmpfile);
488  }
489  STOP_TIMER;
490 
491  /*
492  * Now open, write, close, open again and fsync This simulates processes
493  * fsyncing each other's writes.
494  */
495  printf(LABEL_FORMAT, "write, close, fsync");
496  fflush(stdout);
497 
498  START_TIMER;
499  for (ops = 0; alarm_triggered == false; ops++)
500  {
501  if ((tmpfile = open(filename, O_RDWR, 0)) == -1)
502  die("could not open output file");
503  if (write(tmpfile, buf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
504  die("write failed");
505  close(tmpfile);
506  /* reopen file */
507  if ((tmpfile = open(filename, O_RDWR, 0)) == -1)
508  die("could not open output file");
509  if (fsync(tmpfile) != 0)
510  die("fsync failed");
511  close(tmpfile);
512  }
513  STOP_TIMER;
514 }
static char * filename
Definition: pg_test_fsync.c:67
#define write(a, b, c)
Definition: win32.h:19
static void die(const char *str)
static bool alarm_triggered
Definition: pg_test_fsync.c:70
static char * buf
Definition: pg_test_fsync.c:65
#define fsync(fd)
Definition: win32.h:70
#define STOP_TIMER
Definition: pg_test_fsync.c:54
#define LABEL_FORMAT
Definition: pg_test_fsync.c:26
#define START_TIMER
Definition: pg_test_fsync.c:33
#define close(a)
Definition: win32.h:17
#define _(x)
Definition: elog.c:84
static void test_non_sync ( void  )
static

Definition at line 517 of file pg_test_fsync.c.

References _, alarm_triggered, buf, close, die(), filename, LABEL_FORMAT, START_TIMER, STOP_TIMER, write, and XLOG_BLCKSZ_K.

Referenced by main().

518 {
519  int tmpfile,
520  ops;
521 
522  /*
523  * Test a simple write without fsync
524  */
525  printf(_("\nNon-sync'ed %dkB writes:\n"), XLOG_BLCKSZ_K);
526  printf(LABEL_FORMAT, "write");
527  fflush(stdout);
528 
529  START_TIMER;
530  for (ops = 0; alarm_triggered == false; ops++)
531  {
532  if ((tmpfile = open(filename, O_RDWR, 0)) == -1)
533  die("could not open output file");
534  if (write(tmpfile, buf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
535  die("write failed");
536  close(tmpfile);
537  }
538  STOP_TIMER;
539 }
static char * filename
Definition: pg_test_fsync.c:67
#define write(a, b, c)
Definition: win32.h:19
static void die(const char *str)
static bool alarm_triggered
Definition: pg_test_fsync.c:70
static char * buf
Definition: pg_test_fsync.c:65
#define XLOG_BLCKSZ_K
Definition: pg_test_fsync.c:24
#define STOP_TIMER
Definition: pg_test_fsync.c:54
#define LABEL_FORMAT
Definition: pg_test_fsync.c:26
#define START_TIMER
Definition: pg_test_fsync.c:33
#define close(a)
Definition: win32.h:17
#define _(x)
Definition: elog.c:84
static void test_open ( void  )
static

Definition at line 214 of file pg_test_fsync.c.

References close, die(), filename, fsync, full_buf, needs_unlink, and write.

Referenced by main().

215 {
216  int tmpfile;
217 
218  /*
219  * test if we can open the target file
220  */
221  if ((tmpfile = open(filename, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)) == -1)
222  die("could not open output file");
223  needs_unlink = 1;
224  if (write(tmpfile, full_buf, XLOG_SEG_SIZE) != XLOG_SEG_SIZE)
225  die("write failed");
226 
227  /* fsync now so that dirty buffers don't skew later tests */
228  if (fsync(tmpfile) != 0)
229  die("fsync failed");
230 
231  close(tmpfile);
232 }
static char full_buf[XLOG_SEG_SIZE]
Definition: pg_test_fsync.c:65
static char * filename
Definition: pg_test_fsync.c:67
#define write(a, b, c)
Definition: win32.h:19
static void die(const char *str)
#define fsync(fd)
Definition: win32.h:70
static int needs_unlink
Definition: pg_test_fsync.c:64
#define close(a)
Definition: win32.h:17
static void test_open_sync ( const char *  msg,
int  writes_size 
)
static

Definition at line 413 of file pg_test_fsync.c.

References _, alarm_triggered, buf, close, die(), filename, LABEL_FORMAT, NA_FORMAT, PG_O_DIRECT, START_TIMER, STOP_TIMER, and write.

Referenced by test_open_syncs().

414 {
415 #ifdef OPEN_SYNC_FLAG
416  int tmpfile,
417  ops,
418  writes;
419 #endif
420 
421  printf(LABEL_FORMAT, msg);
422  fflush(stdout);
423 
424 #ifdef OPEN_SYNC_FLAG
425  if ((tmpfile = open(filename, O_RDWR | OPEN_SYNC_FLAG | PG_O_DIRECT, 0)) == -1)
426  printf(NA_FORMAT, _("n/a*\n"));
427  else
428  {
429  START_TIMER;
430  for (ops = 0; alarm_triggered == false; ops++)
431  {
432  for (writes = 0; writes < 16 / writes_size; writes++)
433  if (write(tmpfile, buf, writes_size * 1024) !=
434  writes_size * 1024)
435  die("write failed");
436  if (lseek(tmpfile, 0, SEEK_SET) == -1)
437  die("seek failed");
438  }
439  STOP_TIMER;
440  close(tmpfile);
441  }
442 #else
443  printf(NA_FORMAT, _("n/a\n"));
444 #endif
445 }
#define PG_O_DIRECT
Definition: xlogdefs.h:65
static char * filename
Definition: pg_test_fsync.c:67
#define write(a, b, c)
Definition: win32.h:19
static void die(const char *str)
static bool alarm_triggered
Definition: pg_test_fsync.c:70
static char * buf
Definition: pg_test_fsync.c:65
#define NA_FORMAT
Definition: pg_test_fsync.c:27
#define STOP_TIMER
Definition: pg_test_fsync.c:54
#define LABEL_FORMAT
Definition: pg_test_fsync.c:26
#define START_TIMER
Definition: pg_test_fsync.c:33
#define close(a)
Definition: win32.h:17
#define _(x)
Definition: elog.c:84
static void test_open_syncs ( void  )
static

Definition at line 396 of file pg_test_fsync.c.

References _, and test_open_sync().

Referenced by main().

397 {
398  printf(_("\nCompare open_sync with different write sizes:\n"));
399  printf(_("(This is designed to compare the cost of writing 16kB in different write\n"
400  "open_sync sizes.)\n"));
401 
402  test_open_sync(_(" 1 * 16kB open_sync write"), 16);
403  test_open_sync(_(" 2 * 8kB open_sync writes"), 8);
404  test_open_sync(_(" 4 * 4kB open_sync writes"), 4);
405  test_open_sync(_(" 8 * 2kB open_sync writes"), 2);
406  test_open_sync(_("16 * 1kB open_sync writes"), 1);
407 }
#define _(x)
Definition: elog.c:84
static void test_open_sync(const char *msg, int writes_size)
static void test_sync ( int  writes_per_op)
static

Definition at line 235 of file pg_test_fsync.c.

References _, alarm_triggered, buf, close, die(), filename, fsync, LABEL_FORMAT, NA_FORMAT, O_DSYNC, pg_fsync_writethrough(), PG_O_DIRECT, START_TIMER, STOP_TIMER, write, and XLOG_BLCKSZ_K.

Referenced by main().

236 {
237  int tmpfile,
238  ops,
239  writes;
240  bool fs_warning = false;
241 
242  if (writes_per_op == 1)
243  printf(_("\nCompare file sync methods using one %dkB write:\n"), XLOG_BLCKSZ_K);
244  else
245  printf(_("\nCompare file sync methods using two %dkB writes:\n"), XLOG_BLCKSZ_K);
246  printf(_("(in wal_sync_method preference order, except fdatasync is Linux's default)\n"));
247 
248  /*
249  * Test open_datasync if available
250  */
251  printf(LABEL_FORMAT, "open_datasync");
252  fflush(stdout);
253 
254 #ifdef OPEN_DATASYNC_FLAG
255  if ((tmpfile = open(filename, O_RDWR | O_DSYNC | PG_O_DIRECT, 0)) == -1)
256  {
257  printf(NA_FORMAT, _("n/a*\n"));
258  fs_warning = true;
259  }
260  else
261  {
262  START_TIMER;
263  for (ops = 0; alarm_triggered == false; ops++)
264  {
265  for (writes = 0; writes < writes_per_op; writes++)
266  if (write(tmpfile, buf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
267  die("write failed");
268  if (lseek(tmpfile, 0, SEEK_SET) == -1)
269  die("seek failed");
270  }
271  STOP_TIMER;
272  close(tmpfile);
273  }
274 #else
275  printf(NA_FORMAT, _("n/a\n"));
276 #endif
277 
278 /*
279  * Test fdatasync if available
280  */
281  printf(LABEL_FORMAT, "fdatasync");
282  fflush(stdout);
283 
284 #ifdef HAVE_FDATASYNC
285  if ((tmpfile = open(filename, O_RDWR, 0)) == -1)
286  die("could not open output file");
287  START_TIMER;
288  for (ops = 0; alarm_triggered == false; ops++)
289  {
290  for (writes = 0; writes < writes_per_op; writes++)
291  if (write(tmpfile, buf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
292  die("write failed");
293  fdatasync(tmpfile);
294  if (lseek(tmpfile, 0, SEEK_SET) == -1)
295  die("seek failed");
296  }
297  STOP_TIMER;
298  close(tmpfile);
299 #else
300  printf(NA_FORMAT, _("n/a\n"));
301 #endif
302 
303 /*
304  * Test fsync
305  */
306  printf(LABEL_FORMAT, "fsync");
307  fflush(stdout);
308 
309  if ((tmpfile = open(filename, O_RDWR, 0)) == -1)
310  die("could not open output file");
311  START_TIMER;
312  for (ops = 0; alarm_triggered == false; ops++)
313  {
314  for (writes = 0; writes < writes_per_op; writes++)
315  if (write(tmpfile, buf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
316  die("write failed");
317  if (fsync(tmpfile) != 0)
318  die("fsync failed");
319  if (lseek(tmpfile, 0, SEEK_SET) == -1)
320  die("seek failed");
321  }
322  STOP_TIMER;
323  close(tmpfile);
324 
325 /*
326  * If fsync_writethrough is available, test as well
327  */
328  printf(LABEL_FORMAT, "fsync_writethrough");
329  fflush(stdout);
330 
331 #ifdef HAVE_FSYNC_WRITETHROUGH
332  if ((tmpfile = open(filename, O_RDWR, 0)) == -1)
333  die("could not open output file");
334  START_TIMER;
335  for (ops = 0; alarm_triggered == false; ops++)
336  {
337  for (writes = 0; writes < writes_per_op; writes++)
338  if (write(tmpfile, buf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
339  die("write failed");
340  if (pg_fsync_writethrough(tmpfile) != 0)
341  die("fsync failed");
342  if (lseek(tmpfile, 0, SEEK_SET) == -1)
343  die("seek failed");
344  }
345  STOP_TIMER;
346  close(tmpfile);
347 #else
348  printf(NA_FORMAT, _("n/a\n"));
349 #endif
350 
351 /*
352  * Test open_sync if available
353  */
354  printf(LABEL_FORMAT, "open_sync");
355  fflush(stdout);
356 
357 #ifdef OPEN_SYNC_FLAG
358  if ((tmpfile = open(filename, O_RDWR | OPEN_SYNC_FLAG | PG_O_DIRECT, 0)) == -1)
359  {
360  printf(NA_FORMAT, _("n/a*\n"));
361  fs_warning = true;
362  }
363  else
364  {
365  START_TIMER;
366  for (ops = 0; alarm_triggered == false; ops++)
367  {
368  for (writes = 0; writes < writes_per_op; writes++)
369  if (write(tmpfile, buf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
370 
371  /*
372  * This can generate write failures if the filesystem has
373  * a large block size, e.g. 4k, and there is no support
374  * for O_DIRECT writes smaller than the file system block
375  * size, e.g. XFS.
376  */
377  die("write failed");
378  if (lseek(tmpfile, 0, SEEK_SET) == -1)
379  die("seek failed");
380  }
381  STOP_TIMER;
382  close(tmpfile);
383  }
384 #else
385  printf(NA_FORMAT, _("n/a\n"));
386 #endif
387 
388  if (fs_warning)
389  {
390  printf(_("* This file system and its mount options do not support direct\n"
391  " I/O, e.g. ext4 in journaled mode.\n"));
392  }
393 }
#define PG_O_DIRECT
Definition: xlogdefs.h:65
static char * filename
Definition: pg_test_fsync.c:67
#define write(a, b, c)
Definition: win32.h:19
int pg_fsync_writethrough(int fd)
Definition: fd.c:362
static void die(const char *str)
static bool alarm_triggered
Definition: pg_test_fsync.c:70
#define O_DSYNC
Definition: win32.h:280
static char * buf
Definition: pg_test_fsync.c:65
#define NA_FORMAT
Definition: pg_test_fsync.c:27
#define XLOG_BLCKSZ_K
Definition: pg_test_fsync.c:24
#define fsync(fd)
Definition: win32.h:70
#define STOP_TIMER
Definition: pg_test_fsync.c:54
#define LABEL_FORMAT
Definition: pg_test_fsync.c:26
#define START_TIMER
Definition: pg_test_fsync.c:33
#define close(a)
Definition: win32.h:17
#define _(x)
Definition: elog.c:84

Variable Documentation

bool alarm_triggered = false
static
char * buf
static

Definition at line 65 of file pg_test_fsync.c.

Referenced by _bt_clear_incomplete_split(), _bt_doinsert(), _bt_endpoint(), _bt_findinsertloc(), _bt_first(), _bt_get_endpoint(), _bt_getbuf(), _bt_getstackbuf(), _bt_is_page_halfdead(), _bt_killitems(), _bt_moveright(), _bt_relandgetbuf(), _bt_unlink_halfdead_page(), _bt_walk_left(), _conv(), _discoverArchiveFormat(), _EndBlob(), _hash_doinsert(), _hash_first(), _hash_getbucketbuf_from_hashkey(), _hash_getbuf(), _hash_getbuf_with_condlock_cleanup(), _hash_getbuf_with_strategy(), _hash_getinitbuf(), _hash_getnewbuf(), _hash_init(), _hash_next(), _hash_step(), _PG_init(), _PrintFileData(), _skipData(), _WriteBlobData(), abbroffset(), abstimeout(), abstimerecv(), abstimesend(), add_tablespace_footer(), aes_cbc_decrypt(), AlterSequence(), appendAggOrderBy(), appendConditions(), appendContextKeyword(), appendFunctionName(), appendGroupByClause(), appendOrderByClause(), array_dims(), array_recv(), array_send(), array_to_text_internal(), asyncQueueReadAllNotifications(), AtEOXact_Snapshot(), b64_decode(), b64_encode(), be_lo_export(), big5_to_euc_tw(), bit_recv(), boolrecv(), boolsend(), bootstrap_template1(), box_recv(), box_send(), bpcharrecv(), bqarr_in(), brin_getinsertbuffer(), brin_vacuum_scan(), brin_xlog_createidx(), brin_xlog_revmap_extend(), bringetbitmap(), brininsert(), brinsummarize(), BSD44_derived_dlsym(), btvacuumpage(), btvacuumscan(), buf_init(), BufferAlloc(), build_client_final_message(), build_client_first_message(), BuildIndexValueDescription(), bytearecv(), cache_single_time(), calc_s2k_iter_salted(), calc_s2k_salted(), calc_s2k_simple(), cash_out(), cash_recv(), cash_send(), cash_words(), charrecv(), charsend(), check_key_cksum(), check_strxfrm_bug(), check_TSCurrentConfig(), CheckForExternalTrigger(), CheckPointTwoPhase(), CheckSASLAuth(), checkXLogConsistency(), ChooseIndexColumnNames(), ChooseIndexNameAddition(), cidr_recv(), cidrecv(), cidsend(), circle_recv(), circle_send(), cluster_conn_opts(), compile_pltcl_function(), complex_recv(), complex_send(), ConditionalLockBuffer(), conninfo_parse(), conninfo_uri_decode(), conninfo_uri_parse_options(), constructConnStr(), ConvertTriggerToFK(), copy_file_range(), copy_heap_data(), copy_read_data(), copy_relation_data(), CopyGetInt16(), CopyGetInt32(), CopySendInt16(), CopySendInt32(), count_nondeletable_pages(), create_cursor(), createBackupLabel(), cstring_recv(), cstring_send(), cube_out(), date_out(), date_recv(), date_send(), date_test_fmt(), datum_to_json(), datum_to_jsonb(), dblink_close(), dblink_fdw_validator(), dblink_fetch(), dblink_open(), decrypt_read(), DeleteAllExportedSnapshotFiles(), deparse_expression_pretty(), deparseAggref(), deparseArrayExpr(), deparseArrayRef(), deparseBoolExpr(), deparseConst(), deparseDirectDeleteSql(), deparseDirectUpdateSql(), deparseDistinctExpr(), deparseExplicitTargetList(), deparseFromExpr(), deparseFromExprForRel(), deparseFuncExpr(), deparseLockingClause(), deparseNullTest(), deparseOpExpr(), deparseScalarArrayOpExpr(), deparseSelectSql(), deparseSelectStmtForRel(), deparseSortGroupClause(), deparseSubqueryTargetList(), describeAccessMethods(), describeAggregates(), describeFunctions(), describeOneTableDetails(), describeOneTSConfig(), describeOneTSParser(), describeOperators(), describePublications(), describeRoles(), describeSubscriptions(), describeTableDetails(), describeTablespaces(), describeTypes(), DispatchJobForTocEntry(), do_compile(), do_lo_list(), do_setval(), domain_recv(), dropRoles(), dsm_cleanup_for_mmap(), dump_lo_buf(), dumpBlobs(), dumpCreateDB(), dumpDatabaseConfig(), dumpDbRoleConfig(), dumpGroups(), dumpRoleMembership(), dumpRoles(), dumpTablespaces(), dumpTimestamp(), dumpUserConfig(), ean13_out(), ean2isn(), enum_recv(), enum_send(), escape_param_str(), escape_xml(), euc_tw_to_big5(), exec_command(), exec_describe_statement_message(), ExecBuildSlotPartitionKeyDescription(), ExecBuildSlotValueDescription(), ExecEvalXml(), ExecQueryUsingCursor(), ExecuteSimpleCommands(), expand_fmt_string(), expand_grouping_sets(), ExplainPropertyFloat(), ExplainPropertyInteger(), ExplainPropertyLong(), exportFile(), ExportSnapshot(), file_fdw_validator(), fill_seq_with_data(), find_provider(), FindStreamingStart(), FinishPreparedTransaction(), flatten_reloptions(), flatten_set_variable_args(), float4_numeric(), float4recv(), float4send(), float8_numeric(), float8recv(), float8send(), flush_pipe_input(), fmtlong(), format_aggregate_signature(), format_operator_internal(), format_procedure_internal(), format_type_internal(), formatPGVersionNumber(), FreePageManagerDump(), FreeSpaceMapTruncateRel(), fsm_readbuf(), fsm_search(), fsm_set_and_search(), fsm_vacuum_page(), generate_operator_name(), generate_trgm_only(), generate_wildcard_trgm(), get_agg_expr(), get_basic_select_query(), get_coercion_expr(), get_collation_actual_version(), get_column_alias_list(), get_connect_string(), get_const_collation(), get_const_expr(), get_delete_query_def(), get_from_clause(), get_from_clause_coldeflist(), get_from_clause_item(), get_func_expr(), get_insert_query_def(), get_modifiers(), get_oper_expr(), get_prompt(), get_query_def(), get_raw_page_internal(), get_rule_expr(), get_rule_groupingset(), get_rule_orderby(), get_rule_sortgroupclause(), get_rule_windowclause(), get_rule_windowspec(), get_select_query_def(), get_setop_query(), get_special_variable(), get_sql_delete(), get_sql_insert(), get_sql_update(), get_sublink_expr(), get_tablefunc(), get_tablesample_def(), get_target_list(), get_tuple_of_interest(), get_update_query_def(), get_update_query_targetlist_def(), get_utility_query_def(), get_values_def(), get_variable(), get_wildcard_part(), get_windowfunc_expr(), get_with_clause(), getaddrinfo(), GetBufferFromRing(), GetRecordedFreeSpace(), ginCompressPostingList(), gistfixsplit(), handleCopyIn(), handleCopyOut(), hash_xlog_split_page(), hashbucketcleanup(), hashbulkdelete(), hashgettuple(), heap_lock_updated_tuple_rec(), hmac_finish(), hstore_recv(), hstore_send(), hstorePairs(), importFile(), inet_recv(), infile(), init_params(), InitBufferPool(), initialize_worker_spi(), InitLocalBuffers(), int2recv(), int2send(), int2vectorrecv(), int4recv(), int4send(), int8_avg_deserialize(), int8_avg_serialize(), int8out(), int8recv(), int8send(), interval_out(), interval_recv(), interval_send(), isn_out(), isRelDataFile(), json_recv(), json_send(), jsonb_agg_transfn(), jsonb_object_agg_transfn(), jsonb_recv(), jsonb_send(), KnownAssignedXidsDisplay(), lazy_scan_heap(), lazy_vacuum_heap(), lazy_vacuum_rel(), libpqrcv_get_conninfo(), line_recv(), line_send(), listAllDbs(), listCasts(), listCollations(), listConversions(), listDbRoleSettings(), listDefaultACLs(), listDomains(), listEventTriggers(), listExtensionContents(), listExtensions(), listForeignDataWrappers(), listForeignServers(), listForeignTables(), listLanguages(), listOneExtensionContents(), listPublications(), listSchemas(), listTables(), listTSConfigs(), listTSConfigsVerbose(), listTSDictionaries(), listTSParsers(), listTSParsersVerbose(), listTSTemplates(), listUserMappings(), lo_export(), lo_import_internal(), load_resultmap(), locale_date_order(), LockBuffer(), LogicalDecodingProcessRecord(), LogicalRepApplyLoop(), lquery_in(), lquery_out(), lseg_recv(), lseg_send(), ltree_crc32_sz(), ltree_in(), ltree_out(), macaddr8_recv(), macaddr8_send(), macaddr_recv(), macaddr_send(), main(), make_absolute_path(), make_ruledef(), makeAlterConfigCommand(), map_sql_identifier_to_xml_name(), map_sql_value_to_xml_value(), map_xml_name_to_sql_identifier(), mp_px_rand(), mxid_to_string(), namerecv(), namesend(), network_send(), next_field_expand(), next_token(), nextval_internal(), NotifyMyFrontEnd(), num_word(), numeric_abbrev_convert(), numeric_avg_deserialize(), numeric_avg_serialize(), numeric_deserialize(), numeric_poly_deserialize(), numeric_poly_serialize(), numeric_recv(), numeric_send(), numeric_serialize(), objectDescription(), oidrecv(), oidsend(), oidvectorrecv(), output(), overwrite(), pad_eme_pkcs1_v15(), parse_literal_data(), parse_phrase_operator(), parse_snapshot(), parse_tsquery(), parseAclItem(), parseServiceFile(), passwordFromFile(), path_recv(), path_send(), perform_base_backup(), permissionsList(), pg_armor(), pg_b64_decode(), pg_b64_encode(), pg_dearmor(), pg_gen_salt(), pg_gen_salt_rounds(), pg_get_constraintdef_worker(), pg_get_function_arguments(), pg_get_function_identity_arguments(), pg_get_function_result(), pg_get_functiondef(), pg_get_indexdef_worker(), pg_get_partkeydef_worker(), pg_get_ruledef_worker(), pg_get_triggerdef_worker(), pg_get_viewdef_worker(), pg_local_sendauth(), pg_lsn_mi(), pg_lsn_out(), pg_lsn_recv(), pg_lsn_send(), pg_prewarm(), pg_random_uuid(), pg_sequence_last_value(), pg_size_pretty(), pgp_armor_decode(), pgp_encrypt(), pgp_extract_armor_headers(), pgp_key_id_w(), pgp_mpi_hash(), pgp_mpi_write(), pgrowlocks(), pgstat_btree_page(), pgstat_gist_page(), pgstat_hash_page(), pgstathashindex(), PGTYPESdate_to_asc(), PGTYPESinterval_to_asc(), PGTYPESnumeric_div(), PGTYPEStimestamp_to_asc(), pgwin32_recv(), pgwin32_select(), pgwin32_waitforsinglesocket(), pgxmlNodeSetToText(), pickout(), PLy_exception_set(), PLy_exception_set_plural(), point_recv(), point_send(), poly2path(), poly_recv(), poly_send(), postgres_fdw_validator(), postgresImportForeignSchema(), PostgresMain(), postgresql_fdw_validator(), PQoidStatus(), prefix_init(), prepare_buf(), PrescanPreparedTransactions(), PrintBufferLeakWarning(), PrintQueryStatus(), printRemoteParam(), printRemotePlaceholder(), printsimple(), printsimple_startup(), printSubscripts(), printtup(), printtup_20(), printtup_internal_20(), process_file(), process_pipe_input(), processIndirection(), ProcessStartupPacket(), ProcSleep(), prompt_for_password(), puttzcode(), puttzcode64(), pwdfMatchesString(), px_debug(), px_find_combo(), qtext_load_file(), queryin(), quote_qualified_identifier(), range_bound_escape(), range_deparse(), range_parse_bound(), range_recv(), range_send(), read_binary_file(), read_file_contents(), read_text_file(), read_whole_file(), ReadBufferExtended(), ReadDataFromArchiveNone(), ReadStr(), readtup_alloc(), ReadTwoPhaseFile(), ReadyForQuery(), ReceiveCopyBegin(), record_in(), record_out(), record_recv(), record_send(), RecoverPreparedTransactions(), recv_password_packet(), regression_main(), RelationFindReplTupleByIndex(), RelationFindReplTupleSeq(), reltimeout(), reltimerecv(), reltimesend(), repairDependencyLoop(), replace_text_regexp(), report_invalid_encoding(), report_untranslatable_char(), ResetSequence(), restore(), revmap_physical_extend(), rm_redo_error_callback(), run_crypt_des(), sanitize_char(), send_message_to_frontend(), send_message_to_server_log(), sendAuthRequest(), SendBackupHeader(), SendCopyBegin(), sendFile(), sendFileWithContent(), SendFunctionResult(), SendQuery(), SendRowDescriptionMessage(), SendTimeLineHistory(), SendXlogRecPtrResult(), sepgsql_audit_log(), serialize_deflist(), show_log_file_mode(), show_unix_socket_permissions(), ShowTransactionStateRec(), simple_prompt(), SortTocFromFile(), SPI_result_code_string(), SplitToVariants(), ssl_extension_info(), StandbyRecoverPreparedTransactions(), StandbyTransactionIdIsPrepared(), StartBackgroundWorker(), StartBufferIO(), StartLogicalReplication(), StartReplication(), StartupXLOG(), statapprox_heap(), stop_postmaster(), str_time(), StrategyGetBuffer(), strerror(), string2ean(), t_readline(), tar_write(), test_file_descriptor_sync(), test_non_sync(), test_open_sync(), test_sync(), textrecv(), textsend(), tidout(), tidrecv(), tidsend(), time_out(), time_recv(), time_send(), timeofday(), timestamp_out(), timestamp_recv(), timestamp_send(), timestamptz_out(), timestamptz_recv(), timestamptz_send(), timestamptz_to_str(), timetz_out(), timetz_recv(), timetz_send(), tintervalrecv(), tintervalsend(), to_hex32(), to_hex64(), TQSendRecordInfo(), truncate_identifier(), try_complete_step(), ts_stat_sql(), tsquery_rewrite_query(), tsqueryrecv(), tsquerysend(), tsvectorin(), tsvectorrecv(), tsvectorsend(), txid_snapshot_recv(), txid_snapshot_send(), typeStringToTypeName(), unaccent_lexize(), unknownrecv(), unknownsend(), unpack_sql_state(), uuid_generate_v1mc(), uuid_out(), vacuum_one_database(), vacuumlo(), varbit_recv(), varbit_send(), varcharrecv(), vm_readbuf(), void_send(), WaitForCommands(), WalReceiverMain(), write_auto_conf_file(), write_csvlog(), write_target_range(), xidrecv(), xidsend(), XLogDumpXLogRead(), XLogInitBufferForRedo(), XLogInsertRecord(), XLogRead(), XLogRecordPageWithFreeSpace(), XLOGShmemSize(), xml_out_internal(), xml_recv(), xml_send(), xmlcomment(), xmlconcat(), xmlpi(), xmlroot(), and yearistype().

char full_buf[XLOG_SEG_SIZE]
static

Definition at line 65 of file pg_test_fsync.c.

Referenced by prepare_buf(), and test_open().

int needs_unlink = 0
static

Definition at line 64 of file pg_test_fsync.c.

Referenced by signal_cleanup(), and test_open().

const char* progname
static

Definition at line 61 of file pg_test_fsync.c.

Referenced by handle_args(), and main().

int secs_per_test = 5
static

Definition at line 63 of file pg_test_fsync.c.

Referenced by handle_args().

struct timeval start_t stop_t
static

Definition at line 68 of file pg_test_fsync.c.