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

ircd::fs: Minor reorg of fadvise related.

This commit is contained in:
Jason Volk 2019-07-12 13:34:18 -07:00
parent 4090b8f3da
commit d0cc5b020b
2 changed files with 58 additions and 50 deletions

View file

@ -21,6 +21,8 @@ namespace ircd::fs
ulong device(const fd &);
uint64_t write_life(const fd &) noexcept;
void write_life(const fd &, const uint64_t &);
size_t advise(const fd &, const int &, const size_t & = 0, const opts & = opts_default);
size_t evict(const fd &, const size_t &size = 0, const opts & = opts_default);
}
/// File Desc++ptor. This is simply a native fd (i.e. integer) with c++ object

View file

@ -514,73 +514,24 @@ ircd::fs::flush(const fd &fd,
namespace ircd::fs
{
static bool fincore(void *const &map, const size_t &map_size, uint8_t *const &vec, const size_t &vec_size);
static size_t advise(const fd &, const size_t &, const read_opts &, const int &advice);
}
ircd::fs::read_opts
const ircd::fs::read_opts_default
{};
size_t
ircd::fs::evict(const fd &fd,
const size_t &count,
const read_opts &opts)
{
#if defined(POSIX_FADV_DONTNEED)
return advise(fd, count, opts, POSIX_FADV_DONTNEED);
#else
return 0UL;
#endif
}
size_t
ircd::fs::prefetch(const fd &fd,
const size_t &count,
const read_opts &opts)
{
#if defined(POSIX_FADV_WILLNEED)
return advise(fd, count, opts, POSIX_FADV_WILLNEED);
return advise(fd, POSIX_FADV_WILLNEED, count, opts);
#else
return 0UL;
#endif
}
#if defined(HAVE_POSIX_FADVISE)
size_t
ircd::fs::advise(const fd &fd,
const size_t &count,
const read_opts &opts,
const int &advice)
{
static const size_t max_count
{
128_KiB
};
size_t i(0), off, cnt; do
{
off = opts.offset + max_count * i++;
cnt = std::min(opts.offset + count - off, max_count);
switch(const auto r(::posix_fadvise(fd, off, cnt, advice)); r)
{
case 0: break;
default: throw_system_error(r);
}
}
while(off + cnt < opts.offset + count);
return count;
}
#else
size_t
ircd::fs::advise(const fd &fd,
const size_t &count,
const read_opts &opts,
const int &advice)
{
return 0UL;
}
#endif
bool
ircd::fs::fincore(const fd &fd,
const size_t &count,
@ -1470,6 +1421,61 @@ ircd::fs::fd::opts::direct_io_enable
{ "persist", false },
};
#if defined(POSIX_FADV_DONTNEED)
size_t
ircd::fs::evict(const fd &fd,
const size_t &count,
const opts &opts)
{
return advise(fd, POSIX_FADV_DONTNEED, count, opts);
}
#else
#warning "POSIX_FADV_DONTNEED not available on this platform."
size_t
ircd::fs::evict(const fd &fd,
const size_t &count,
const opts &opts)
{
return 0UL;
}
#endif
#if defined(HAVE_POSIX_FADVISE)
size_t
ircd::fs::advise(const fd &fd,
const int &advice,
const size_t &count,
const opts &opts)
{
static const size_t max_count
{
128_KiB
};
size_t i(0), off, cnt; do
{
off = opts.offset + max_count * i++;
cnt = std::min(opts.offset + count - off, max_count);
switch(const auto r(::posix_fadvise(fd, off, cnt, advice)); r)
{
case 0: break;
default: throw_system_error(r);
}
}
while(off + cnt < opts.offset + count);
return count;
}
#else
#warning "posix_fadvise(2) not available for this compilation."
size_t
ircd::fs::advise(const fd &fd,
const int &advice,
const size_t &count,
const opts &opts)
{
}
#endif
#if defined(HAVE_FCNTL_H) && defined(F_SET_FILE_RW_HINT)
void
ircd::fs::write_life(const fd &fd,