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

Unified Diff: chromecast/browser/cast_memory_pressure_monitor.cc

Issue 2151693005: [Chromecast] Use MemAvailable to compute memory pressure (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: static_cast Created 4 years, 5 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/browser/cast_memory_pressure_monitor.cc
diff --git a/chromecast/browser/cast_memory_pressure_monitor.cc b/chromecast/browser/cast_memory_pressure_monitor.cc
index ed70148356ecc30525ea4d267ab0602439f86d6e..61479144b4ee76c4352e8b48108daadf83330f4f 100644
--- a/chromecast/browser/cast_memory_pressure_monitor.cc
+++ b/chromecast/browser/cast_memory_pressure_monitor.cc
@@ -22,8 +22,8 @@ namespace {
// Memory thresholds (as fraction of total memory) for memory pressure levels.
// See more detailed description of pressure heuristic in PollPressureLevel.
// TODO(halliwell): tune thresholds based on data.
-constexpr float kCriticalMemoryFraction = 0.2f;
-constexpr float kModerateMemoryFraction = 0.3f;
+constexpr float kCriticalMemoryFraction = 0.25f;
+constexpr float kModerateMemoryFraction = 0.4f;
// Memory thresholds in MB for the simple heuristic based on 'free' memory.
constexpr int kCriticalFreeMemoryKB = 20 * 1024;
@@ -67,25 +67,30 @@ void CastMemoryPressureMonitor::PollPressureLevel() {
if (!base::GetSystemMemoryInfo(&info)) {
LOG(ERROR) << "GetSystemMemoryInfo failed";
} else {
- if (system_reserved_kb_ == 0) {
- // System reserved memory not configured: we have no idea how much of
- // buffers+cached is safe to treat as usable, so use a simple heuristic
- // based purely on 'free' memory.
- if (info.free < kCriticalFreeMemoryKB)
+ if (system_reserved_kb_ != 0 || info.available != 0) {
+ // Preferred memory pressure heuristic:
+ // 1. Use /proc/meminfo's MemAvailable if possible, fall back to estimate
+ // of free + buffers + cached otherwise.
+ const int total_available =
+ (info.available != 0) ? info.available
+ : (info.free + info.buffers + info.cached);
+
+ // 2. Allow some memory to be 'reserved' on command line.
+ const int available = total_available - system_reserved_kb_;
+ const int total = info.total - system_reserved_kb_;
+ DCHECK_GT(total, 0);
+ const float ratio = available / static_cast<float>(total);
+
+ if (ratio < kCriticalMemoryFraction)
level = base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL;
- else if (info.free < kModerateFreeMemoryKB)
+ else if (ratio < kModerateMemoryFraction)
level = base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE;
} else {
- // Platform has configured the 'reserved' memory; treat buffers plus
- // cached minus reserved as available.
- const float max_free =
- info.free + info.buffers + info.cached - system_reserved_kb_;
- const float total = info.total - system_reserved_kb_;
- DCHECK(total > 0);
-
- if ((max_free / total) < kCriticalMemoryFraction)
+ // Backup method purely using 'free' memory. It may generate more
+ // pressure events than necessary, since more memory may actually be free.
+ if (info.free < kCriticalFreeMemoryKB)
level = base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL;
- else if ((max_free / total) < kModerateMemoryFraction)
+ else if (info.free < kModerateFreeMemoryKB)
level = base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE;
}
}
« 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