test_fsync in tools/fsync pre-creates a 16MB file. If it is given a number of iterations greater than 1024 (like one might use if trying to see what happens when NVRAM gets filled, or on a journaling file system), than one of the writes being timed will have to extend the size of the pre-created test file, which can greatly skew the results.
This patch uses lseek to periodically restart at the beginning of the file, rather than writing past the end of it. Cheers, Jeff
Index: test_fsync.c =================================================================== RCS file: /home/jjanes/pgrepo/pgsql/src/tools/fsync/test_fsync.c,v retrieving revision 1.24 diff -c -r1.24 test_fsync.c *** test_fsync.c 10 Aug 2009 18:19:06 -0000 1.24 --- test_fsync.c 13 Sep 2009 17:29:27 -0000 *************** *** 31,36 **** --- 31,37 ---- #endif #define WRITE_SIZE (16 * 1024) /* 16k */ + #define REWIND_FILE if (i%1020 == 1019 && (-1 == lseek(tmpfile,0,SEEK_SET))) die ("Cannot lseek."); void die(char *str); void print_elapse(struct timeval start_t, struct timeval elapse_t); *************** *** 148,156 **** if ((tmpfile = open(filename, O_RDWR | OPEN_SYNC_FLAG, 0)) == -1) die("Cannot open output file."); gettimeofday(&start_t, NULL); ! for (i = 0; i < loops; i++) if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE) die("write failed"); gettimeofday(&elapse_t, NULL); close(tmpfile); printf("\tone 16k o_sync write "); --- 149,160 ---- if ((tmpfile = open(filename, O_RDWR | OPEN_SYNC_FLAG, 0)) == -1) die("Cannot open output file."); gettimeofday(&start_t, NULL); ! for (i = 0; i < loops; i++) ! { ! REWIND_FILE; if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE) die("write failed"); + }; gettimeofday(&elapse_t, NULL); close(tmpfile); printf("\tone 16k o_sync write "); *************** *** 163,168 **** --- 167,173 ---- gettimeofday(&start_t, NULL); for (i = 0; i < loops; i++) { + REWIND_FILE; if (write(tmpfile, buf, WRITE_SIZE / 2) != WRITE_SIZE / 2) die("write failed"); if (write(tmpfile, buf, WRITE_SIZE / 2) != WRITE_SIZE / 2) *************** *** 188,195 **** --- 193,203 ---- die("Cannot open output file."); gettimeofday(&start_t, NULL); for (i = 0; i < loops; i++) + { + REWIND_FILE; if (write(tmpfile, buf, WRITE_SIZE / 2) != WRITE_SIZE / 2) die("write failed"); + } gettimeofday(&elapse_t, NULL); close(tmpfile); printf("\topen o_dsync, write "); *************** *** 205,212 **** --- 213,223 ---- die("Cannot open output file."); gettimeofday(&start_t, NULL); for (i = 0; i < loops; i++) + { + REWIND_FILE; if (write(tmpfile, buf, WRITE_SIZE / 2) != WRITE_SIZE / 2) die("write failed"); + } gettimeofday(&elapse_t, NULL); close(tmpfile); printf("\topen o_sync, write "); *************** *** 223,228 **** --- 234,240 ---- gettimeofday(&start_t, NULL); for (i = 0; i < loops; i++) { + REWIND_FILE; if (write(tmpfile, buf, WRITE_SIZE / 2) != WRITE_SIZE / 2) die("write failed"); fdatasync(tmpfile); *************** *** 242,247 **** --- 254,260 ---- gettimeofday(&start_t, NULL); for (i = 0; i < loops; i++) { + REWIND_FILE; if (write(tmpfile, buf, WRITE_SIZE / 2) != WRITE_SIZE / 2) die("write failed"); if (fsync(tmpfile) != 0) *************** *** 265,270 **** --- 278,284 ---- gettimeofday(&start_t, NULL); for (i = 0; i < loops; i++) { + REWIND_FILE; if (write(tmpfile, buf, WRITE_SIZE / 2) != WRITE_SIZE / 2) die("write failed"); if (write(tmpfile, buf, WRITE_SIZE / 2) != WRITE_SIZE / 2) *************** *** 286,291 **** --- 300,306 ---- gettimeofday(&start_t, NULL); for (i = 0; i < loops; i++) { + REWIND_FILE; if (write(tmpfile, buf, WRITE_SIZE / 2) != WRITE_SIZE / 2) die("write failed"); if (write(tmpfile, buf, WRITE_SIZE / 2) != WRITE_SIZE / 2) *************** *** 305,310 **** --- 320,326 ---- gettimeofday(&start_t, NULL); for (i = 0; i < loops; i++) { + REWIND_FILE; if (write(tmpfile, buf, WRITE_SIZE / 2) != WRITE_SIZE / 2) die("write failed"); if (write(tmpfile, buf, WRITE_SIZE / 2) != WRITE_SIZE / 2) *************** *** 326,331 **** --- 342,348 ---- gettimeofday(&start_t, NULL); for (i = 0; i < loops; i++) { + REWIND_FILE; if (write(tmpfile, buf, WRITE_SIZE / 2) != WRITE_SIZE / 2) die("write failed"); if (write(tmpfile, buf, WRITE_SIZE / 2) != WRITE_SIZE / 2)
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers