1
0
mirror of https://github.com/Zygo/bees.git synced 2025-06-16 17:46:16 +02:00

hash: don't throw an exception if MADV_HUGEPAGE fails

We don't _need_ transparent hugepages.  We like them because they can
be faster, but it's not a requirement, and some people will disable
transparent hugepages because they make non-Bees-like workloads slow.

Try to use MADV_HUGEPAGE, but if it fails, just log the error and
continue.

MADV_DONTFORK would be useful if we still fork()ed, but we don't currently
do that.  It's still a useful flag to have because a fork() with more
than 50% of RAM in mlocked pages would result in a kernel OOM crash.
I don't think it's possible to run Bees on a kernel that does not support
the MADV_DONTFORK flag, so don't bother checking for that flag separately.
This commit is contained in:
Zygo Blaxell
2016-12-08 23:09:37 -05:00
parent d82909387d
commit b5c01c1985

View File

@ -11,13 +11,6 @@
using namespace crucible; using namespace crucible;
using namespace std; using namespace std;
static inline
bool
using_any_madvise()
{
return true;
}
ostream & ostream &
operator<<(ostream &os, const BeesHash &bh) operator<<(ostream &os, const BeesHash &bh)
{ {
@ -645,11 +638,13 @@ BeesHashTable::BeesHashTable(shared_ptr<BeesContext> ctx, string filename, off_t
THROW_CHECK2(runtime_error, m_void_ptr, m_bucket_ptr, m_void_ptr == m_bucket_ptr); THROW_CHECK2(runtime_error, m_void_ptr, m_bucket_ptr, m_void_ptr == m_bucket_ptr);
THROW_CHECK2(runtime_error, m_void_ptr, m_extent_ptr, m_void_ptr == m_extent_ptr); THROW_CHECK2(runtime_error, m_void_ptr, m_extent_ptr, m_void_ptr == m_extent_ptr);
// madvise fails if MAP_SHARED {
if (using_any_madvise()) { // It's OK if this fails (e.g. kernel not built with CONFIG_TRANSPARENT_HUGEPAGE)
// DONTFORK because fork won't end well // We don't fork any more so DONTFORK isn't really needed
BEESTOOLONG("madvise(MADV_HUGEPAGE | MADV_DONTFORK)"); BEESTOOLONG("madvise(MADV_HUGEPAGE | MADV_DONTFORK)");
DIE_IF_NON_ZERO(madvise(m_byte_ptr, m_size, MADV_HUGEPAGE | MADV_DONTFORK)); if (madvise(m_byte_ptr, m_size, MADV_HUGEPAGE | MADV_DONTFORK)) {
BEESLOG("mostly harmless: madvise(MADV_HUGEPAGE | MADV_DONTFORK) failed: " << strerror(errno));
}
} }
for (uint64_t i = 0; i < m_size / sizeof(Extent); ++i) { for (uint64_t i = 0; i < m_size / sizeof(Extent); ++i) {