Skip to content

Commit

Permalink
Added logging of system memory in bytes and fixed calculations to com…
Browse files Browse the repository at this point in the history
…pare in unit of bytes
  • Loading branch information
minhancao committed Feb 5, 2025
1 parent 6b32567 commit fc2ad18
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions presto-native-execution/presto_cpp/main/LinuxMemoryChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,25 @@ class LinuxMemoryChecker : public PeriodicMemoryChecker {
void start() {
// Check system-memory-gb < system-mem-limit-gb < actual total memory
// capacity.
auto* systemConfig = SystemConfig::instance();
int64_t systemMemoryInBytes = systemConfig->systemMemoryGb() << 30;
LOG(INFO) << fmt::format("System memory in bytes: {}", systemMemoryInBytes);

LOG(INFO) << fmt::format(
"System memory limit in bytes: {}", config_.systemMemLimitBytes);

int64_t actualTotalMemory = getActualTotalMemory();
LOG(INFO) << fmt::format(
"Actual total memory in bytes: {}", actualTotalMemory);

VELOX_CHECK_LE(
config_.systemMemLimitBytes,
actualTotalMemory,
"system memory limit = {} bytes is higher than the actual total memory capacity = {} bytes.",
config_.systemMemLimitBytes,
actualTotalMemory);

auto* systemConfig = SystemConfig::instance();
if (config_.systemMemLimitBytes < systemConfig->systemMemoryGb()) {
if (config_.systemMemLimitBytes < systemMemoryInBytes) {
LOG(WARNING) << "system-mem-limit-gb is smaller than system-memory-gb. "
<< "Expected: system-mem-limit-gb >= system-memory-gb.";
}
Expand All @@ -108,6 +115,7 @@ class LinuxMemoryChecker : public PeriodicMemoryChecker {
// Set actual total memory to be the smaller number between /proc/meminfo
// and memMaxFile_.
int64_t actualTotalMemory = 0;
// meminfo's units is in kB.
folly::gen::byLine(memInfoFile_.c_str()) |
[&](const folly::StringPiece& line) -> void {
if (actualTotalMemory != 0) {
Expand Down Expand Up @@ -140,6 +148,7 @@ class LinuxMemoryChecker : public PeriodicMemoryChecker {
};
}

// Unit is in bytes.
return actualTotalMemory;
}

Expand Down

0 comments on commit fc2ad18

Please sign in to comment.