Skip to content

Commit

Permalink
Renamed start() to checkMemoryConfigs() and changed LOG to PRESTO_STA…
Browse files Browse the repository at this point in the history
…RTUP_LOG
  • Loading branch information
minhancao committed Feb 6, 2025
1 parent fc2ad18 commit 049d519
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions presto-native-execution/presto_cpp/main/LinuxMemoryChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <sys/stat.h>
#include "presto_cpp/main/PeriodicMemoryChecker.h"
#include "presto_cpp/main/common/Configs.h"
#include "presto_cpp/main/common/Utils.h"

namespace facebook::presto {

Expand All @@ -30,16 +31,16 @@ class LinuxMemoryChecker : public PeriodicMemoryChecker {
struct stat buffer;
if ((stat(kCgroupV1Path, &buffer) == 0)) {
statFile_ = kCgroupV1Path;
LOG(INFO) << fmt::format(
"Using cgroup v1 memory stat file: {}", statFile_);
PRESTO_STARTUP_LOG(INFO)
<< fmt::format("Using cgroup v1 memory stat file: {}", statFile_);
} else if ((stat(kCgroupV2Path, &buffer) == 0)) {
statFile_ = kCgroupV2Path;
LOG(INFO) << fmt::format(
"Using cgroup v2 memory stat file: {}", statFile_);
PRESTO_STARTUP_LOG(INFO)
<< fmt::format("Using cgroup v2 memory stat file: {}", statFile_);
} else {
statFile_ = "None";
LOG(INFO) << fmt::format(
"Could not find memory stat file: {}", statFile_);
PRESTO_STARTUP_LOG(INFO)
<< fmt::format("Could not find memory stat file: {}", statFile_);
}

// Set memMaxFile_ to:
Expand All @@ -48,16 +49,19 @@ class LinuxMemoryChecker : public PeriodicMemoryChecker {
// "/sys/fs/cgroup/memory.max" for cgroup v2.
if ((stat(kCgroupV1MaxMemFilePath, &buffer) == 0)) {
memMaxFile_ = kCgroupV1MaxMemFilePath;
LOG(INFO) << fmt::format(
"Using cgroup v1 memory max file {}", memMaxFile_);
PRESTO_STARTUP_LOG(INFO)
<< fmt::format("Using cgroup v1 memory max file {}", memMaxFile_);
} else if ((stat(kCgroupV2MaxMemFilePath, &buffer) == 0)) {
memMaxFile_ = kCgroupV2MaxMemFilePath;
LOG(INFO) << fmt::format(
"Using cgroup v2 memory max file {}", memMaxFile_);
PRESTO_STARTUP_LOG(INFO)
<< fmt::format("Using cgroup v2 memory max file {}", memMaxFile_);
} else {
memMaxFile_ = "None";
LOG(INFO) << fmt::format("Could not find memory max file: {}", statFile_);
PRESTO_STARTUP_LOG(INFO)
<< fmt::format("Could not find memory max file: {}", memMaxFile_);
}

checkMemoryConfigs();
}

~LinuxMemoryChecker() override {}
Expand All @@ -82,19 +86,20 @@ class LinuxMemoryChecker : public PeriodicMemoryChecker {
LOG(INFO) << fmt::format("Changed to using meminfo file {}", memInfoFile_);
}

void start() {
void checkMemoryConfigs() {
// 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);
PRESTO_STARTUP_LOG(INFO)
<< fmt::format("System memory in bytes: {}", systemMemoryInBytes);

LOG(INFO) << fmt::format(
PRESTO_STARTUP_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);
PRESTO_STARTUP_LOG(INFO)
<< fmt::format("Actual total memory in bytes: {}", actualTotalMemory);

VELOX_CHECK_LE(
config_.systemMemLimitBytes,
Expand All @@ -107,8 +112,6 @@ class LinuxMemoryChecker : public PeriodicMemoryChecker {
LOG(WARNING) << "system-mem-limit-gb is smaller than system-memory-gb. "
<< "Expected: system-mem-limit-gb >= system-memory-gb.";
}

PeriodicMemoryChecker::start();
}

int64_t getActualTotalMemory() {
Expand Down

0 comments on commit 049d519

Please sign in to comment.