Commit 0599ca5e authored by Sebastien Marchand's avatar Sebastien Marchand Committed by Commit Bot

Win OS Memory Pressure signals: address some comments from previous CL.

Change-Id: I6625de68dcac33fd74f768d7fa7c60b899e2f200
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2354527
Commit-Queue: Sébastien Marchand <sebmarchand@chromium.org>
Reviewed-by: default avatarRafael Cintron <rafael.cintron@microsoft.com>
Auto-Submit: Sébastien Marchand <sebmarchand@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797936}
parent cb64c418
...@@ -54,22 +54,18 @@ MemoryPressureWatcherDelegate::MemoryPressureWatcherDelegate( ...@@ -54,22 +54,18 @@ MemoryPressureWatcherDelegate::MemoryPressureWatcherDelegate(
CHECK(watcher_.StartWatchingOnce(handle_.Get(), this)); CHECK(watcher_.StartWatchingOnce(handle_.Get(), this));
} }
MemoryPressureWatcherDelegate::~MemoryPressureWatcherDelegate() { MemoryPressureWatcherDelegate::~MemoryPressureWatcherDelegate() = default;
if (watcher_.IsWatching())
watcher_.StopWatching();
handle_.Close();
}
void MemoryPressureWatcherDelegate::ReplaceWatchedHandleForTesting( void MemoryPressureWatcherDelegate::ReplaceWatchedHandleForTesting(
base::win::ScopedHandle handle) { base::win::ScopedHandle handle) {
if (watcher_.IsWatching()) if (watcher_.IsWatching())
watcher_.StopWatching(); watcher_.StopWatching();
handle_.Close();
handle_ = std::move(handle); handle_ = std::move(handle);
CHECK(watcher_.StartWatchingOnce(handle_.Get(), this)); CHECK(watcher_.StartWatchingOnce(handle_.Get(), this));
} }
void MemoryPressureWatcherDelegate::OnObjectSignaled(HANDLE object) { void MemoryPressureWatcherDelegate::OnObjectSignaled(HANDLE handle) {
DCHECK_EQ(handle, handle_.Get());
std::move(callback_).Run(); std::move(callback_).Run();
} }
...@@ -79,7 +75,8 @@ void MemoryPressureWatcherDelegate::OnObjectSignaled(HANDLE object) { ...@@ -79,7 +75,8 @@ void MemoryPressureWatcherDelegate::OnObjectSignaled(HANDLE object) {
// memory pressure monitor. The values were determined experimentally to ensure // memory pressure monitor. The values were determined experimentally to ensure
// sufficient responsiveness of the memory pressure subsystem, and minimal // sufficient responsiveness of the memory pressure subsystem, and minimal
// overhead. // overhead.
const int SystemMemoryPressureEvaluator::kModeratePressureCooldownMs = 10000; const base::TimeDelta SystemMemoryPressureEvaluator::kModeratePressureCooldown =
base::TimeDelta::FromSeconds(10);
// TODO(chrisha): Explore the following constants further with an experiment. // TODO(chrisha): Explore the following constants further with an experiment.
...@@ -269,9 +266,8 @@ void SystemMemoryPressureEvaluator::CheckMemoryPressure() { ...@@ -269,9 +266,8 @@ void SystemMemoryPressureEvaluator::CheckMemoryPressure() {
// Already in moderate pressure, only notify if sustained over the // Already in moderate pressure, only notify if sustained over the
// cooldown period. // cooldown period.
const int kModeratePressureCooldownCycles = const int kModeratePressureCooldownCycles =
kModeratePressureCooldownMs / kModeratePressureCooldown /
base::MemoryPressureMonitor::kUMAMemoryPressureLevelPeriod base::MemoryPressureMonitor::kUMAMemoryPressureLevelPeriod;
.InMilliseconds();
if (++moderate_pressure_repeat_count_ == if (++moderate_pressure_repeat_count_ ==
kModeratePressureCooldownCycles) { kModeratePressureCooldownCycles) {
moderate_pressure_repeat_count_ = 0; moderate_pressure_repeat_count_ = 0;
......
...@@ -33,7 +33,7 @@ class SystemMemoryPressureEvaluator ...@@ -33,7 +33,7 @@ class SystemMemoryPressureEvaluator
// Constants governing the polling and hysteresis behaviour of the observer. // Constants governing the polling and hysteresis behaviour of the observer.
// The time which should pass between 2 successive moderate memory pressure // The time which should pass between 2 successive moderate memory pressure
// signals, in milliseconds. // signals, in milliseconds.
static const int kModeratePressureCooldownMs; static const base::TimeDelta kModeratePressureCooldown;
// Constants governing the memory pressure level detection. // Constants governing the memory pressure level detection.
......
...@@ -241,9 +241,8 @@ TEST_F(WinSystemMemoryPressureEvaluatorTest, CheckMemoryPressure) { ...@@ -241,9 +241,8 @@ TEST_F(WinSystemMemoryPressureEvaluatorTest, CheckMemoryPressure) {
// Check that the event gets reposted after a while. // Check that the event gets reposted after a while.
const int kModeratePressureCooldownCycles = const int kModeratePressureCooldownCycles =
evaluator.kModeratePressureCooldownMs / evaluator.kModeratePressureCooldown /
base::MemoryPressureMonitor::kUMAMemoryPressureLevelPeriod base::MemoryPressureMonitor::kUMAMemoryPressureLevelPeriod;
.InMilliseconds();
for (int i = 0; i < kModeratePressureCooldownCycles; ++i) { for (int i = 0; i < kModeratePressureCooldownCycles; ++i) {
if (i + 1 == kModeratePressureCooldownCycles) { if (i + 1 == kModeratePressureCooldownCycles) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment