Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Unified Diff: chromecast/renderer/cast_content_renderer_client.cc

Issue 834213002: Chromecast: forcibly trigger GC in low-memory situations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add TODO Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromecast/renderer/cast_content_renderer_client.cc
diff --git a/chromecast/renderer/cast_content_renderer_client.cc b/chromecast/renderer/cast_content_renderer_client.cc
index 6f9c67c84624b5712dbddd483aedb95f752ee677..521602d8d74f382240aeb10f42b351c5190fe59e 100644
--- a/chromecast/renderer/cast_content_renderer_client.cc
+++ b/chromecast/renderer/cast_content_renderer_client.cc
@@ -27,6 +27,46 @@ namespace shell {
namespace {
+#if defined(ARCH_CPU_ARM_FAMILY) && !defined(OS_ANDROID)
+// These memory thresholds are set for Chromecast. See the UMA histogram
+// Platform.MeminfoMemFree when tuning.
+// TODO(gunsch): These should be platform/product-dependent. Look into a way
+// to move these to platform-specific repositories.
+const int kCriticalMinFreeMemMB = 24;
+const int kModerateMinFreeMemMB = 48;
+const int kPollingIntervalMS = 5000;
+
+void PlatformPollFreemem(void) {
+ struct sysinfo sys;
+
+ if (sysinfo(&sys) == -1) {
+ LOG(ERROR) << "platform_poll_freemem(): sysinfo failed";
+ } else {
+ int free_mem_mb = static_cast<int64_t>(sys.freeram) *
+ sys.mem_unit / (1024 * 1024);
+
+ if (free_mem_mb <= kModerateMinFreeMemMB) {
+ if (free_mem_mb <= kCriticalMinFreeMemMB) {
+ // Memory is getting really low, we need to do whatever we can to
+ // prevent deadlocks and interfering with other processes.
+ base::MemoryPressureListener::NotifyMemoryPressure(
+ base::MemoryPressureListener::MEMORY_PRESSURE_CRITICAL);
+ } else {
+ // There is enough memory, but it is starting to get low.
+ base::MemoryPressureListener::NotifyMemoryPressure(
+ base::MemoryPressureListener::MEMORY_PRESSURE_MODERATE);
+ }
+ }
+ }
+
+ // Setup next poll.
+ base::MessageLoopProxy::current()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&PlatformPollFreemem),
+ base::TimeDelta::FromMilliseconds(kPollingIntervalMS));
+}
+#endif
+
// Default background color to set for WebViews. WebColor is in ARGB format
// though the comment of WebColor says it is in RGBA.
const blink::WebColor kColorBlack = 0xFF000000;
@@ -51,6 +91,10 @@ void CastContentRendererClient::RenderThreadStarted() {
crypto::InitNSSSafely();
#endif
+#if defined(ARCH_CPU_ARM_FAMILY) && !defined(OS_ANDROID)
+ PlatformPollFreemem();
+#endif
+
cast_observer_.reset(new CastRenderProcessObserver());
prescient_networking_dispatcher_.reset(
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698