Skip to content

Commit

Permalink
[fix](memory) Fix refresh cgroup meminfo (#41123)
Browse files Browse the repository at this point in the history
cgroup memory usage should be refreshed frequently.
  • Loading branch information
xinyiZzz authored Sep 24, 2024
1 parent f0e2717 commit 601cc58
Showing 1 changed file with 26 additions and 29 deletions.
55 changes: 26 additions & 29 deletions be/src/util/mem_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,40 +189,37 @@ void MemInfo::refresh_proc_meminfo() {
}

// refresh cgroup memory
if (_s_cgroup_mem_refresh_wait_times >= 0 && config::enable_use_cgroup_memory_info) {
int64_t cgroup_mem_limit = -1;
int64_t cgroup_mem_usage = -1;
std::string cgroup_mem_info_file_path;
_s_cgroup_mem_refresh_state = true;
Status status = CGroupMemoryCtl::find_cgroup_mem_limit(&cgroup_mem_limit);
if (!status.ok()) {
_s_cgroup_mem_refresh_state = false;
}
status = CGroupMemoryCtl::find_cgroup_mem_usage(&cgroup_mem_usage);
if (!status.ok()) {
_s_cgroup_mem_refresh_state = false;
}

if (_s_cgroup_mem_refresh_state) {
_s_cgroup_mem_limit = cgroup_mem_limit;
_s_cgroup_mem_usage = cgroup_mem_usage;
// wait 10s, 100 * 100ms, avoid too frequently.
_s_cgroup_mem_refresh_wait_times = -100;
LOG(INFO) << "Refresh cgroup memory win, refresh again after 10s, cgroup mem limit: "
<< _s_cgroup_mem_limit << ", cgroup mem usage: " << _s_cgroup_mem_usage;
if (config::enable_use_cgroup_memory_info) {
if (_s_cgroup_mem_refresh_wait_times >= 0) {
auto status = CGroupMemoryCtl::find_cgroup_mem_limit(&_s_cgroup_mem_limit);
if (!status.ok()) {
_s_cgroup_mem_limit = std::numeric_limits<int64_t>::max();
// find cgroup limit failed, wait 300s, 1000 * 100ms.
_s_cgroup_mem_refresh_wait_times = -3000;
LOG(INFO) << "Refresh cgroup memory limit failed, refresh again after 300s, cgroup "
"mem limit: "
<< _s_cgroup_mem_limit;
} else {
// wait 10s, 100 * 100ms, avoid too frequently.
_s_cgroup_mem_refresh_wait_times = -100;
}
} else {
// find cgroup failed, wait 300s, 1000 * 100ms.
_s_cgroup_mem_refresh_wait_times = -3000;
LOG(INFO)
<< "Refresh cgroup memory failed, refresh again after 300s, cgroup mem limit: "
<< _s_cgroup_mem_limit << ", cgroup mem usage: " << _s_cgroup_mem_usage;
}
} else {
if (config::enable_use_cgroup_memory_info) {
_s_cgroup_mem_refresh_wait_times++;
}

if (_s_cgroup_mem_limit != std::numeric_limits<int64_t>::max()) {
auto status = CGroupMemoryCtl::find_cgroup_mem_usage(&_s_cgroup_mem_usage);
if (!status.ok()) {
_s_cgroup_mem_usage = std::numeric_limits<int64_t>::min();
_s_cgroup_mem_refresh_state = false;
} else {
_s_cgroup_mem_refresh_state = true;
}
} else {
_s_cgroup_mem_refresh_state = false;
}
} else {
_s_cgroup_mem_refresh_state = false;
}

// 1. calculate physical_mem
Expand Down

0 comments on commit 601cc58

Please sign in to comment.