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

Unified Diff: base/chromeos/memory_pressure_observer_chromeos.cc

Issue 803443006: Adding flag to specify the used memory pressure strategy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing unit test 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
Index: base/chromeos/memory_pressure_observer_chromeos.cc
diff --git a/base/chromeos/memory_pressure_observer_chromeos.cc b/base/chromeos/memory_pressure_observer_chromeos.cc
index 4da7d24bfdb75a38bb9be99b5877819b8c5ed3bf..5ed8c511fcf46cbac0cc0bece2fc77cfe1c898e5 100644
--- a/base/chromeos/memory_pressure_observer_chromeos.cc
+++ b/base/chromeos/memory_pressure_observer_chromeos.cc
@@ -24,25 +24,58 @@ const int kModerateMemoryPressureCooldown =
kModerateMemoryPressureCooldownMs / kMemoryPressureIntervalMs;
// Threshold constants to emit pressure events.
-const int kMemoryPressureModerateThresholdPercent = 70;
-const int kMemoryPressureCriticalThresholdPercent = 90;
+const int kNormalMemoryPressureModerateThresholdPercent = 60;
+const int kNormalMemoryPressureCriticalThresholdPercent = 90;
+const int kAggressiveMemoryPressureModerateThresholdPercent = 35;
+const int kAggressiveMemoryPressureCriticalThresholdPercent = 70;
+
+// Converts a |MemoryPressureThreshold| value into a used memory percentage for
+// the moderate pressure event.
+int GetModerateMemoryThresholdInPercent(
+ MemoryPressureObserverChromeOS::MemoryPressureThresholds thresholds) {
+ return thresholds == MemoryPressureObserverChromeOS::
+ MEMORY_PRESSURE_THRESHOLD_AGGRESSIVE_CACHE_DISCARD ||
James Cook 2015/01/21 21:24:25 nit: Given that these are namespaced with MemoryPr
Mr4D (OOO till 08-26) 2015/01/21 21:54:34 Done.
+ thresholds == MemoryPressureObserverChromeOS::
+ MEMORY_PRESSURE_THRESHOLD_AGGRESSIVE
+ ? kAggressiveMemoryPressureModerateThresholdPercent
+ : kNormalMemoryPressureModerateThresholdPercent;
+}
+
+// Converts a |MemoryPressureThreshold| value into a used memory percentage for
+// the critical pressure event.
+int GetCriticalMemoryThresholdInPercent(
+ MemoryPressureObserverChromeOS::MemoryPressureThresholds thresholds) {
+ return thresholds == MemoryPressureObserverChromeOS::
+ MEMORY_PRESSURE_THRESHOLD_AGGRESSIVE_TAB_DISCARD ||
+ thresholds == MemoryPressureObserverChromeOS::
+ MEMORY_PRESSURE_THRESHOLD_AGGRESSIVE
+ ? kAggressiveMemoryPressureCriticalThresholdPercent
+ : kNormalMemoryPressureCriticalThresholdPercent;
+}
// Converts free percent of memory into a memory pressure value.
MemoryPressureListener::MemoryPressureLevel GetMemoryPressureLevelFromFillLevel(
- int memory_fill_level) {
- if (memory_fill_level < kMemoryPressureModerateThresholdPercent)
+ int actual_fill_level,
+ int moderate_threshold,
+ int critical_threshold) {
+ if (actual_fill_level < moderate_threshold)
return MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE;
- return memory_fill_level < kMemoryPressureCriticalThresholdPercent ?
- MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE :
- MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL;
+ return actual_fill_level < critical_threshold
+ ? MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE
+ : MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL;
}
} // namespace
-MemoryPressureObserverChromeOS::MemoryPressureObserverChromeOS()
+MemoryPressureObserverChromeOS::MemoryPressureObserverChromeOS(
+ MemoryPressureThresholds thresholds)
: current_memory_pressure_level_(
- MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE),
+ MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE),
moderate_pressure_repeat_count_(0),
+ moderate_pressure_threshold_(
+ GetModerateMemoryThresholdInPercent(thresholds)),
+ critical_pressure_threshold_(
+ GetCriticalMemoryThresholdInPercent(thresholds)),
weak_ptr_factory_(this) {
StartObserving();
}
@@ -74,7 +107,9 @@ void MemoryPressureObserverChromeOS::CheckMemoryPressure() {
MemoryPressureListener::MemoryPressureLevel old_pressure =
current_memory_pressure_level_;
current_memory_pressure_level_ =
- GetMemoryPressureLevelFromFillLevel(GetUsedMemoryInPercent());
+ GetMemoryPressureLevelFromFillLevel(GetUsedMemoryInPercent(),
+ moderate_pressure_threshold_,
+ critical_pressure_threshold_);
// In case there is no memory pressure we do not notify.
if (current_memory_pressure_level_ ==
MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) {

Powered by Google App Engine
This is Rietveld 408576698