From 89b258c5a78cfb560563c6e995b8aceda9ed1a04 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 15 Mar 2019 21:25:07 -0700 Subject: [PATCH] ircd::fs: Improve fs::prefetch(). --- include/ircd/fs/read.h | 2 +- ircd/fs.cc | 33 +++++++++++++-------------------- ircd/fs_aio.cc | 12 ------------ ircd/fs_aio.h | 1 - 4 files changed, 14 insertions(+), 34 deletions(-) diff --git a/include/ircd/fs/read.h b/include/ircd/fs/read.h index 5e8ee1144..fd2b760e4 100644 --- a/include/ircd/fs/read.h +++ b/include/ircd/fs/read.h @@ -28,7 +28,7 @@ namespace ircd::fs std::string read(const string_view &path, const read_opts & = read_opts_default); // Prefetch bytes for subsequent read(); offset is given in opts. - void prefetch(const fd &, const size_t &, const read_opts & = read_opts_default); + size_t prefetch(const fd &, const size_t &, const read_opts & = read_opts_default); } /// Options for a read operation diff --git a/ircd/fs.cc b/ircd/fs.cc index c4e795e8f..9ddb515b3 100644 --- a/ircd/fs.cc +++ b/ircd/fs.cc @@ -445,36 +445,29 @@ ircd::fs::read_opts const ircd::fs::read_opts_default {}; -#ifdef __linux__ -void +size_t ircd::fs::prefetch(const fd &fd, const size_t &count, const read_opts &opts) { - const auto flags + static const size_t max_count { - syscall(::fcntl, fd, F_GETFL) + 128_KiB }; - if(~flags & O_DIRECT) + size_t i(0), off, cnt; do { - syscall(::readahead, fd, opts.offset, count); - return; + off = opts.offset + max_count * i++; + cnt = std::min(opts.offset + count - off, max_count); + switch(const auto r(::posix_fadvise(fd, off, cnt, POSIX_FADV_WILLNEED)); r) + { + case 0: break; + default: throw_system_error(r); + } } - - #ifdef IRCD_USE_AIO - if(likely(aio::system) && opts.aio) - aio::prefetch(fd, count, opts); - #endif + while(off + cnt < opts.offset + count); + return count; } -#else -void -ircd::fs::prefetch(const fd &fd, - const size_t &count, - const read_opts &opts) -{ -} -#endif std::string ircd::fs::read(const string_view &path, diff --git a/ircd/fs_aio.cc b/ircd/fs_aio.cc index 450ee5cb7..d89da9dc8 100644 --- a/ircd/fs_aio.cc +++ b/ircd/fs_aio.cc @@ -258,18 +258,6 @@ ircd::fs::aio::write(const fd &fd, return bytes; } -// -// request::prefetch -// - -void -ircd::fs::aio::prefetch(const fd &fd, - const size_t &size, - const read_opts &opts) -{ - -} - // // request // diff --git a/ircd/fs_aio.h b/ircd/fs_aio.h index 855a6722a..0c3b13fc8 100644 --- a/ircd/fs_aio.h +++ b/ircd/fs_aio.h @@ -17,7 +17,6 @@ namespace ircd::fs::aio struct system; struct request; - void prefetch(const fd &, const size_t &, const read_opts &); size_t write(const fd &, const const_iovec_view &, const write_opts &); size_t read(const fd &, const const_iovec_view &, const read_opts &); void fdsync(const fd &, const sync_opts &);