From a1c58075279454a91ec43366846b93e8dcf9753c Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Tue, 4 Aug 2009 23:17:02 +0200 Subject: [PATCH] Add strong madvise() hint for cache pruning Signed-off-by: Jens Axboe --- filesetup.c | 7 +++++-- os/os-freebsd.h | 4 ++++ os/os-linux.h | 4 ++++ os/os-solaris.h | 4 ++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/filesetup.c b/filesetup.c index d7c83a79..f8f81d2b 100644 --- a/filesetup.c +++ b/filesetup.c @@ -303,9 +303,12 @@ static int __file_invalidate_cache(struct thread_data *td, struct fio_file *f, /* * FIXME: add blockdev flushing too */ - if (f->mmap_ptr) + if (f->mmap_ptr) { ret = madvise(f->mmap_ptr, f->mmap_sz, MADV_DONTNEED); - else if (f->filetype == FIO_TYPE_FILE) { +#ifdef FIO_MADV_FREE + (void) madvise(f->mmap_ptr, f->mmap_sz, FIO_MADV_FREE); +#endif + } else if (f->filetype == FIO_TYPE_FILE) { ret = fadvise(f->fd, off, len, POSIX_FADV_DONTNEED); } else if (f->filetype == FIO_TYPE_BD) { ret = blockdev_invalidate_cache(f->fd); diff --git a/os/os-freebsd.h b/os/os-freebsd.h index 88de7138..26bb8a09 100644 --- a/os/os-freebsd.h +++ b/os/os-freebsd.h @@ -51,4 +51,8 @@ static inline long os_random_long(os_random_state_t *rs) return val; } +#ifdef MADV_FREE +#define FIO_MADV_FREE MADV_FREE +#endif + #endif diff --git a/os/os-linux.h b/os/os-linux.h index dd9c5aaf..e4c4c3fd 100644 --- a/os/os-linux.h +++ b/os/os-linux.h @@ -250,6 +250,10 @@ static inline int fio_lookup_raw(dev_t dev, int *majdev, int *mindev) #define FIO_O_NOATIME 0 #endif +#ifdef MADV_REMOVE +#define FIO_MADV_FREE MADV_REMOVE +#endif + #define CACHE_LINE_FILE \ "/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size" diff --git a/os/os-solaris.h b/os/os-solaris.h index 943d387d..5029d38f 100644 --- a/os/os-solaris.h +++ b/os/os-solaris.h @@ -108,4 +108,8 @@ static inline int fio_cpuset_exit(os_cpu_mask_t *mask) */ #define FIO_MAX_CPUS 16384 +#ifdef MADV_FREE +#define FIO_MADV_FREE MADV_FREE +#endif + #endif -- 2.25.1