@@ -47,6 +47,7 @@ void test_open(void);
47
47
void test_non_sync (void );
48
48
void test_sync (int writes_per_op );
49
49
void test_open_syncs (void );
50
+ void test_open_sync (const char * msg , int writes_size );
50
51
void test_file_descriptor_sync (void );
51
52
void print_elapse (struct timeval start_t , struct timeval stop_t );
52
53
void die (char * str );
@@ -61,8 +62,6 @@ main(int argc, char *argv[])
61
62
62
63
test_open ();
63
64
64
- test_non_sync ();
65
-
66
65
/* Test using 1 8k write */
67
66
test_sync (1 );
68
67
@@ -73,6 +72,8 @@ main(int argc, char *argv[])
73
72
74
73
test_file_descriptor_sync ();
75
74
75
+ test_non_sync ();
76
+
76
77
unlink (filename );
77
78
78
79
return 0 ;
@@ -105,7 +106,7 @@ handle_args(int argc, char *argv[])
105
106
}
106
107
107
108
while ((option = getopt_long (argc , argv , "f:o:" ,
108
- long_options , & optindex )) != -1 )
109
+ long_options , & optindex )) != -1 )
109
110
{
110
111
switch (option )
111
112
{
@@ -126,7 +127,7 @@ handle_args(int argc, char *argv[])
126
127
}
127
128
}
128
129
129
- printf ("%d operations per test\n\n " , ops_per_test );
130
+ printf ("%d operations per test\n" , ops_per_test );
130
131
}
131
132
132
133
void
@@ -161,58 +162,26 @@ test_open(void)
161
162
close (tmpfile );
162
163
}
163
164
164
- void
165
- test_non_sync (void )
166
- {
167
- int tmpfile , ops ;
168
-
169
- /*
170
- * Test a simple write without fsync
171
- */
172
- printf ("Simple non-sync'ed write:\n" );
173
- printf (LABEL_FORMAT , "8k write" );
174
- fflush (stdout );
175
-
176
- gettimeofday (& start_t , NULL );
177
- for (ops = 0 ; ops < ops_per_test ; ops ++ )
178
- {
179
- if ((tmpfile = open (filename , O_RDWR , 0 )) == -1 )
180
- die ("Cannot open output file." );
181
- if (write (tmpfile , buf , WRITE_SIZE ) != WRITE_SIZE )
182
- die ("write failed" );
183
- close (tmpfile );
184
- }
185
- gettimeofday (& stop_t , NULL );
186
- print_elapse (start_t , stop_t );
187
- }
188
-
189
165
void
190
166
test_sync (int writes_per_op )
191
167
{
192
168
int tmpfile , ops , writes ;
193
169
bool fs_warning = false;
194
170
195
171
if (writes_per_op == 1 )
196
- printf ("\nCompare file sync methods using one write:\n" );
172
+ printf ("\nCompare file sync methods using one 8k write:\n" );
197
173
else
198
- printf ("\nCompare file sync methods using two writes:\n" );
174
+ printf ("\nCompare file sync methods using two 8k writes:\n" );
199
175
printf ("(in wal_sync_method preference order, except fdatasync\n" );
200
176
printf ("is Linux's default)\n" );
201
177
202
178
/*
203
179
* Test open_datasync if available
204
180
*/
205
181
#ifdef OPEN_DATASYNC_FLAG
206
- if (writes_per_op == 1 )
207
- printf (LABEL_FORMAT , "open_datasync 8k write"
208
- #if PG_O_DIRECT != 0
209
- "*"
210
- #endif
211
- );
212
- else
213
- printf (LABEL_FORMAT , "2 open_datasync 8k writes"
182
+ printf (LABEL_FORMAT , "open_datasync"
214
183
#if PG_O_DIRECT != 0
215
- "*"
184
+ " (non-direct I/O) *"
216
185
#endif
217
186
);
218
187
fflush (stdout );
@@ -243,10 +212,7 @@ test_sync(int writes_per_op)
243
212
}
244
213
else
245
214
{
246
- if (writes_per_op == 1 )
247
- printf (LABEL_FORMAT , "open_datasync 8k direct I/O write" );
248
- else
249
- printf (LABEL_FORMAT , "2 open_datasync 8k direct I/O writes" );
215
+ printf (LABEL_FORMAT , "open_datasync (direct I/O)" );
250
216
fflush (stdout );
251
217
252
218
gettimeofday (& start_t , NULL );
@@ -262,8 +228,6 @@ test_sync(int writes_per_op)
262
228
close (tmpfile );
263
229
print_elapse (start_t , stop_t );
264
230
}
265
- #else
266
- printf (NA_FORMAT , "o_direct" , "n/a\n" );
267
231
#endif
268
232
269
233
#else
@@ -274,10 +238,7 @@ test_sync(int writes_per_op)
274
238
* Test fdatasync if available
275
239
*/
276
240
#ifdef HAVE_FDATASYNC
277
- if (writes_per_op == 1 )
278
- printf (LABEL_FORMAT , "8k write, fdatasync" );
279
- else
280
- printf (LABEL_FORMAT , "8k write, 8k write, fdatasync" );
241
+ printf (LABEL_FORMAT , "fdatasync" );
281
242
fflush (stdout );
282
243
283
244
if ((tmpfile = open (filename , O_RDWR , 0 )) == -1 )
@@ -302,10 +263,7 @@ test_sync(int writes_per_op)
302
263
/*
303
264
* Test fsync
304
265
*/
305
- if (writes_per_op == 1 )
306
- printf (LABEL_FORMAT , "8k write, fsync" );
307
- else
308
- printf (LABEL_FORMAT , "8k write, 8k write, fsync" );
266
+ printf (LABEL_FORMAT , "fsync" );
309
267
fflush (stdout );
310
268
311
269
if ((tmpfile = open (filename , O_RDWR , 0 )) == -1 )
@@ -329,10 +287,7 @@ test_sync(int writes_per_op)
329
287
* If fsync_writethrough is available, test as well
330
288
*/
331
289
#ifdef HAVE_FSYNC_WRITETHROUGH
332
- if (writes_per_op == 1 )
333
- printf (LABEL_FORMAT , "8k write, fsync_writethrough" );
334
- else
335
- printf (LABEL_FORMAT , "8k write, 8k write, fsync_writethrough" );
290
+ printf (LABEL_FORMAT , "fsync_writethrough" );
336
291
fflush (stdout );
337
292
338
293
if ((tmpfile = open (filename , O_RDWR , 0 )) == -1 )
@@ -359,16 +314,9 @@ test_sync(int writes_per_op)
359
314
* Test open_sync if available
360
315
*/
361
316
#ifdef OPEN_SYNC_FLAG
362
- if (writes_per_op == 1 )
363
- printf (LABEL_FORMAT , "open_sync 8k write"
364
- #if PG_O_DIRECT != 0
365
- "*"
366
- #endif
367
- );
368
- else
369
- printf (LABEL_FORMAT , "2 open_sync 8k writes"
317
+ printf (LABEL_FORMAT , "open_sync"
370
318
#if PG_O_DIRECT != 0
371
- "*"
319
+ " (non-direct I/O) *"
372
320
#endif
373
321
);
374
322
fflush (stdout );
@@ -399,10 +347,7 @@ test_sync(int writes_per_op)
399
347
}
400
348
else
401
349
{
402
- if (writes_per_op == 1 )
403
- printf (LABEL_FORMAT , "open_sync 8k direct I/O write" );
404
- else
405
- printf (LABEL_FORMAT , "2 open_sync 8k direct I/O writes" );
350
+ printf (LABEL_FORMAT , "open_sync (direct I/O)" );
406
351
fflush (stdout );
407
352
408
353
gettimeofday (& start_t , NULL );
@@ -418,8 +363,6 @@ test_sync(int writes_per_op)
418
363
close (tmpfile );
419
364
print_elapse (start_t , stop_t );
420
365
}
421
- #else
422
- printf (NA_FORMAT , "o_direct" , "n/a\n" );
423
366
#endif
424
367
425
368
#else
@@ -428,7 +371,7 @@ test_sync(int writes_per_op)
428
371
429
372
#if defined(OPEN_DATASYNC_FLAG ) || defined(OPEN_SYNC_FLAG )
430
373
if (PG_O_DIRECT != 0 )
431
- printf ("* This non-direct I/O option is not used by Postgres.\n" );
374
+ printf ("* This non-direct I/O mode is not used by Postgres.\n" );
432
375
#endif
433
376
434
377
if (fs_warning )
@@ -441,14 +384,22 @@ test_sync(int writes_per_op)
441
384
void
442
385
test_open_syncs (void )
443
386
{
444
- int tmpfile , ops ;
387
+ printf ("\nCompare open_sync with different write sizes:\n" );
388
+ printf ("(This is designed to compare the cost of writing 16k\n" );
389
+ printf ("in different write open_sync sizes.)\n" );
390
+
391
+ test_open_sync (" 1 16k open_sync write" , 16 );
392
+ test_open_sync (" 2 8k open_sync writes" , 8 );
393
+ test_open_sync (" 4 4k open_sync writes" , 4 );
394
+ test_open_sync (" 8 2k open_sync writes" , 2 );
395
+ test_open_sync ("16 1k open_sync writes" , 1 );
396
+ }
445
397
446
- /*
447
- * Compare 1 to 2 writes
448
- */
449
- printf ("\nCompare open_sync with different sizes:\n" );
450
- printf ("(This is designed to compare the cost of one large\n" );
451
- printf ("sync'ed write and two smaller sync'ed writes.)\n" );
398
+
399
+ void
400
+ test_open_sync (const char * msg , int writes_size )
401
+ {
402
+ int tmpfile , ops , writes ;
452
403
453
404
/*
454
405
* Test open_sync with different size files
@@ -458,14 +409,15 @@ test_open_syncs(void)
458
409
printf (NA_FORMAT , "o_direct" , "n/a**\n" );
459
410
else
460
411
{
461
- printf (LABEL_FORMAT , "open_sync 16k write" );
412
+ printf (LABEL_FORMAT , msg );
462
413
fflush (stdout );
463
414
464
415
gettimeofday (& start_t , NULL );
465
416
for (ops = 0 ; ops < ops_per_test ; ops ++ )
466
417
{
467
- if (write (tmpfile , buf , WRITE_SIZE * 2 ) != WRITE_SIZE * 2 )
468
- die ("write failed" );
418
+ for (writes = 0 ; writes < 16 / writes_size ; writes ++ )
419
+ if (write (tmpfile , buf , writes_size ) != writes_size )
420
+ die ("write failed" );
469
421
if (lseek (tmpfile , 0 , SEEK_SET ) == -1 )
470
422
die ("seek failed" );
471
423
}
@@ -474,27 +426,6 @@ test_open_syncs(void)
474
426
print_elapse (start_t , stop_t );
475
427
}
476
428
477
- if ((tmpfile = open (filename , O_RDWR | OPEN_SYNC_FLAG | PG_O_DIRECT , 0 )) == -1 )
478
- printf (NA_FORMAT , "o_direct" , "n/a**\n" );
479
- else
480
- {
481
- printf (LABEL_FORMAT , "2 open_sync 8k writes" );
482
- fflush (stdout );
483
-
484
- gettimeofday (& start_t , NULL );
485
- for (ops = 0 ; ops < ops_per_test ; ops ++ )
486
- {
487
- if (write (tmpfile , buf , WRITE_SIZE ) != WRITE_SIZE )
488
- die ("write failed" );
489
- if (write (tmpfile , buf , WRITE_SIZE ) != WRITE_SIZE )
490
- die ("write failed" );
491
- if (lseek (tmpfile , 0 , SEEK_SET ) == -1 )
492
- die ("seek failed" );
493
- }
494
- gettimeofday (& stop_t , NULL );
495
- close (tmpfile );
496
- print_elapse (start_t , stop_t );
497
- }
498
429
#else
499
430
printf (NA_FORMAT , "open_sync" , "n/a\n" );
500
431
#endif
@@ -520,7 +451,7 @@ test_file_descriptor_sync(void)
520
451
* first write, fsync and close, which is the
521
452
* normal behavior without multiple descriptors
522
453
*/
523
- printf (LABEL_FORMAT , "8k write, fsync, close" );
454
+ printf (LABEL_FORMAT , "write, fsync, close" );
524
455
fflush (stdout );
525
456
526
457
gettimeofday (& start_t , NULL );
@@ -549,7 +480,7 @@ test_file_descriptor_sync(void)
549
480
* This simulates processes fsyncing each other's
550
481
* writes.
551
482
*/
552
- printf (LABEL_FORMAT , "8k write, close, fsync" );
483
+ printf (LABEL_FORMAT , "write, close, fsync" );
553
484
fflush (stdout );
554
485
555
486
gettimeofday (& start_t , NULL );
@@ -572,6 +503,31 @@ test_file_descriptor_sync(void)
572
503
573
504
}
574
505
506
+ void
507
+ test_non_sync (void )
508
+ {
509
+ int tmpfile , ops ;
510
+
511
+ /*
512
+ * Test a simple write without fsync
513
+ */
514
+ printf ("\nNon-sync'ed 8k writes:\n" );
515
+ printf (LABEL_FORMAT , "write" );
516
+ fflush (stdout );
517
+
518
+ gettimeofday (& start_t , NULL );
519
+ for (ops = 0 ; ops < ops_per_test ; ops ++ )
520
+ {
521
+ if ((tmpfile = open (filename , O_RDWR , 0 )) == -1 )
522
+ die ("Cannot open output file." );
523
+ if (write (tmpfile , buf , WRITE_SIZE ) != WRITE_SIZE )
524
+ die ("write failed" );
525
+ close (tmpfile );
526
+ }
527
+ gettimeofday (& stop_t , NULL );
528
+ print_elapse (start_t , stop_t );
529
+ }
530
+
575
531
/*
576
532
* print out the writes per second for tests
577
533
*/
0 commit comments