Skip to content

Commit

Permalink
Memavailable (vesoft-inc#416)
Browse files Browse the repository at this point in the history
#### What type of PR is this?
- [* ] bug
- [ ] feature
- [ ] enhancement

#### What does this PR do?
fix meminfo bug

#### Which issue(s)/PR(s) this PR relates to?
fix issue vesoft-inc#3356
  
#### Special notes for your reviewer, ex. impact of this fix, etc:


#### Additional context/ Design document:


#### Checklist:
- [ ] Documentation affected (Please add the label if documentation needs to be modified.)
- [ ] Incompatibility (If it breaks the compatibility, please describe it and add the corresponding label.)
- [ ] If it's needed to cherry-pick (If cherry-pick to some branches is required, please label the destination version(s).)
- [ ] Performance impacted: Consumes more CPU/Memory

#### Release notes:

Please confirm whether to be reflected in release notes and how to describe:
>                                                                 `


Migrated from vesoft-inc#3534

Co-authored-by: yuehua.jia <[email protected]>
  • Loading branch information
nebula-bots and jiayuehua authored Jan 4, 2022
1 parent 8fb64ff commit 8021a49
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ venv/

#ctags
.tags

/.vs
#license
tests/secrets/nebula.license
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];
} else {
return false;
}
total = memorySize[i];
available = memorySize[j];
}

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

0 comments on commit 8021a49

Please sign in to comment.