Add strong madvise() hint for cache pruning
[fio.git] / filesetup.c
index 17bdd2639f6ce3cc75e192063c1c5276ba6076e0..f8f81d2b2a54e9a7692cdb41289ac8c5ff472c2c 100644 (file)
@@ -156,6 +156,9 @@ static int pre_read_file(struct thread_data *td, struct fio_file *f)
        unsigned int bs;
        char *b;
 
+       if (td->io_ops->flags & FIO_PIPEIO)
+               return 0;
+
        if (!fio_file_open(f)) {
                if (td->io_ops->open_file(td, f)) {
                        log_err("fio: cannot pre-read, failed to open file\n");
@@ -300,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);
@@ -608,7 +614,7 @@ int setup_files(struct thread_data *td)
                temp_stall_ts = 1;
                if (!terse_output)
                        log_info("%s: Laying out IO file(s) (%u file(s) /"
-                                " %LuMiB)\n", td->o.name, need_extend,
+                                " %LuMB)\n", td->o.name, need_extend,
                                        extend_size >> 20);
 
                for_each_file(td, f, i) {
@@ -710,8 +716,10 @@ void close_files(struct thread_data *td)
        struct fio_file *f;
        unsigned int i;
 
-       for_each_file(td, f, i)
-               td_io_close_file(td, f);
+       for_each_file(td, f, i) {
+               if (fio_file_open(f))
+                       td_io_close_file(td, f);
+       }
 }
 
 void close_and_free_files(struct thread_data *td)