Here is what I would consider a better test, imho :) /* * fsync-tester.c * * Written by Theodore Ts'o, 3/21/09. * * This file may be redistributed under the terms of the GNU Public * License, version 2. */ #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <time.h> #include <fcntl.h> #include <string.h> #define SIZE (32768*32) static float timeval_subtract(struct timeval *tv1, struct timeval *tv2) { return ((tv1->tv_sec - tv2->tv_sec) + ((float) (tv1->tv_usec - tv2->tv_usec)) / 1000000); } int main(int argc, char **argv) { int fd; struct timeval tv, tv2, tv3, tv4; char buf[SIZE]; fd = open("fsync-tester.tst-file", O_RDWR|O_CREAT); if (fd < 0) { perror("open"); exit(1); } memset(buf, 'a', SIZE); while (1) { pwrite(fd, buf, SIZE, 0); gettimeofday(&tv, NULL); fsync(fd); gettimeofday(&tv2, NULL); printf("fsync time: %5.4f\n", timeval_subtract(&tv2, &tv)); sleep(1); gettimeofday(&tv3, NULL); pread(fd, buf, SIZE, 0); gettimeofday(&tv4, NULL); printf("pread time: %5.4f\n", timeval_subtract(&tv4, &tv3)); sleep(1); } } --- fsync-tester.c 2010-09-11 17:25:53.000000000 +1000 +++ mine.c 2010-09-11 18:57:36.000000000 +1000 @@ -27,10 +27,10 @@ int main(int argc, char **argv) { int fd; - struct timeval tv, tv2; + struct timeval tv, tv2, tv3, tv4; char buf[SIZE]; - fd = open("fsync-tester.tst-file", O_WRONLY|O_CREAT); + fd = open("fsync-tester.tst-file", O_RDWR|O_CREAT); if (fd < 0) { perror("open"); exit(1); @@ -43,6 +43,12 @@ gettimeofday(&tv2, NULL); printf("fsync time: %5.4f\n", timeval_subtract(&tv2, &tv)); sleep(1); + + gettimeofday(&tv3, NULL); + pread(fd, buf, SIZE, 0); + gettimeofday(&tv4, NULL); + printf("pread time: %5.4f\n", timeval_subtract(&tv4, &tv3)); + sleep(1); } } This still isn't as good a test as I would like :) ./mine.out fsync time: 0.0264 pread time: 0.0009 fsync time: 0.0415 pread time: 0.0008 fsync time: 2.4119 pread time: 1.0698 fsync time: 19.5375 pread time: 0.0009 fsync time: 15.9053 pread time: 0.0009 fsync time: 6.3872 pread time: 3.6912 fsync time: 6.8910 pread time: 0.0099 fsync time: 4.0445 pread time: 0.3053 fsync time: 8.3816 pread time: 0.3386 fsync time: 6.0976 pread time: 0.0009 fsync time: 0.0236 pread time: 0.0008 fsync time: 0.0255 So when I try to do other things I see the pread time go way up :) _______________________________________________ dm-crypt mailing list dm-crypt@xxxxxxxx http://www.saout.de/mailman/listinfo/dm-crypt