mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 10:12:39 +01:00
ircd::fs: Improve fs::prefetch().
This commit is contained in:
parent
cc25cce9e4
commit
89b258c5a7
4 changed files with 14 additions and 34 deletions
|
@ -28,7 +28,7 @@ namespace ircd::fs
|
||||||
std::string read(const string_view &path, 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.
|
// 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
|
/// Options for a read operation
|
||||||
|
|
33
ircd/fs.cc
33
ircd/fs.cc
|
@ -445,36 +445,29 @@ ircd::fs::read_opts
|
||||||
const ircd::fs::read_opts_default
|
const ircd::fs::read_opts_default
|
||||||
{};
|
{};
|
||||||
|
|
||||||
#ifdef __linux__
|
size_t
|
||||||
void
|
|
||||||
ircd::fs::prefetch(const fd &fd,
|
ircd::fs::prefetch(const fd &fd,
|
||||||
const size_t &count,
|
const size_t &count,
|
||||||
const read_opts &opts)
|
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);
|
off = opts.offset + max_count * i++;
|
||||||
return;
|
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
|
while(off + cnt < opts.offset + count);
|
||||||
if(likely(aio::system) && opts.aio)
|
return count;
|
||||||
aio::prefetch(fd, count, opts);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
void
|
|
||||||
ircd::fs::prefetch(const fd &fd,
|
|
||||||
const size_t &count,
|
|
||||||
const read_opts &opts)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
ircd::fs::read(const string_view &path,
|
ircd::fs::read(const string_view &path,
|
||||||
|
|
|
@ -258,18 +258,6 @@ ircd::fs::aio::write(const fd &fd,
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// request::prefetch
|
|
||||||
//
|
|
||||||
|
|
||||||
void
|
|
||||||
ircd::fs::aio::prefetch(const fd &fd,
|
|
||||||
const size_t &size,
|
|
||||||
const read_opts &opts)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// request
|
// request
|
||||||
//
|
//
|
||||||
|
|
|
@ -17,7 +17,6 @@ namespace ircd::fs::aio
|
||||||
struct system;
|
struct system;
|
||||||
struct request;
|
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 write(const fd &, const const_iovec_view &, const write_opts &);
|
||||||
size_t read(const fd &, const const_iovec_view &, const read_opts &);
|
size_t read(const fd &, const const_iovec_view &, const read_opts &);
|
||||||
void fdsync(const fd &, const sync_opts &);
|
void fdsync(const fd &, const sync_opts &);
|
||||||
|
|
Loading…
Reference in a new issue