Chromium Code Reviews| 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..776904f0239fab813743dccbf6ecf2b34adf9d48 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,29 @@ 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 float total_available = |
|
wzhong
2016/07/14 21:30:13
Why is it a float? Shouldn't cast only when calcul
halliwell
2016/07/14 23:49:50
Sure, I updated to just cast when calculating rati
|
| + (info.available != 0) ? info.available |
| + : (info.free + info.buffers + info.cached); |
| + |
| + // 2. Allow some memory to be 'reserved' on command line. |
| + const float available = total_available - system_reserved_kb_; |
| + const float total = info.total - system_reserved_kb_; |
| + DCHECK_GT(total, 0.0f); |
| + |
| + if ((available / total) < kCriticalMemoryFraction) |
| level = base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL; |
| - else if (info.free < kModerateFreeMemoryKB) |
| + else if ((available / total) < 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; |
| } |
| } |