[PATCH] Sync and invalidate cache prior to running verify
authorJens Axboe <jens.axboe@oracle.com>
Wed, 18 Oct 2006 14:03:40 +0000 (16:03 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Wed, 18 Oct 2006 14:03:40 +0000 (16:03 +0200)
Make sure we re-read the contents from disk, not from memory.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
filesetup.c
fio.c
fio.h
os-freebsd.h
os-linux.h
os-solaris.h

index 04052bf368e6a0ebd2fb17e9af1e1c57fcf13f4b..4f3d6cdf7ea4e4e62915343e00e2c5ede8bb52bd 100644 (file)
@@ -183,6 +183,30 @@ static int get_file_size(struct thread_data *td, struct fio_file *f)
        return 0;
 }
 
+int file_invalidate_cache(struct thread_data *td, struct fio_file *f)
+{
+       int ret = 0;
+
+       /*
+        * FIXME: add blockdev flushing too
+        */
+       if (td->io_ops->flags & FIO_MMAPIO)
+               ret = madvise(f->mmap, f->file_size, MADV_DONTNEED);
+       else if (td->filetype == FIO_TYPE_FILE)
+               ret = fadvise(f->fd, f->file_offset, f->file_size, POSIX_FADV_DONTNEED);
+       else if (td->filetype == FIO_TYPE_BD)
+               ret = blockdev_invalidate_cache(f->fd);
+       else if (td->filetype == FIO_TYPE_CHAR)
+               ret = 0;
+
+       if (ret < 0) {
+               td_verror(td, errno);
+               return 1;
+       }
+
+       return 0;
+}
+
 static int __setup_file_mmap(struct thread_data *td, struct fio_file *f)
 {
        int flags;
@@ -204,12 +228,8 @@ static int __setup_file_mmap(struct thread_data *td, struct fio_file *f)
                return 1;
        }
 
-       if (td->invalidate_cache) {
-               if (madvise(f->mmap, f->file_size, MADV_DONTNEED) < 0) {
-                       td_verror(td, errno);
-                       return 1;
-               }
-       }
+       if (td->invalidate_cache && file_invalidate_cache(td, f))
+               return 1;
 
        if (td->sequential) {
                if (madvise(f->mmap, f->file_size, MADV_SEQUENTIAL) < 0) {
@@ -242,12 +262,8 @@ static int setup_files_mmap(struct thread_data *td)
 
 static int __setup_file_plain(struct thread_data *td, struct fio_file *f)
 {
-       if (td->invalidate_cache) {
-               if (fadvise(f->fd, f->file_offset, f->file_size, POSIX_FADV_DONTNEED) < 0) {
-                       td_verror(td, errno);
-                       return 1;
-               }
-       }
+       if (td->invalidate_cache && file_invalidate_cache(td, f))
+               return 1;
 
        if (td->sequential) {
                if (fadvise(f->fd, f->file_offset, f->file_size, POSIX_FADV_SEQUENTIAL) < 0) {
diff --git a/fio.c b/fio.c
index 2b760ddd4beb0c56244637a626284b6faa47d9f8..5432e383d439319eb918b3dd4162c2df774b0337 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -563,7 +563,16 @@ void do_verify(struct thread_data *td)
        struct io_u *io_u, *v_io_u = NULL;
        struct io_completion_data icd;
        struct fio_file *f;
-       int ret;
+       int ret, i;
+
+       /*
+        * sync io first and invalidate cache, to make sure we really
+        * read from disk.
+        */
+       for_each_file(td, f, i) {
+               td_io_sync(td, f);
+               file_invalidate_cache(td, f);
+       }
 
        td_set_runstate(td, TD_VERIFYING);
 
diff --git a/fio.h b/fio.h
index e279574a387026ab07e5b975df2a51fe5d384d0e..6ecb11cf9cae333cee0c9fb4333e6ca27993a610 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -448,6 +448,7 @@ extern int init_random_state(struct thread_data *);
  */
 extern void close_files(struct thread_data *);
 extern int setup_files(struct thread_data *);
+extern int file_invalidate_cache(struct thread_data *, struct fio_file *);
 
 /*
  * ETA/status stuff
index 6a4c11b634aa064ba37335b8e78f7c01858b9d98..01c5ce917b57d9501774cd80d8a84e82b6df6b35 100644 (file)
@@ -21,7 +21,12 @@ typedef unsigned int os_random_state_t;
  */
 static inline int blockdev_size(int fd, unsigned long long *bytes)
 {
-       return 1;
+       return EINVAL;
+}
+
+static inline int blockdev_invalidate_cache(int fd)
+{
+       return EINVAL;
 }
 
 static inline unsigned long long os_phys_mem(void)
index 4c54c8ccc6f0991af3dfbf4edd16d3267c45e0ea..752d17e1e84db3af75726560574aaa20b712a8e1 100644 (file)
@@ -84,6 +84,18 @@ enum {
 #define BLKGETSIZE64   _IOR(0x12,114,size_t)
 #endif
 
+#ifndef BLKFLSBUF
+#define BLKFLSBUF      _IO(0x12,97)
+#endif
+
+static inline int blockdev_invalidate_cache(int fd)
+{
+       if (!ioctl(fd, BLKFLSBUF))
+               return 0;
+
+       return errno;
+}
+
 static inline int blockdev_size(int fd, unsigned long long *bytes)
 {
        if (!ioctl(fd, BLKGETSIZE64, bytes))
index e7f4e4ee22b35fa36aab2174fb2d2e463f09f41d..898da18e988d205004f8826c8ba08d6768ac2352 100644 (file)
@@ -19,7 +19,12 @@ typedef unsigned int os_random_state_t;
  */
 static inline int blockdev_size(int fd, unsigned long long *bytes)
 {
-       return 1;
+       return EINVAL;
+}
+
+static inline int blockdev_invalidate_cache(int fd)
+{
+       return EINVAL;
 }
 
 static inline unsigned long long os_phys_mem(void)