1 #define _XOPEN_SOURCE 500
11 static struct timeval tp1,tp2;
13 static void start_timer()
15 gettimeofday(&tp1,NULL);
18 static double end_timer()
20 gettimeofday(&tp2,NULL);
21 return (tp2.tv_sec + (tp2.tv_usec*1.0e-6)) -
22 (tp1.tv_sec + (tp1.tv_usec*1.0e-6));
25 int main(int argc, const char *argv[])
30 const char *fname = "fsync.dat";
33 fd = open(fname, O_RDWR|O_CREAT|O_EXCL, 0600);
39 while (size < 100*1024*1024) {
43 p = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
44 if (p == (void *)-1) {
50 msync(p, size, MS_SYNC);
54 while (end_timer() < 2) {
56 pwrite(fd, &count, 1, size-1);
59 memset(p+size-100, count, 100);
60 // msync(p, size, MS_SYNC);
61 msync(p+size-4096, 4096, MS_SYNC);
66 printf("%7d %.2f us (count=%d)\n",
67 size, 1.0e6 * end_timer() / count, count);