Thread: test_fsync file overrun
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
This patch uses lseek to periodically restart at the beginning of the file, rather than writing past the end of it.
Cheers,
Jeff
Attachment
Jeff Janes wrote: > 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. Oh, I never noticed that the later tests kept appending to the file rather then overwriting it. I have applied the attached fix for CVS HEAD that just uses lseek() before each write group, as you suggested. I have backpatched it to 8.4.X because the original code created 16GB files in tests (yikes). -- Bruce Momjian <bruce@momjian.us> http://momjian.us EnterpriseDB http://enterprisedb.com + If your life is a hard drive, Christ can be your backup. + Index: src/tools/fsync/test_fsync.c =================================================================== RCS file: /cvsroot/pgsql/src/tools/fsync/test_fsync.c,v retrieving revision 1.24 diff -c -c -r1.24 test_fsync.c *** src/tools/fsync/test_fsync.c 10 Aug 2009 18:19:06 -0000 1.24 --- src/tools/fsync/test_fsync.c 21 Sep 2009 16:52:00 -0000 *************** *** 149,156 **** --- 149,160 ---- 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"); + if (lseek(tmpfile, 0, SEEK_SET) == -1) + die("seek failed"); + } gettimeofday(&elapse_t, NULL); close(tmpfile); printf("\tone 16k o_sync write "); *************** *** 167,172 **** --- 171,178 ---- die("write failed"); if (write(tmpfile, buf, WRITE_SIZE / 2) != WRITE_SIZE / 2) die("write failed"); + if (lseek(tmpfile, 0, SEEK_SET) == -1) + die("seek failed"); } gettimeofday(&elapse_t, NULL); close(tmpfile); *************** *** 188,195 **** --- 194,205 ---- die("Cannot open output file."); gettimeofday(&start_t, NULL); for (i = 0; i < loops; i++) + { if (write(tmpfile, buf, WRITE_SIZE / 2) != WRITE_SIZE / 2) die("write failed"); + if (lseek(tmpfile, 0, SEEK_SET) == -1) + die("seek failed"); + } gettimeofday(&elapse_t, NULL); close(tmpfile); printf("\topen o_dsync, write "); *************** *** 205,212 **** --- 215,226 ---- die("Cannot open output file."); gettimeofday(&start_t, NULL); for (i = 0; i < loops; i++) + { if (write(tmpfile, buf, WRITE_SIZE / 2) != WRITE_SIZE / 2) die("write failed"); + if (lseek(tmpfile, 0, SEEK_SET) == -1) + die("seek failed"); + } gettimeofday(&elapse_t, NULL); close(tmpfile); printf("\topen o_sync, write "); *************** *** 226,231 **** --- 240,247 ---- if (write(tmpfile, buf, WRITE_SIZE / 2) != WRITE_SIZE / 2) die("write failed"); fdatasync(tmpfile); + if (lseek(tmpfile, 0, SEEK_SET) == -1) + die("seek failed"); } gettimeofday(&elapse_t, NULL); close(tmpfile); *************** *** 246,251 **** --- 262,269 ---- die("write failed"); if (fsync(tmpfile) != 0) die("fsync failed"); + if (lseek(tmpfile, 0, SEEK_SET) == -1) + die("seek failed"); } gettimeofday(&elapse_t, NULL); close(tmpfile); *************** *** 269,274 **** --- 287,294 ---- die("write failed"); if (write(tmpfile, buf, WRITE_SIZE / 2) != WRITE_SIZE / 2) die("write failed"); + if (lseek(tmpfile, 0, SEEK_SET) == -1) + die("seek failed"); } gettimeofday(&elapse_t, NULL); close(tmpfile); *************** *** 290,295 **** --- 310,317 ---- die("write failed"); if (write(tmpfile, buf, WRITE_SIZE / 2) != WRITE_SIZE / 2) die("write failed"); + if (lseek(tmpfile, 0, SEEK_SET) == -1) + die("seek failed"); } gettimeofday(&elapse_t, NULL); close(tmpfile); *************** *** 310,315 **** --- 332,339 ---- if (write(tmpfile, buf, WRITE_SIZE / 2) != WRITE_SIZE / 2) die("write failed"); fdatasync(tmpfile); + if (lseek(tmpfile, 0, SEEK_SET) == -1) + die("seek failed"); } gettimeofday(&elapse_t, NULL); close(tmpfile); *************** *** 332,337 **** --- 356,363 ---- die("write failed"); if (fsync(tmpfile) != 0) die("fsync failed"); + if (lseek(tmpfile, 0, SEEK_SET) == -1) + die("seek failed"); } gettimeofday(&elapse_t, NULL); close(tmpfile);