0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 10:08:56 +02:00

ircd::fs: Improve fs::prefetch().

This commit is contained in:
Jason Volk 2019-03-15 21:25:07 -07:00
parent cc25cce9e4
commit 89b258c5a7
4 changed files with 14 additions and 34 deletions

View file

@ -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

View file

@ -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,

View file

@ -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
//

View file

@ -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 &);