diff options
author | Tor Brede Vekterli <vekterli@yahooinc.com> | 2022-03-03 15:52:07 +0000 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@yahooinc.com> | 2022-03-03 15:52:07 +0000 |
commit | fdee58d78d32a86b7f754f135680d2aa147667de (patch) | |
tree | 56677966405f0d0d7c57848ef554547aa65fc32b /vespalib | |
parent | e91467c5c8811a0bcc1e8e781ff1d17c7f490c0e (diff) |
Make global alloc hugepages failure flag atomic
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/vespa/vespalib/util/alloc.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/vespalib/src/vespa/vespalib/util/alloc.cpp b/vespalib/src/vespa/vespalib/util/alloc.cpp index bf5f0200600..3933a92ad09 100644 --- a/vespalib/src/vespa/vespalib/util/alloc.cpp +++ b/vespalib/src/vespa/vespalib/util/alloc.cpp @@ -1,5 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "alloc.h" +#include "atomic.h" #include "memory_allocator.h" #include "round_up_to_page_size.h" #include <sys/mman.h> @@ -17,11 +18,13 @@ #include <vespa/log/log.h> LOG_SETUP(".vespalib.alloc"); +using namespace vespalib::atomic; + namespace vespalib { namespace { -volatile bool _G_hasHugePageFailureJustHappened(false); +std::atomic<bool> _G_hasHugePageFailureJustHappened(false); bool _G_SilenceCoreOnOOM(false); int _G_HugeFlags = 0; size_t _G_MMapLogLimit = std::numeric_limits<size_t>::max(); @@ -328,8 +331,8 @@ MMapAllocator::salloc(size_t sz, void * wantedAddress) } buf = mmap(wantedAddress, sz, prot, flags | _G_HugeFlags, -1, 0); if (buf == MAP_FAILED) { - if ( ! _G_hasHugePageFailureJustHappened ) { - _G_hasHugePageFailureJustHappened = true; + if ( ! load_relaxed(_G_hasHugePageFailureJustHappened)) { + store_relaxed(_G_hasHugePageFailureJustHappened, true); LOG(debug, "Failed allocating %ld bytes with hugepages due too '%s'." " Will resort to ordinary mmap until it works again.", sz, FastOS_FileInterface::getLastErrorString().c_str()); @@ -347,8 +350,8 @@ MMapAllocator::salloc(size_t sz, void * wantedAddress) } } } else { - if (_G_hasHugePageFailureJustHappened) { - _G_hasHugePageFailureJustHappened = false; + if (load_relaxed(_G_hasHugePageFailureJustHappened)) { + store_relaxed(_G_hasHugePageFailureJustHappened, false); } } #ifdef __linux__ |