8000 Implement memory detection override. by neunhoef · Pull Request #11268 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

Implement memory detection override. #11268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Implement memory detection override.
  • Loading branch information
neunhoef committed Mar 13, 2020
commit bd4b1e7ea197300046ff7cd77278631ee860754d
6 changes: 6 additions & 0 deletions lib/ApplicationFeatures/EnvironmentFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ void EnvironmentFeature::prepare() {
if (res == 0) {
double swapSpace = static_cast<double>(info.totalswap);
double ram = static_cast<double>(PhysicalMemory::getValue());
std::string overriddenmsg;
if (PhysicalMemory::overridden()) {
overriddenmsg = " (overridden by environment variable)";
}
LOG_TOPIC("25362", INFO, Logger::MEMORY)
<< "Available physical memory: " << ram << overriddenmsg;
double rr = (ram >= swapSpace) ? 100.0 * ((ram - swapSpace) / ram) : 0.0;
if (static_cast<double>(r) < 0.99 * rr) {
LOG_TOPIC("b0a75", WARN, Logger::MEMORY)
Expand Down
35 changes: 32 additions & 3 deletions lib/Basics/PhysicalMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "Basics/operating-system.h"

#include "Basics/PhysicalMemory.h"
#include "Basics/StringUtils.h"
#include "Basics/files.h"

#ifdef TRI_HAVE_UNISTD_H
#include <unistd.h>
Expand Down Expand Up @@ -90,10 +92,32 @@ uint64_t physicalMemoryImpl() {
#endif
#endif


struct PhysicalMemoryCache {
PhysicalMemoryCache() : cachedValue(physicalMemoryImpl()) {}
uint64_t const cachedValue;
PhysicalMemoryCache() : cachedValue(physicalMemoryImpl()), overridden(false) {
std::string value;
if (TRI_GETENV("ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY", value)) {
if (!value.empty()) {
uint64_t multiplier = 1;
if (value.back() == 'G' || value.back() == 'g') {
multiplier = 1024*1024*1024;
value.pop_back();
} else if (value.back() == 'M' || value.back() == 'm') {
multiplier = 1024 * 1024;
value.pop_back();
} else if (value.back() == 'K' || value.back() == 'k') {
multiplier = 1024;
value.pop_back();
}
uint64_t v = arangodb::basics::StringUtils::uint64(value) * multiplier;
if (v != 0) {
cachedValue = v;
overridden = true;
}
}
}
}
uint64_t cachedValue;
bool overridden;
};

PhysicalMemoryCache const cache;
Expand All @@ -104,3 +128,8 @@ PhysicalMemoryCache const cache;
uint64_t arangodb::PhysicalMemory::getValue() {
return ::cache.cachedValue;
}

/// @brief return if physical memory size was overridden
bool arangodb::PhysicalMemory::overridden() {
return ::cache.overridden;
}
1 change: 1 addition & 0 deletions lib/Basics/PhysicalMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace PhysicalMemory {

/// @brief return system's physical memory
uint64_t getValue();
bool overridden();

}
} // namespace arangodb
Expand Down
0