Commit b80a48f3 authored by Sebastien Marchand's avatar Sebastien Marchand Committed by Commit Bot

[PM] Urgent discarding policy - only discard on critical pressure


Bug: 1030399
Change-Id: I98304a72ef053569988d82efacfb564f25d4717c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2007981
Auto-Submit: Sébastien Marchand <sebmarchand@chromium.org>
Commit-Queue: François Doray <fdoray@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#733418}
parent a1d2c77c
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/containers/flat_map.h" #include "base/containers/flat_map.h"
#include "base/containers/flat_set.h" #include "base/containers/flat_set.h"
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/memory/memory_pressure_listener.h"
#include "base/sequence_checker.h" #include "base/sequence_checker.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "build/build_config.h" #include "build/build_config.h"
...@@ -89,6 +90,11 @@ void UrgentPageDiscardingPolicy::OnMemoryPressure( ...@@ -89,6 +90,11 @@ void UrgentPageDiscardingPolicy::OnMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel level) { base::MemoryPressureListener::MemoryPressureLevel level) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (level != base::MemoryPressureListener::MemoryPressureLevel::
MEMORY_PRESSURE_LEVEL_CRITICAL) {
return;
}
// The Memory Pressure Monitor will send notifications at regular interval, // The Memory Pressure Monitor will send notifications at regular interval,
// it's important to unregister the pressure listener to ensure that we don't // it's important to unregister the pressure listener to ensure that we don't
// reply to multiple notifications at the same time. // reply to multiple notifications at the same time.
......
...@@ -159,6 +159,9 @@ class UrgentPageDiscardingPolicyTest : public GraphTestHarness { ...@@ -159,6 +159,9 @@ class UrgentPageDiscardingPolicyTest : public GraphTestHarness {
FrameNodeImpl* frame_node() { return main_frame_node_.get(); } FrameNodeImpl* frame_node() { return main_frame_node_.get(); }
void ResetFrameNode() { main_frame_node_.reset(); } void ResetFrameNode() { main_frame_node_.reset(); }
MockPageDiscarder* discarder() { return mock_discarder_; } MockPageDiscarder* discarder() { return mock_discarder_; }
util::test::FakeMemoryPressureMonitor* mem_pressure_monitor() {
return &mem_pressure_monitor_;
}
protected: protected:
// Make sure that |page_node| is discardable. // Make sure that |page_node| is discardable.
...@@ -413,5 +416,14 @@ TEST_F(UrgentPageDiscardingPolicyTest, ...@@ -413,5 +416,14 @@ TEST_F(UrgentPageDiscardingPolicyTest,
testing::Mock::VerifyAndClearExpectations(discarder()); testing::Mock::VerifyAndClearExpectations(discarder());
} }
TEST_F(UrgentPageDiscardingPolicyTest, NoDiscardOnModeratePressure) {
// No tab should be discarded on moderate pressure.
mem_pressure_monitor()->SetAndNotifyMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel::
MEMORY_PRESSURE_LEVEL_MODERATE);
task_env().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(discarder());
}
} // namespace policies } // namespace policies
} // namespace performance_manager } // namespace performance_manager
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