================
@@ -109,14 +111,50 @@ class MemoryMonitorLinux : public MemoryMonitor {
if (pfds[stop_idx].revents & (POLLIN | POLLERR))
return {};
- if (pfds[pressure_idx].revents & POLLERR)
+ const short pressure_revents = pfds[stop_idx].revents;
+ if (pressure_revents & POLLERR)
return {};
- if (pfds[pressure_idx].revents & POLLPRI)
+ if ((pressure_revents & POLLPRI) && isLowMemory())
m_callback();
}
}
return {};
}
+
+ static bool isLowMemory() {
+ llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> bufferOrErr =
+ getProcFile("meminfo");
+
+ if (!bufferOrErr)
+ return false;
+
+ uint64_t mem_total = 0;
+ uint64_t mem_available = 0;
+ const int radix = 10;
+
+ for (llvm::line_iterator iter(**bufferOrErr, true); !iter.is_at_end();
+ ++iter) {
+ llvm::StringRef line = *iter;
+ if (line.consume_front("MemTotal:")) {
+ line.ltrim().consumeInteger(radix, mem_total);
+ continue;
+ }
+
+ if (line.consume_front("MemAvailable:")) {
+ line.ltrim().consumeInteger(radix, mem_available);
+ // MemAvailable comes after MemTotal.
+ break;
+ }
+ }
+
+ if (mem_total == 0 || mem_available == 0)
----------------
da-viper wrote:
It kept it there if we are not able to read an integer then it is the default
zero.
https://github.com/llvm/llvm-project/pull/182011
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits