Commit c870aecd authored by Kuo-Hsin Yang's avatar Kuo-Hsin Yang Committed by Chromium LUCI CQ

CrOS: Handle the no meminfo case in memory pressure

When meminfo is not available, print an error message instead of
crashing chrome.

Bug: 1155300
Change-Id: Id42b08306fba83b776aaa1978fcab94f9184f27d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2586501Reviewed-by: default avatarBrian Geffon <bgeffon@chromium.org>
Commit-Queue: Kuo-Hsin Yang <vovoy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#836999}
parent 3aa1234b
......@@ -178,9 +178,14 @@ uint64_t CalculateAvailableMemoryUserSpaceKB(
uint64_t GetAvailableMemoryKB() {
base::SystemMemoryInfoKB info;
CHECK(base::GetSystemMemoryInfo(&info));
return CalculateAvailableMemoryUserSpaceKB(info, reserved_free, min_filelist,
ram_swap_weight);
if (base::GetSystemMemoryInfo(&info)) {
return CalculateAvailableMemoryUserSpaceKB(info, reserved_free,
min_filelist, ram_swap_weight);
}
PLOG(ERROR) << "Assume low memory pressure if opening/parsing meminfo failed";
LOG_IF(FATAL, base::SysInfo::IsRunningOnChromeOS())
<< "procfs isn't mounted or unable to open /proc/meminfo";
return 4 * 1024;
}
std::vector<uint64_t> GetMarginFileParts(const std::string& file) {
......@@ -222,8 +227,16 @@ std::pair<uint64_t, uint64_t> GetMemoryMarginsKBImpl() {
// Critical margin is 5.2% of total memory, moderate margin is 40% of total
// memory. See also /usr/share/cros/init/swap.sh on DUT.
base::SystemMemoryInfoKB info;
CHECK(base::GetSystemMemoryInfo(&info));
return {info.total * 13 / 250, info.total * 2 / 5};
int total_memory_kb = 2 * 1024;
if (base::GetSystemMemoryInfo(&info)) {
total_memory_kb = info.total;
} else {
PLOG(ERROR)
<< "Assume 2 GiB total memory if opening/parsing meminfo failed";
LOG_IF(FATAL, base::SysInfo::IsRunningOnChromeOS())
<< "procfs isn't mounted or unable to open /proc/meminfo";
}
return {total_memory_kb * 13 / 250, total_memory_kb * 2 / 5};
}
} // namespace
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment