Commit 21fb10d0 authored by Sebastien Marchand's avatar Sebastien Marchand Committed by Commit Bot

Add the fieldtrial config for UrgentDiscardingFromPerformanceManager

Bug: 1030399
Change-Id: Iae8a083d00e95c4214e360303f30bd2d7dea45e2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2056107
Commit-Queue: Sébastien Marchand <sebmarchand@chromium.org>
Commit-Queue: Alexei Svitkine <asvitkine@chromium.org>
Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Auto-Submit: Sébastien Marchand <sebmarchand@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742266}
parent 0afae3ca
......@@ -9,6 +9,7 @@
#include "base/memory/memory_pressure_listener.h"
#include "base/run_loop.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/simple_test_tick_clock.h"
#include "base/util/memory_pressure/fake_memory_pressure_monitor.h"
#include "build/build_config.h"
......@@ -16,6 +17,7 @@
#include "chrome/browser/devtools/devtools_window_testing.h"
#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
#include "chrome/browser/media/webrtc/media_stream_capture_indicator.h"
#include "chrome/browser/performance_manager/graph/policies/policy_features.h"
#include "chrome/browser/resource_coordinator/local_site_characteristics_data_unittest_utils.h"
#include "chrome/browser/resource_coordinator/tab_lifecycle_observer.h"
#include "chrome/browser/resource_coordinator/tab_lifecycle_unit.h"
......@@ -487,66 +489,6 @@ IN_PROC_BROWSER_TEST_F(TabManagerTest, TabManagerBasics) {
EXPECT_TRUE(chrome::CanGoForward(browser()));
}
// On Linux, memory pressure listener is not implemented yet.
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
// Test that the MemoryPressureListener event is properly triggering a tab
// discard upon |MEMORY_PRESSURE_LEVEL_CRITICAL| event.
IN_PROC_BROWSER_TEST_F(TabManagerTest, OomPressureListener) {
// Get two tabs open.
content::WindowedNotificationObserver load1(
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources());
OpenURLParams open1(GURL(chrome::kChromeUIAboutURL), content::Referrer(),
WindowOpenDisposition::CURRENT_TAB,
ui::PAGE_TRANSITION_TYPED, false);
browser()->OpenURL(open1);
load1.Wait();
content::WindowedNotificationObserver load2(
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources());
OpenURLParams open2(GURL(chrome::kChromeUICreditsURL), content::Referrer(),
WindowOpenDisposition::NEW_FOREGROUND_TAB,
ui::PAGE_TRANSITION_TYPED, false);
browser()->OpenURL(open2);
load2.Wait();
ASSERT_EQ(tsm()->count(), 2);
EXPECT_FALSE(IsTabDiscarded(GetWebContentsAt(0)));
EXPECT_FALSE(IsTabDiscarded(GetWebContentsAt(1)));
// Advance time so everything is urgent discardable.
test_clock_.Advance(kBackgroundUrgentProtectionTime);
// Nothing should happen with a moderate memory pressure event.
fake_memory_pressure_monitor_.SetAndNotifyMemoryPressure(
base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE);
EXPECT_FALSE(IsTabDiscarded(GetWebContentsAt(0)));
EXPECT_FALSE(IsTabDiscarded(GetWebContentsAt(1)));
// A critical memory pressure event should discard a tab.
fake_memory_pressure_monitor_.SetAndNotifyMemoryPressure(
base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL);
// Coming here, an asynchronous operation will collect system stats. Once in,
// a tab should get discarded. As such we need to give it 10s time to discard.
const int kTimeoutTimeInMS = 10000;
const int kIntervalTimeInMS = 5;
int timeout = kTimeoutTimeInMS / kIntervalTimeInMS;
while (--timeout) {
base::PlatformThread::Sleep(
base::TimeDelta::FromMilliseconds(kIntervalTimeInMS));
base::RunLoop().RunUntilIdle();
if (IsTabDiscarded(GetWebContentsAt(0)))
break;
}
EXPECT_TRUE(IsTabDiscarded(GetWebContentsAt(0)));
EXPECT_FALSE(IsTabDiscarded(GetWebContentsAt(1)));
}
#endif
IN_PROC_BROWSER_TEST_F(TabManagerTest, InvalidOrEmptyURL) {
// Open two tabs. Wait for the foreground one to load but do not wait for the
// background one.
......@@ -617,83 +559,6 @@ IN_PROC_BROWSER_TEST_F(TabManagerTest, TabDiscardDoneCallback) {
EXPECT_TRUE(callback_state.called_);
}
// On Linux, memory pressure listener is not implemented yet.
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
IN_PROC_BROWSER_TEST_F(TabManagerTest, RegisterMemoryPressureListener) {
// Open two tabs. Wait for the foreground one to load but do not wait for the
// background one.
content::WindowedNotificationObserver load1(
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources());
OpenURLParams open1(GURL(chrome::kChromeUIAboutURL), content::Referrer(),
WindowOpenDisposition::CURRENT_TAB,
ui::PAGE_TRANSITION_TYPED, false);
browser()->OpenURL(open1);
load1.Wait();
content::WindowedNotificationObserver load2(
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources());
OpenURLParams open2(GURL(chrome::kChromeUICreditsURL), content::Referrer(),
WindowOpenDisposition::NEW_BACKGROUND_TAB,
ui::PAGE_TRANSITION_TYPED, false);
browser()->OpenURL(open2);
load2.Wait();
ASSERT_EQ(2, tsm()->count());
EXPECT_FALSE(IsTabDiscarded(GetWebContentsAt(0)));
EXPECT_FALSE(IsTabDiscarded(GetWebContentsAt(1)));
// Advance time so everything is urgent discardable.
test_clock_.Advance(kBackgroundUrgentProtectionTime);
// After receiving memory pressure, the background tab should be discarded.
// A critical memory pressure event should discard a tab.
fake_memory_pressure_monitor_.SetAndNotifyMemoryPressure(
base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL);
if (!IsTabDiscarded(GetWebContentsAt(1))) {
DiscardWaiter discard_waiter;
discard_waiter.Wait();
}
// Critical memory pressure should make the background tab discarded.
EXPECT_FALSE(IsTabDiscarded(GetWebContentsAt(0)));
EXPECT_TRUE(IsTabDiscarded(GetWebContentsAt(1)));
// Open another background tab.
content::WindowedNotificationObserver load3(
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources());
OpenURLParams open3(GURL(chrome::kChromeUICreditsURL), content::Referrer(),
WindowOpenDisposition::NEW_BACKGROUND_TAB,
ui::PAGE_TRANSITION_TYPED, false);
browser()->OpenURL(open3);
load3.Wait();
ASSERT_EQ(3, tsm()->count());
// Advance time again so the new background tab is discardable.
test_clock_.Advance(kBackgroundUrgentProtectionTime);
// After receiving another critical memory pressure, the new background tab
// should be discarded. This verifies that the memory pressure listener is
// registered back when the previous dicard finished.
fake_memory_pressure_monitor_.SetAndNotifyMemoryPressure(
base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL);
if (!IsTabDiscarded(GetWebContentsAt(2))) {
DiscardWaiter discard_waiter;
discard_waiter.Wait();
}
// Critical memory pressure should make the background tab discarded.
EXPECT_FALSE(IsTabDiscarded(GetWebContentsAt(0)));
EXPECT_TRUE(IsTabDiscarded(GetWebContentsAt(1)));
EXPECT_TRUE(IsTabDiscarded(GetWebContentsAt(2)));
}
#endif
// Makes sure that PDF pages are protected.
IN_PROC_BROWSER_TEST_F(TabManagerTest, ProtectPDFPages) {
// Start the embedded test server so we can get served the required PDF page.
......@@ -1377,6 +1242,155 @@ IN_PROC_BROWSER_TEST_F(TabManagerTest, UnfreezeTabOnNavigationEvent) {
expect_state_transition.Wait();
}
// On Linux, memory pressure listener is not implemented yet.
#if !defined(OS_LINUX)
class TabManagerMemoryPressureTest : public TabManagerTest {
public:
TabManagerMemoryPressureTest() {
scoped_feature_list_.InitAndDisableFeature(
performance_manager::features::kUrgentDiscardingFromPerformanceManager);
}
~TabManagerMemoryPressureTest() override = default;
TabManagerMemoryPressureTest(const TabManagerMemoryPressureTest& other) =
delete;
TabManagerMemoryPressureTest& operator=(const TabManagerMemoryPressureTest&) =
delete;
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
// Test that the MemoryPressureListener event is properly triggering a tab
// discard upon |MEMORY_PRESSURE_LEVEL_CRITICAL| event.
IN_PROC_BROWSER_TEST_F(TabManagerMemoryPressureTest, OomPressureListener) {
// Get two tabs open.
content::WindowedNotificationObserver load1(
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources());
OpenURLParams open1(GURL(chrome::kChromeUIAboutURL), content::Referrer(),
WindowOpenDisposition::CURRENT_TAB,
ui::PAGE_TRANSITION_TYPED, false);
browser()->OpenURL(open1);
load1.Wait();
content::WindowedNotificationObserver load2(
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources());
OpenURLParams open2(GURL(chrome::kChromeUICreditsURL), content::Referrer(),
WindowOpenDisposition::NEW_FOREGROUND_TAB,
ui::PAGE_TRANSITION_TYPED, false);
browser()->OpenURL(open2);
load2.Wait();
ASSERT_EQ(tsm()->count(), 2);
EXPECT_FALSE(IsTabDiscarded(GetWebContentsAt(0)));
EXPECT_FALSE(IsTabDiscarded(GetWebContentsAt(1)));
// Advance time so everything is urgent discardable.
test_clock_.Advance(kBackgroundUrgentProtectionTime);
// Nothing should happen with a moderate memory pressure event.
fake_memory_pressure_monitor_.SetAndNotifyMemoryPressure(
base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE);
EXPECT_FALSE(IsTabDiscarded(GetWebContentsAt(0)));
EXPECT_FALSE(IsTabDiscarded(GetWebContentsAt(1)));
// A critical memory pressure event should discard a tab.
fake_memory_pressure_monitor_.SetAndNotifyMemoryPressure(
base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL);
// Coming here, an asynchronous operation will collect system stats. Once in,
// a tab should get discarded. As such we need to give it 10s time to discard.
const int kTimeoutTimeInMS = 10000;
const int kIntervalTimeInMS = 5;
int timeout = kTimeoutTimeInMS / kIntervalTimeInMS;
while (--timeout) {
base::PlatformThread::Sleep(
base::TimeDelta::FromMilliseconds(kIntervalTimeInMS));
base::RunLoop().RunUntilIdle();
if (IsTabDiscarded(GetWebContentsAt(0)))
break;
}
EXPECT_TRUE(IsTabDiscarded(GetWebContentsAt(0)));
EXPECT_FALSE(IsTabDiscarded(GetWebContentsAt(1)));
}
IN_PROC_BROWSER_TEST_F(TabManagerMemoryPressureTest,
RegisterMemoryPressureListener) {
// Open two tabs. Wait for the foreground one to load but do not wait for the
// background one.
content::WindowedNotificationObserver load1(
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources());
OpenURLParams open1(GURL(chrome::kChromeUIAboutURL), content::Referrer(),
WindowOpenDisposition::CURRENT_TAB,
ui::PAGE_TRANSITION_TYPED, false);
browser()->OpenURL(open1);
load1.Wait();
content::WindowedNotificationObserver load2(
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources());
OpenURLParams open2(GURL(chrome::kChromeUICreditsURL), content::Referrer(),
WindowOpenDisposition::NEW_BACKGROUND_TAB,
ui::PAGE_TRANSITION_TYPED, false);
browser()->OpenURL(open2);
load2.Wait();
ASSERT_EQ(2, tsm()->count());
EXPECT_FALSE(IsTabDiscarded(GetWebContentsAt(0)));
EXPECT_FALSE(IsTabDiscarded(GetWebContentsAt(1)));
// Advance time so everything is urgent discardable.
test_clock_.Advance(kBackgroundUrgentProtectionTime);
// After receiving memory pressure, the background tab should be discarded.
// A critical memory pressure event should discard a tab.
fake_memory_pressure_monitor_.SetAndNotifyMemoryPressure(
base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL);
if (!IsTabDiscarded(GetWebContentsAt(1))) {
DiscardWaiter discard_waiter;
discard_waiter.Wait();
}
// Critical memory pressure should make the background tab discarded.
EXPECT_FALSE(IsTabDiscarded(GetWebContentsAt(0)));
EXPECT_TRUE(IsTabDiscarded(GetWebContentsAt(1)));
// Open another background tab.
content::WindowedNotificationObserver load3(
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources());
OpenURLParams open3(GURL(chrome::kChromeUICreditsURL), content::Referrer(),
WindowOpenDisposition::NEW_BACKGROUND_TAB,
ui::PAGE_TRANSITION_TYPED, false);
browser()->OpenURL(open3);
load3.Wait();
ASSERT_EQ(3, tsm()->count());
// Advance time again so the new background tab is discardable.
test_clock_.Advance(kBackgroundUrgentProtectionTime);
// After receiving another critical memory pressure, the new background tab
// should be discarded. This verifies that the memory pressure listener is
// registered back when the previous discard finished.
fake_memory_pressure_monitor_.SetAndNotifyMemoryPressure(
base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL);
if (!IsTabDiscarded(GetWebContentsAt(2))) {
DiscardWaiter discard_waiter;
discard_waiter.Wait();
}
// Critical memory pressure should make the background tab discarded.
EXPECT_FALSE(IsTabDiscarded(GetWebContentsAt(0)));
EXPECT_TRUE(IsTabDiscarded(GetWebContentsAt(1)));
EXPECT_TRUE(IsTabDiscarded(GetWebContentsAt(2)));
}
#endif // !OS_LINUX
} // namespace resource_coordinator
#endif // OS_WIN || OS_MAXOSX || OS_LINUX || defined(OS_CHROMEOS)
......@@ -5305,31 +5305,6 @@
]
}
],
"ProactiveTabFreezeAndDiscard": [
{
"platforms": [
"chromeos",
"linux",
"mac",
"windows"
],
"experiments": [
{
"name": "Enabled",
"params": {
"HighLoadedTabCount": "1000",
"ShouldPeriodicallyUnfreeze": "true",
"ShouldProactivelyDiscard": "false",
"ShouldProtectTabsSharingBrowsingInstance": "true"
},
"enable_features": [
"ProactiveTabFreezeAndDiscard",
"stop-non-timers-in-background"
]
}
]
}
],
"ProactivelySwapBrowsingInstance": [
{
"platforms": [
......@@ -7181,6 +7156,21 @@
]
}
],
"UrgentDiscardingFromPerformanceManager": [
{
"platforms": [
"windows"
],
"experiments": [
{
"name": "Enabled_20200129",
"enable_features": [
"UrgentDiscardingFromPerformanceManager"
]
}
]
}
],
"UseFluentLanguageModel": [
{
"platforms": [
......
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