Skip to content

Commit 71eae9f

Browse files
committed
util: Log reasoning when returning true from SystemNeedsMemoryReleased
1 parent aed813c commit 71eae9f

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/common/system.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,12 @@ bool SystemNeedsMemoryReleased()
122122
MEMORYSTATUSEX mem_status;
123123
mem_status.dwLength = sizeof(mem_status);
124124
if (GlobalMemoryStatusEx(&mem_status)) {
125-
if (mem_status.dwMemoryLoad >= 99) return true;
126-
if (mem_status.ullAvailPhys < low_memory_threshold) return true;
127-
if (mem_status.ullAvailVirtual < low_memory_threshold) return true;
125+
if (mem_status.dwMemoryLoad >= 99 ||
126+
mem_status.ullAvailPhys < low_memory_threshold ||
127+
mem_status.ullAvailVirtual < low_memory_threshold) {
128+
LogPrintf("%s: YES: %s%% memory load; %s available physical memory; %s available virtual memory\n", __func__, int(mem_status.dwMemoryLoad), size_t(mem_status.ullAvailPhys), size_t(mem_status.ullAvailVirtual));
129+
return true;
130+
}
128131
}
129132
#endif
130133
#ifdef HAVE_LINUX_SYSINFO
@@ -133,7 +136,10 @@ bool SystemNeedsMemoryReleased()
133136
// Explicitly 64-bit in case of 32-bit userspace on 64-bit kernel
134137
const uint64_t free_ram = uint64_t(sys_info.freeram) * sys_info.mem_unit;
135138
const uint64_t buffer_ram = uint64_t(sys_info.bufferram) * sys_info.mem_unit;
136-
if (free_ram + buffer_ram < low_memory_threshold) return true;
139+
if (free_ram + buffer_ram < low_memory_threshold) {
140+
LogPrintf("%s: YES: %s free RAM + %s buffer RAM\n", __func__, free_ram, buffer_ram);
141+
return true;
142+
}
137143
}
138144
#endif
139145
// NOTE: sysconf(_SC_AVPHYS_PAGES) doesn't account for caches on at least Linux, so not safe to use here

0 commit comments

Comments
 (0)