From fc2ad18e830f0bee656fbdb8187ba7837ae2f1e6 Mon Sep 17 00:00:00 2001 From: Minhan Cao Date: Tue, 4 Feb 2025 17:47:25 -0800 Subject: [PATCH] Added logging of system memory in bytes and fixed calculations to compare in unit of bytes --- .../presto_cpp/main/LinuxMemoryChecker.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/presto-native-execution/presto_cpp/main/LinuxMemoryChecker.cpp b/presto-native-execution/presto_cpp/main/LinuxMemoryChecker.cpp index eac88aafe2f39..9a1055917f4a8 100644 --- a/presto-native-execution/presto_cpp/main/LinuxMemoryChecker.cpp +++ b/presto-native-execution/presto_cpp/main/LinuxMemoryChecker.cpp @@ -85,9 +85,17 @@ 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, @@ -95,8 +103,7 @@ class LinuxMemoryChecker : public PeriodicMemoryChecker { 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."; } @@ -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) { @@ -140,6 +148,7 @@ class LinuxMemoryChecker : public PeriodicMemoryChecker { }; } + // Unit is in bytes. return actualTotalMemory; }