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
Attachments:
test_fsync_v1.patchtext/x-diff; charset=US-ASCII; name=test_fsync_v1.patchDownload
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)
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. +
Attachments:
/rtmp/difftext/x-diffDownload
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);