Skip to content
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

Memavailable #3534

Merged
merged 13 commits into from
Dec 27, 2021
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ venv/

#ctags
.tags
/.vs
17 changes: 10 additions & 7 deletions src/common/memory/MemoryUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <folly/String.h>
#include <gflags/gflags.h>

#include <algorithm>
#include <cstdio>
#include <fstream>
#include <regex>
Expand All @@ -21,7 +22,9 @@ using nebula::fs::FileUtils;

namespace nebula {

static const std::regex reMemAvailable(R"(^Mem(Available|Total):\s+(\d+)\skB$)");
static const std::regex reMemAvailable(
R"(^Mem(Available|Free|Total):\s+(\d+)\skB$)"); // when can't use MemAvailable, use MemFree
// instead.
static const std::regex reTotalCache(R"(^total_(cache|inactive_file)\s+(\d+)$)");

std::atomic_bool MemoryUtils::kHitMemoryHighWatermark{false};
Expand Down Expand Up @@ -63,13 +66,13 @@ StatusOr<bool> MemoryUtils::hitsHighWatermark() {
auto& sm = iter.matched();
memorySize.emplace_back(std::stoul(sm[2].str(), NULL) << 10);
}
CHECK_EQ(memorySize.size(), 2U);
size_t i = 0, j = 1;
if (memorySize[0] < memorySize[1]) {
std::swap(i, j);
std::sort(memorySize.begin(), memorySize.end());
if (memorySize.size() >= 2u) {
total = memorySize.back();
available = memorySize[memorySize.size() - 2];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

free <= available <= total

} else {
return false;
}
total = memorySize[i];
available = memorySize[j];
}

auto hits = (1 - available / total) > FLAGS_system_memory_high_watermark_ratio;
Expand Down