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 <fcntl.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   "%21s\n"
 
#define OPS_FORMAT   gettext_noop("%13.3f ops/sec %6.0f usecs/op\n")
 
#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 [DEFAULT_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 23 of file pg_test_fsync.c.

#define LABEL_FORMAT   " %-30s"
#define NA_FORMAT   "%21s\n"

Definition at line 28 of file pg_test_fsync.c.

Referenced by test_open_sync(), and test_sync().

#define OPS_FORMAT   gettext_noop("%13.3f ops/sec %6.0f usecs/op\n")

Definition at line 30 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:65
static bool alarm_triggered
Definition: pg_test_fsync.c:72

Definition at line 35 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:70

Definition at line 56 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 31 of file pg_test_fsync.c.

Referenced by print_elapse().

#define XLOG_BLCKSZ_K   (XLOG_BLCKSZ / 1024)

Definition at line 25 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 606 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().

607 {
608  fprintf(stderr, _("%s: %s\n"), _(str), strerror(errno));
609  exit(1);
610 }
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 139 of file pg_test_fsync.c.

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

Referenced by main().

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

Definition at line 99 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(), and test_sync().

100 {
101  set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_test_fsync"));
102  progname = get_progname(argv[0]);
103 
104  handle_args(argc, argv);
105 
106  /* Prevent leaving behind the test file */
107  pqsignal(SIGINT, signal_cleanup);
108  pqsignal(SIGTERM, signal_cleanup);
109 #ifndef WIN32
111 #endif
112 #ifdef SIGHUP
113  /* Not defined on win32 */
115 #endif
116 
117  prepare_buf();
118 
119  test_open();
120 
121  /* Test using 1 XLOG_BLCKSZ write */
122  test_sync(1);
123 
124  /* Test using 2 XLOG_BLCKSZ writes */
125  test_sync(2);
126 
127  test_open_syncs();
128 
130 
131  test_non_sync();
132 
133  unlink(filename);
134 
135  return 0;
136 }
static void test_sync(int writes_per_op)
static char * filename
Definition: pg_test_fsync.c:69
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:63
#define PG_TEXTDOMAIN(domain)
Definition: c.h:1018
static void test_open_syncs(void)
static void test_non_sync(void)
#define SIGHUP
Definition: win32.h:188
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:194
static void handle_args(int argc, char *argv[])
static void prepare_buf ( void  )
static

Definition at line 207 of file pg_test_fsync.c.

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

Referenced by main().

208 {
209  int ops;
210 
211  /* write random data into buffer */
212  for (ops = 0; ops < DEFAULT_XLOG_SEG_SIZE; ops++)
213  full_buf[ops] = random();
214 
215  buf = (char *) TYPEALIGN(XLOG_BLCKSZ, full_buf);
216 }
long random(void)
Definition: random.c:22
#define DEFAULT_XLOG_SEG_SIZE
static char full_buf[DEFAULT_XLOG_SEG_SIZE]
Definition: pg_test_fsync.c:67
static char * buf
Definition: pg_test_fsync.c:67
#define TYPEALIGN(ALIGNVAL, LEN)
Definition: c.h:569
static void print_elapse ( struct timeval  start_t,
struct timeval  stop_t,
int  ops 
)
static

Definition at line 578 of file pg_test_fsync.c.

References _, OPS_FORMAT, and USECS_SEC.

579 {
580  double total_time = (stop_t.tv_sec - start_t.tv_sec) +
581  (stop_t.tv_usec - start_t.tv_usec) * 0.000001;
582  double per_second = ops / total_time;
583  double avg_op_time_us = (total_time / ops) * USECS_SEC;
584 
585  printf(_(OPS_FORMAT), per_second, avg_op_time_us);
586 }
#define USECS_SEC
Definition: pg_test_fsync.c:31
static struct timeval start_t stop_t
Definition: pg_test_fsync.c:70
#define OPS_FORMAT
Definition: pg_test_fsync.c:30
#define _(x)
Definition: elog.c:84
static void process_alarm ( int  sig)
static

Definition at line 590 of file pg_test_fsync.c.

References alarm_triggered.

Referenced by main().

591 {
592  alarm_triggered = true;
593 }
static bool alarm_triggered
Definition: pg_test_fsync.c:72
static void signal_cleanup ( int  sig)
static

Definition at line 548 of file pg_test_fsync.c.

References filename, and needs_unlink.

Referenced by main().

549 {
550  /* Delete the file if it exists. Ignore errors */
551  if (needs_unlink)
552  unlink(filename);
553  /* Finish incomplete line on stdout */
554  puts("");
555  exit(signum);
556 }
static char * filename
Definition: pg_test_fsync.c:69
static int needs_unlink
Definition: pg_test_fsync.c:66
static void test_file_descriptor_sync ( void  )
static

Definition at line 454 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().

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

Definition at line 523 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().

524 {
525  int tmpfile,
526  ops;
527 
528  /*
529  * Test a simple write without fsync
530  */
531  printf(_("\nNon-sync'ed %dkB writes:\n"), XLOG_BLCKSZ_K);
532  printf(LABEL_FORMAT, "write");
533  fflush(stdout);
534 
535  START_TIMER;
536  for (ops = 0; alarm_triggered == false; ops++)
537  {
538  if ((tmpfile = open(filename, O_RDWR, 0)) == -1)
539  die("could not open output file");
540  if (write(tmpfile, buf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
541  die("write failed");
542  close(tmpfile);
543  }
544  STOP_TIMER;
545 }
static char * filename
Definition: pg_test_fsync.c:69
#define write(a, b, c)
Definition: win32.h:14
static void die(const char *str)
static bool alarm_triggered
Definition: pg_test_fsync.c:72
static char * buf
Definition: pg_test_fsync.c:67
#define XLOG_BLCKSZ_K
Definition: pg_test_fsync.c:25
#define STOP_TIMER
Definition: pg_test_fsync.c:56
#define LABEL_FORMAT
Definition: pg_test_fsync.c:27
#define START_TIMER
Definition: pg_test_fsync.c:35
#define close(a)
Definition: win32.h:12
#define _(x)
Definition: elog.c:84
static void test_open ( void  )
static

Definition at line 219 of file pg_test_fsync.c.

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

Referenced by main().

220 {
221  int tmpfile;
222 
223  /*
224  * test if we can open the target file
225  */
226  if ((tmpfile = open(filename, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)) == -1)
227  die("could not open output file");
228  needs_unlink = 1;
229  if (write(tmpfile, full_buf, DEFAULT_XLOG_SEG_SIZE) !=
231  die("write failed");
232 
233  /* fsync now so that dirty buffers don't skew later tests */
234  if (fsync(tmpfile) != 0)
235  die("fsync failed");
236 
237  close(tmpfile);
238 }
static char * filename
Definition: pg_test_fsync.c:69
#define write(a, b, c)
Definition: win32.h:14
#define DEFAULT_XLOG_SEG_SIZE
static char full_buf[DEFAULT_XLOG_SEG_SIZE]
Definition: pg_test_fsync.c:67
static void die(const char *str)
#define fsync(fd)
Definition: win32.h:62
static int needs_unlink
Definition: pg_test_fsync.c:66
#define close(a)
Definition: win32.h:12
static void test_open_sync ( const char *  msg,
int  writes_size 
)
static

Definition at line 419 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().

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

Definition at line 402 of file pg_test_fsync.c.

References _, and test_open_sync().

Referenced by main().

403 {
404  printf(_("\nCompare open_sync with different write sizes:\n"));
405  printf(_("(This is designed to compare the cost of writing 16kB in different write\n"
406  "open_sync sizes.)\n"));
407 
408  test_open_sync(_(" 1 * 16kB open_sync write"), 16);
409  test_open_sync(_(" 2 * 8kB open_sync writes"), 8);
410  test_open_sync(_(" 4 * 4kB open_sync writes"), 4);
411  test_open_sync(_(" 8 * 2kB open_sync writes"), 2);
412  test_open_sync(_("16 * 1kB open_sync writes"), 1);
413 }
#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 241 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().

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

Variable Documentation

bool alarm_triggered = false
static
char * buf
static

Definition at line 67 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_kill_items(), _hash_next(), _hash_readpage(), _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(), autoprewarm_database_main(), 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(), CheckSCRAMAuth(), 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(), DescribeQuery(), 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_password(), exec_command_sf_sv(), ExecBuildSlotPartitionKeyDescription(), ExecBuildSlotValueDescription(), ExecEvalXmlExpr(), 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_range_partbound_string(), get_raw_page_internal(), get_rule_expr(), get_rule_expr_funccall(), 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(), heap_lock_updated_tuple_rec(), hmac_finish(), hstore_recv(), hstore_send(), hstorePairs(), ignore_boolean_expression(), 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(), is_true_boolean_expression(), 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_statisticsobj_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_saslprep(), 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(), print_wchar_str(), PrintBufferLeakWarning(), PrintQueryStatus(), printRemoteParam(), printRemotePlaceholder(), printsimple(), printsimple_startup(), printSubscripts(), printtup(), printtup_20(), printtup_internal_20(), process_file(), process_pipe_input(), processIndirection(), ProcessStartupPacket(), ProcessTwoPhaseBuffer(), ProcSleep(), prompt_for_password(), psql_get_variable(), 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(), restoreTwoPhaseData(), revmap_physical_extend(), rm_redo_error_callback(), run_crypt_des(), sanitize_char(), search_directory(), send_message_to_frontend(), send_message_to_server_log(), sendAuthRequest(), SendBackupHeader(), SendCopyBegin(), sendFile(), sendFileWithContent(), SendFunctionResult(), SendQuery(), SendTimeLineHistory(), SendXlogRecPtrResult(), sepgsql_audit_log(), serialize_deflist(), SetWALSegSize(), show_log_file_mode(), show_unix_socket_permissions(), ShowTransactionStateRec(), simple_prompt(), SortTocFromFile(), SPI_result_code_string(), SplitToVariants(), ssl_extension_info(), StandbyRecoverPreparedTransactions(), StandbyTransactionIdIsPrepared(), 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(), 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[DEFAULT_XLOG_SEG_SIZE]
static

Definition at line 67 of file pg_test_fsync.c.

Referenced by prepare_buf(), and test_open().

int needs_unlink = 0
static

Definition at line 66 of file pg_test_fsync.c.

Referenced by signal_cleanup(), and test_open().

const char* progname
static

Definition at line 63 of file pg_test_fsync.c.

Referenced by handle_args(), and main().

int secs_per_test = 5
static

Definition at line 65 of file pg_test_fsync.c.

Referenced by handle_args().

struct timeval start_t stop_t
static

Definition at line 70 of file pg_test_fsync.c.