Bug 1869457 - Don't attempt to compute low-memory conditions if we don't know how much memory is in the system r=KrisWright

Differential Revision: https://phabricator.services.mozilla.com/D196293
This commit is contained in:
Gabriele Svelto 2023-12-19 20:29:45 +00:00
Родитель 73612ff736
Коммит 2948adb94c
1 изменённых файлов: 8 добавлений и 12 удалений

Просмотреть файл

@ -120,26 +120,22 @@ void nsAvailableMemoryWatcher::StopPolling(const MutexAutoLock&)
/* static */
bool nsAvailableMemoryWatcher::IsMemoryLow() {
MemoryInfo memInfo{0, 0};
bool aResult = false;
nsresult rv = ReadMemoryFile(kMeminfoPath, memInfo);
if (NS_FAILED(rv) || memInfo.memAvailable == 0) {
if (NS_FAILED(rv) || (memInfo.memAvailable == 0) || (memInfo.memTotal == 0)) {
// If memAvailable cannot be found, then we are using an older system.
// We can't accurately poll on this.
return aResult;
// If memTotal is zero we can't calculate how much memory we're using.
return false;
}
unsigned long memoryAsPercentage =
(memInfo.memAvailable * 100) / memInfo.memTotal;
if (memoryAsPercentage <=
StaticPrefs::browser_low_commit_space_threshold_percent() ||
memInfo.memAvailable <
StaticPrefs::browser_low_commit_space_threshold_mb() * 1024) {
aResult = true;
}
return aResult;
return memoryAsPercentage <=
StaticPrefs::browser_low_commit_space_threshold_percent() ||
memInfo.memAvailable <
StaticPrefs::browser_low_commit_space_threshold_mb() * 1024;
}
void nsAvailableMemoryWatcher::ShutDown() {