From ab9d60be3fedb502011b2ed93cc8bc742a5f253c Mon Sep 17 00:00:00 2001 From: Herman Lee Date: Fri, 19 May 2017 16:02:19 -0700 Subject: [PATCH] Add posix_fadvise(FADV_DONTNEED) to flush buffered pages Summary: When InnoDB opens a .ibd or log file in O_DIRECT mode, request the os to flush the buffer cache. Otherwise, direct IO is serialized when buffered pages for the file existing within the filesystem cache. Reviewed By: alxyang Differential Revision: D5100237 fbshipit-source-id: bbbd3db --- storage/innobase/os/os0file.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/storage/innobase/os/os0file.cc b/storage/innobase/os/os0file.cc index 2125d2b607fa..42e35ddd562f 100644 --- a/storage/innobase/os/os0file.cc +++ b/storage/innobase/os/os0file.cc @@ -65,6 +65,11 @@ Created 10/21/1995 Heikki Tuuri #include #endif +/* Ignore posix_fadvise() on those platforms where it does not exist */ +#if defined __WIN__ +# define posix_fadvise(fd, offset, len, advice) /* nothing */ +#endif /* __WIN__ */ + #define max(a,b) ((a)>(b)?(a):(b)) /* Configurable histogram step sizes */ @@ -1703,6 +1708,11 @@ os_file_set_nocache( } return -1; } +#ifdef POSIX_FADV_DONTNEED + /* Request the filesystem to flush cached pages. Otherwise, + DIRECTIO requests are serialized. */ + posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED); +#endif /* POSIX_FADV_DONTNEED */ #endif /* defined(UNIV_SOLARIS) && defined(DIRECTIO_ON) */ return 0; }