0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 10:12:39 +01:00

ircd::fs: Add prefetch().

This commit is contained in:
Jason Volk 2018-06-02 11:44:53 -07:00
parent 7f93f3ea2c
commit 79b2bdfb42
2 changed files with 28 additions and 0 deletions

View file

@ -22,6 +22,9 @@ namespace ircd::fs
// Yields ircd::ctx for read into allocated string; returns that string
std::string read(const fd &, const read_opts & = read_opts_default);
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);
}
/// Options for a read operation

View file

@ -122,6 +122,31 @@ const ircd::fs::read_opts_default
// ircd::fs interface linkage
//
#ifdef __linux__
void
ircd::fs::prefetch(const fd &fd,
const size_t &count,
const read_opts &opts)
{
const auto flags
{
syscall(::fcntl, fd, F_GETFL)
};
if(flags & O_DIRECT)
return; //TODO: AIO prefetch scheme
syscall(::readahead, fd, opts.offset, 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,
const read_opts &opts)