From e5b401d4bf67a1704f28872d3abe09eaf65cdabe Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Wed, 18 Oct 2006 16:03:40 +0200 Subject: [PATCH] [PATCH] Sync and invalidate cache prior to running verify Make sure we re-read the contents from disk, not from memory. Signed-off-by: Jens Axboe --- filesetup.c | 40 ++++++++++++++++++++++++++++------------ fio.c | 11 ++++++++++- fio.h | 1 + os-freebsd.h | 7 ++++++- os-linux.h | 12 ++++++++++++ os-solaris.h | 7 ++++++- 6 files changed, 63 insertions(+), 15 deletions(-) diff --git a/filesetup.c b/filesetup.c index 04052bf3..4f3d6cdf 100644 --- a/filesetup.c +++ b/filesetup.c @@ -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 2b760ddd..5432e383 100644 --- 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 e279574a..6ecb11cf 100644 --- 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 diff --git a/os-freebsd.h b/os-freebsd.h index 6a4c11b6..01c5ce91 100644 --- a/os-freebsd.h +++ b/os-freebsd.h @@ -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) diff --git a/os-linux.h b/os-linux.h index 4c54c8cc..752d17e1 100644 --- a/os-linux.h +++ b/os-linux.h @@ -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)) diff --git a/os-solaris.h b/os-solaris.h index e7f4e4ee..898da18e 100644 --- a/os-solaris.h +++ b/os-solaris.h @@ -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) -- 2.25.1