From b5c01c198507b3b6cfb71eeab9479d69bbf697e7 Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Thu, 8 Dec 2016 23:09:37 -0500 Subject: [PATCH] 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. --- src/bees-hash.cc | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/bees-hash.cc b/src/bees-hash.cc index da4b6db..873153c 100644 --- a/src/bees-hash.cc +++ b/src/bees-hash.cc @@ -11,13 +11,6 @@ using namespace crucible; using namespace std; -static inline -bool -using_any_madvise() -{ - return true; -} - ostream & operator<<(ostream &os, const BeesHash &bh) { @@ -645,11 +638,13 @@ BeesHashTable::BeesHashTable(shared_ptr 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_extent_ptr, m_void_ptr == m_extent_ptr); - // madvise fails if MAP_SHARED - if (using_any_madvise()) { - // DONTFORK because fork won't end well + { + // It's OK if this fails (e.g. kernel not built with CONFIG_TRANSPARENT_HUGEPAGE) + // We don't fork any more so DONTFORK isn't really needed 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) {