mirror of
https://github.com/matrix-construct/construct
synced 2024-12-28 16:34:13 +01:00
ircd::allocator: Add trapdoor on size and alignment for hugepage advise.
This commit is contained in:
parent
9417659367
commit
d338e589f5
1 changed files with 42 additions and 0 deletions
|
@ -19,6 +19,11 @@
|
||||||
//
|
//
|
||||||
// #define RB_PROF_ALLOC
|
// #define RB_PROF_ALLOC
|
||||||
|
|
||||||
|
namespace ircd::allocator
|
||||||
|
{
|
||||||
|
static void advise_hugepage(void *const &, const size_t &alignment, const size_t &size);
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<char, decltype(&std::free)>
|
std::unique_ptr<char, decltype(&std::free)>
|
||||||
ircd::allocator::aligned_alloc(const size_t &alignment_,
|
ircd::allocator::aligned_alloc(const size_t &alignment_,
|
||||||
const size_t &size_)
|
const size_t &size_)
|
||||||
|
@ -61,6 +66,9 @@ ircd::allocator::aligned_alloc(const size_t &alignment_,
|
||||||
assert(ret != nullptr);
|
assert(ret != nullptr);
|
||||||
assert(uintptr_t(ret) % alignment == 0);
|
assert(uintptr_t(ret) % alignment == 0);
|
||||||
|
|
||||||
|
if(likely(info::thp_size))
|
||||||
|
advise_hugepage(ret, alignment, size);
|
||||||
|
|
||||||
#ifdef RB_PROF_ALLOC
|
#ifdef RB_PROF_ALLOC
|
||||||
auto &this_thread(ircd::allocator::profile::this_thread);
|
auto &this_thread(ircd::allocator::profile::this_thread);
|
||||||
this_thread.alloc_bytes += size;
|
this_thread.alloc_bytes += size;
|
||||||
|
@ -73,6 +81,40 @@ ircd::allocator::aligned_alloc(const size_t &alignment_,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ircd::allocator::advise_hugepage(void *const &ptr,
|
||||||
|
const size_t &alignment,
|
||||||
|
const size_t &size)
|
||||||
|
|
||||||
|
#if defined(MADV_HUGEPAGE)
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if(likely(alignment < info::thp_size))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(likely(alignment % size_t(info::thp_size) != 0))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(!has(info::thp_enable, "[madvise]"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
sys::call(::madvise, ptr, size, MADV_HUGEPAGE);
|
||||||
|
}
|
||||||
|
catch(const std::exception &e)
|
||||||
|
{
|
||||||
|
log::critical
|
||||||
|
{
|
||||||
|
"Failed to madvise(%p, %zu, MADV_HUGEPAGE) :%s",
|
||||||
|
ptr,
|
||||||
|
size,
|
||||||
|
e.what(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
ircd::allocator::incore(const const_buffer &buf)
|
ircd::allocator::incore(const const_buffer &buf)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue