0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 18:22:50 +01:00

ircd::fs: Use fd::map object for fincore() impl.

This commit is contained in:
Jason Volk 2020-08-24 08:56:23 -07:00
parent f6475a2906
commit 64e5df1d86

View file

@ -806,45 +806,50 @@ ircd::fs::fincore(const fd &fd,
const size_t &count, const size_t &count,
const read_opts &opts) const read_opts &opts)
{ {
assert(opts.offset % info::page_size == 0); using word_t = unsigned long long;
thread_local std::array<word_t, 64> tls_vec;
fs::map::opts map_opts;
map_opts.offset = buffer::align(opts.offset, info::page_size);
map_opts.blocking = false;
const size_t &map_size const size_t &map_size
{ {
count?: size(fd) count?: size(fd)
}; };
void *const &map const size_t &map_pages
{ {
::mmap(nullptr, map_size, PROT_NONE, MAP_NONBLOCK | MAP_SHARED, int(fd), opts.offset) (map_size + info::page_size - 1) / info::page_size
}; };
if(unlikely(map == MAP_FAILED)) const size_t &vec_size
throw_system_error(errno);
const custom_ptr<void> map_ptr
{ {
map, [&map_size](void *const &map) std::max(map_pages / sizeof(word_t), 1UL)
{
syscall(::munmap, map, map_size);
}
}; };
using word_t = unsigned long long; const size_t &dynamic_vec_size
thread_local std::array<word_t, 64> tls_vec;
const size_t vec_size
{ {
std::max(((map_size + info::page_size - 1) / info::page_size) / sizeof(word_t), 1UL) vec_size > tls_vec.size()?
}; vec_size:
0UL
assert(vec_size > 0 && vec_size < map_size);
const auto dynamic_vec_size
{
vec_size > tls_vec.size()? vec_size : 0UL
}; };
std::vector<word_t> dynamic_vec(dynamic_vec_size); std::vector<word_t> dynamic_vec(dynamic_vec_size);
auto *const vec(dynamic_vec_size? dynamic_vec.data(): tls_vec.data()); auto *const vec
return fincore(map, map_size, reinterpret_cast<uint8_t *>(vec), vec_size); {
dynamic_vec_size?
dynamic_vec.data():
tls_vec.data()
};
assert(map_opts.offset % 4096 == 0);
const fs::map map
{
fd, map_opts, map_size
};
assert(vec_size > 0 && vec_size <= map_size);
return fincore(data(map), map_size, reinterpret_cast<uint8_t *>(vec), vec_size);
} }
bool bool