<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[214294] trunk/Source</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/214294">214294</a></dd>
<dt>Author</dt> <dd>akling@apple.com</dd>
<dt>Date</dt> <dd>2017-03-22 21:14:03 -0700 (Wed, 22 Mar 2017)</dd>
</dl>
<h3>Log Message</h3>
<pre>Let MemoryPressureHandler track whether the process is active or inactive.
<https://webkit.org/b/169990>
Reviewed by Antti Koivisto.
Source/WebCore:
Have PerformanceMonitor inform MemoryPressureHandler about relevant
changes to the page activity states.
Also change the "1 hour after last page load" policy to "1 hour after
last being visible in an active window."
* page/MainFrame.cpp:
(WebCore::MainFrame::didCompleteLoad):
* page/MainFrame.h:
* page/MemoryRelease.cpp:
(WebCore::processIsEligibleForMemoryKill): Deleted.
* page/MemoryRelease.h:
* page/Page.h:
(WebCore::Page::performanceMonitor):
* page/PerformanceMonitor.cpp:
(WebCore::PerformanceMonitor::PerformanceMonitor):
(WebCore::PerformanceMonitor::activityStateChanged):
(WebCore::PerformanceMonitor::processMayBecomeInactiveTimerFired):
(WebCore::PerformanceMonitor::updateProcessStateForMemoryPressure):
* page/PerformanceMonitor.h:
Source/WebKit2:
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::initializeWebProcess):
Source/WTF:
An active process is a process that meets any of these criteria:
- Has had a visible Page in an active window in the last hour
- Is playing audio
This replaces the old mechanism where MemoryPressureHandler would invoke
a callback to know whether the process was eligible for a memory kill.
Instead we now plumb the relevant information down from WebCore and kill
based on this activity state.
* wtf/MemoryPressureHandler.cpp:
(WTF::MemoryPressureHandler::measurementTimerFired):
(WTF::MemoryPressureHandler::setProcessState):
* wtf/MemoryPressureHandler.h:
(WTF::MemoryPressureHandler::setMemoryKillCallback):
(WTF::MemoryPressureHandler::processState):
(WTF::MemoryPressureHandler::setProcessIsEligibleForMemoryKillCallback): Deleted.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtfMemoryPressureHandlercpp">trunk/Source/WTF/wtf/MemoryPressureHandler.cpp</a></li>
<li><a href="#trunkSourceWTFwtfMemoryPressureHandlerh">trunk/Source/WTF/wtf/MemoryPressureHandler.h</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorepageMainFramecpp">trunk/Source/WebCore/page/MainFrame.cpp</a></li>
<li><a href="#trunkSourceWebCorepageMainFrameh">trunk/Source/WebCore/page/MainFrame.h</a></li>
<li><a href="#trunkSourceWebCorepageMemoryReleasecpp">trunk/Source/WebCore/page/MemoryRelease.cpp</a></li>
<li><a href="#trunkSourceWebCorepageMemoryReleaseh">trunk/Source/WebCore/page/MemoryRelease.h</a></li>
<li><a href="#trunkSourceWebCorepagePageh">trunk/Source/WebCore/page/Page.h</a></li>
<li><a href="#trunkSourceWebCorepagePerformanceMonitorcpp">trunk/Source/WebCore/page/PerformanceMonitor.cpp</a></li>
<li><a href="#trunkSourceWebCorepagePerformanceMonitorh">trunk/Source/WebCore/page/PerformanceMonitor.h</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebProcesscpp">trunk/Source/WebKit2/WebProcess/WebProcess.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (214293 => 214294)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2017-03-23 02:44:57 UTC (rev 214293)
+++ trunk/Source/WTF/ChangeLog        2017-03-23 04:14:03 UTC (rev 214294)
</span><span class="lines">@@ -1,3 +1,28 @@
</span><ins>+2017-03-22 Andreas Kling <akling@apple.com>
+
+ Let MemoryPressureHandler track whether the process is active or inactive.
+ <https://webkit.org/b/169990>
+
+ Reviewed by Antti Koivisto.
+
+ An active process is a process that meets any of these criteria:
+
+ - Has had a visible Page in an active window in the last hour
+ - Is playing audio
+
+ This replaces the old mechanism where MemoryPressureHandler would invoke
+ a callback to know whether the process was eligible for a memory kill.
+ Instead we now plumb the relevant information down from WebCore and kill
+ based on this activity state.
+
+ * wtf/MemoryPressureHandler.cpp:
+ (WTF::MemoryPressureHandler::measurementTimerFired):
+ (WTF::MemoryPressureHandler::setProcessState):
+ * wtf/MemoryPressureHandler.h:
+ (WTF::MemoryPressureHandler::setMemoryKillCallback):
+ (WTF::MemoryPressureHandler::processState):
+ (WTF::MemoryPressureHandler::setProcessIsEligibleForMemoryKillCallback): Deleted.
+
</ins><span class="cx"> 2017-03-20 Simon Fraser <simon.fraser@apple.com>
</span><span class="cx">
</span><span class="cx"> Add a system trace point for memory warning handling
</span></span></pre></div>
<a id="trunkSourceWTFwtfMemoryPressureHandlercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/MemoryPressureHandler.cpp (214293 => 214294)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/MemoryPressureHandler.cpp        2017-03-23 02:44:57 UTC (rev 214293)
+++ trunk/Source/WTF/wtf/MemoryPressureHandler.cpp        2017-03-23 04:14:03 UTC (rev 214294)
</span><span class="lines">@@ -143,11 +143,9 @@
</span><span class="cx"> RELEASE_ASSERT(newPolicy == MemoryUsagePolicy::Panic);
</span><span class="cx">
</span><span class="cx"> RELEASE_LOG(MemoryPressure, "Attempting to reduce memory footprint by freeing more important objects.");
</span><del>- if (m_processIsEligibleForMemoryKillCallback) {
- if (!m_processIsEligibleForMemoryKillCallback()) {
- releaseMemory(Critical::Yes, Synchronous::No);
- return;
- }
</del><ins>+ if (m_processState == WebsamProcessState::Active) {
+ releaseMemory(Critical::Yes, Synchronous::No);
+ return;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> releaseMemory(Critical::Yes, Synchronous::Yes);
</span><span class="lines">@@ -168,6 +166,13 @@
</span><span class="cx"> m_memoryKillCallback();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void MemoryPressureHandler::setProcessState(WebsamProcessState state)
+{
+ if (m_processState == state)
+ return;
+ m_processState = state;
+}
+
</ins><span class="cx"> void MemoryPressureHandler::beginSimulatedMemoryPressure()
</span><span class="cx"> {
</span><span class="cx"> if (m_isSimulatingMemoryPressure)
</span></span></pre></div>
<a id="trunkSourceWTFwtfMemoryPressureHandlerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/MemoryPressureHandler.h (214293 => 214294)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/MemoryPressureHandler.h        2017-03-23 02:44:57 UTC (rev 214293)
+++ trunk/Source/WTF/wtf/MemoryPressureHandler.h        2017-03-23 04:14:03 UTC (rev 214294)
</span><span class="lines">@@ -52,6 +52,11 @@
</span><span class="cx"> Panic, // OH GOD WE'RE SINKING, THROW EVERYTHING OVERBOARD
</span><span class="cx"> };
</span><span class="cx">
</span><ins>+enum class WebsamProcessState {
+ Active,
+ Inactive,
+};
+
</ins><span class="cx"> enum class Critical { No, Yes };
</span><span class="cx"> enum class Synchronous { No, Yes };
</span><span class="cx">
</span><span class="lines">@@ -67,7 +72,6 @@
</span><span class="cx"> WTF_EXPORT_PRIVATE void setShouldUsePeriodicMemoryMonitor(bool);
</span><span class="cx">
</span><span class="cx"> void setMemoryKillCallback(WTF::Function<void()> function) { m_memoryKillCallback = WTFMove(function); }
</span><del>- void setProcessIsEligibleForMemoryKillCallback(WTF::Function<bool()> function) { m_processIsEligibleForMemoryKillCallback = WTFMove(function); }
</del><span class="cx"> void setMemoryPressureStatusChangedCallback(WTF::Function<void(bool)> function) { m_memoryPressureStatusChangedCallback = WTFMove(function); }
</span><span class="cx">
</span><span class="cx"> void setLowMemoryHandler(LowMemoryHandler&& handler)
</span><span class="lines">@@ -140,6 +144,9 @@
</span><span class="cx"> WTF_EXPORT_PRIVATE void beginSimulatedMemoryPressure();
</span><span class="cx"> WTF_EXPORT_PRIVATE void endSimulatedMemoryPressure();
</span><span class="cx">
</span><ins>+ WTF_EXPORT_PRIVATE void setProcessState(WebsamProcessState);
+ WebsamProcessState processState() const { return m_processState; }
+
</ins><span class="cx"> private:
</span><span class="cx"> void memoryPressureStatusChanged();
</span><span class="cx">
</span><span class="lines">@@ -177,6 +184,8 @@
</span><span class="cx"> };
</span><span class="cx"> #endif
</span><span class="cx">
</span><ins>+ WebsamProcessState m_processState { WebsamProcessState::Inactive };
+
</ins><span class="cx"> bool m_installed { false };
</span><span class="cx"> LowMemoryHandler m_lowMemoryHandler;
</span><span class="cx">
</span><span class="lines">@@ -186,7 +195,6 @@
</span><span class="cx"> std::unique_ptr<RunLoop::Timer<MemoryPressureHandler>> m_measurementTimer;
</span><span class="cx"> MemoryUsagePolicy m_memoryUsagePolicy { MemoryUsagePolicy::Unrestricted };
</span><span class="cx"> WTF::Function<void()> m_memoryKillCallback;
</span><del>- WTF::Function<bool()> m_processIsEligibleForMemoryKillCallback;
</del><span class="cx"> WTF::Function<void(bool)> m_memoryPressureStatusChangedCallback;
</span><span class="cx">
</span><span class="cx"> #if OS(WINDOWS)
</span><span class="lines">@@ -213,3 +221,4 @@
</span><span class="cx"> using WTF::Critical;
</span><span class="cx"> using WTF::MemoryPressureHandler;
</span><span class="cx"> using WTF::Synchronous;
</span><ins>+using WTF::WebsamProcessState;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (214293 => 214294)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2017-03-23 02:44:57 UTC (rev 214293)
+++ trunk/Source/WebCore/ChangeLog        2017-03-23 04:14:03 UTC (rev 214294)
</span><span class="lines">@@ -1,3 +1,31 @@
</span><ins>+2017-03-22 Andreas Kling <akling@apple.com>
+
+ Let MemoryPressureHandler track whether the process is active or inactive.
+ <https://webkit.org/b/169990>
+
+ Reviewed by Antti Koivisto.
+
+ Have PerformanceMonitor inform MemoryPressureHandler about relevant
+ changes to the page activity states.
+
+ Also change the "1 hour after last page load" policy to "1 hour after
+ last being visible in an active window."
+
+ * page/MainFrame.cpp:
+ (WebCore::MainFrame::didCompleteLoad):
+ * page/MainFrame.h:
+ * page/MemoryRelease.cpp:
+ (WebCore::processIsEligibleForMemoryKill): Deleted.
+ * page/MemoryRelease.h:
+ * page/Page.h:
+ (WebCore::Page::performanceMonitor):
+ * page/PerformanceMonitor.cpp:
+ (WebCore::PerformanceMonitor::PerformanceMonitor):
+ (WebCore::PerformanceMonitor::activityStateChanged):
+ (WebCore::PerformanceMonitor::processMayBecomeInactiveTimerFired):
+ (WebCore::PerformanceMonitor::updateProcessStateForMemoryPressure):
+ * page/PerformanceMonitor.h:
+
</ins><span class="cx"> 2017-03-22 Youenn Fablet <youenn@apple.com>
</span><span class="cx">
</span><span class="cx"> Support RTCPeerConnectionState
</span></span></pre></div>
<a id="trunkSourceWebCorepageMainFramecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/MainFrame.cpp (214293 => 214294)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/MainFrame.cpp        2017-03-23 02:44:57 UTC (rev 214293)
+++ trunk/Source/WebCore/page/MainFrame.cpp        2017-03-23 04:14:03 UTC (rev 214294)
</span><span class="lines">@@ -97,7 +97,6 @@
</span><span class="cx">
</span><span class="cx"> void MainFrame::didCompleteLoad()
</span><span class="cx"> {
</span><del>- m_timeOfLastCompletedLoad = MonotonicTime::now();
</del><span class="cx"> performanceLogging().didReachPointOfInterest(PerformanceLogging::MainFrameLoadCompleted);
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCorepageMainFrameh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/MainFrame.h (214293 => 214294)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/MainFrame.h        2017-03-23 02:44:57 UTC (rev 214293)
+++ trunk/Source/WebCore/page/MainFrame.h        2017-03-23 04:14:03 UTC (rev 214294)
</span><span class="lines">@@ -70,7 +70,6 @@
</span><span class="cx"> PerformanceLogging& performanceLogging() const { return *m_performanceLogging; }
</span><span class="cx">
</span><span class="cx"> void didCompleteLoad();
</span><del>- MonotonicTime timeOfLastCompletedLoad() const { return m_timeOfLastCompletedLoad; }
</del><span class="cx">
</span><span class="cx"> private:
</span><span class="cx"> MainFrame(Page&, PageConfiguration&);
</span><span class="lines">@@ -94,8 +93,6 @@
</span><span class="cx"> #endif
</span><span class="cx">
</span><span class="cx"> std::unique_ptr<PerformanceLogging> m_performanceLogging;
</span><del>-
- MonotonicTime m_timeOfLastCompletedLoad;
</del><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCorepageMemoryReleasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/MemoryRelease.cpp (214293 => 214294)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/MemoryRelease.cpp        2017-03-23 02:44:57 UTC (rev 214293)
+++ trunk/Source/WebCore/page/MemoryRelease.cpp        2017-03-23 04:14:03 UTC (rev 214294)
</span><span class="lines">@@ -193,33 +193,6 @@
</span><span class="cx"> CRASH();
</span><span class="cx"> }
</span><span class="cx">
</span><del>-bool processIsEligibleForMemoryKill()
-{
- bool hasVisiblePages = false;
- bool hasAudiblePages = false;
- bool hasMainFrameNavigatedInTheLastHour = false;
-
- auto now = MonotonicTime::now();
- Page::forEachPage([&] (Page& page) {
- if (page.isUtilityPage())
- return;
- if (page.isVisible())
- hasVisiblePages = true;
- if (page.activityState() & ActivityState::IsAudible)
- hasAudiblePages = true;
- if (auto timeOfLastCompletedLoad = page.mainFrame().timeOfLastCompletedLoad()) {
- if (now - timeOfLastCompletedLoad <= Seconds::fromMinutes(60))
- hasMainFrameNavigatedInTheLastHour = true;
- }
- });
-
- bool eligible = !hasVisiblePages && !hasAudiblePages && !hasMainFrameNavigatedInTheLastHour;
- if (!eligible)
- RELEASE_LOG(MemoryPressure, "Process not eligible for panic memory kill. Reasons: hasVisiblePages=%u, hasAudiblePages=%u, hasMainFrameNavigatedInTheLastHour=%u", hasVisiblePages, hasAudiblePages, hasMainFrameNavigatedInTheLastHour);
-
- return eligible;
-}
-
</del><span class="cx"> #if !PLATFORM(COCOA)
</span><span class="cx"> void platformReleaseMemory(Critical) { }
</span><span class="cx"> void jettisonExpensiveObjectsOnTopLevelNavigation() { }
</span></span></pre></div>
<a id="trunkSourceWebCorepageMemoryReleaseh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/MemoryRelease.h (214293 => 214294)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/MemoryRelease.h        2017-03-23 02:44:57 UTC (rev 214293)
+++ trunk/Source/WebCore/page/MemoryRelease.h        2017-03-23 04:14:03 UTC (rev 214294)
</span><span class="lines">@@ -35,6 +35,5 @@
</span><span class="cx"> WEBCORE_EXPORT void registerMemoryReleaseNotifyCallbacks();
</span><span class="cx"> WEBCORE_EXPORT void logMemoryStatisticsAtTimeOfDeath();
</span><span class="cx"> WEBCORE_EXPORT NO_RETURN_DUE_TO_CRASH void didExceedMemoryLimitAndFailedToRecover();
</span><del>-WEBCORE_EXPORT bool processIsEligibleForMemoryKill();
</del><span class="cx">
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCorepagePageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/Page.h (214293 => 214294)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/Page.h        2017-03-23 02:44:57 UTC (rev 214293)
+++ trunk/Source/WebCore/page/Page.h        2017-03-23 04:14:03 UTC (rev 214294)
</span><span class="lines">@@ -226,6 +226,7 @@
</span><span class="cx"> #endif
</span><span class="cx"> LibWebRTCProvider& libWebRTCProvider() { return m_libWebRTCProvider.get(); }
</span><span class="cx"> RTCController& rtcController() { return m_rtcController; }
</span><ins>+ PerformanceMonitor* performanceMonitor() { return m_performanceMonitor.get(); }
</ins><span class="cx">
</span><span class="cx"> ValidationMessageClient* validationMessageClient() const { return m_validationMessageClient.get(); }
</span><span class="cx"> void updateValidationBubbleStateIfNeeded();
</span></span></pre></div>
<a id="trunkSourceWebCorepagePerformanceMonitorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/PerformanceMonitor.cpp (214293 => 214294)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/PerformanceMonitor.cpp        2017-03-23 02:44:57 UTC (rev 214293)
+++ trunk/Source/WebCore/page/PerformanceMonitor.cpp        2017-03-23 04:14:03 UTC (rev 214294)
</span><span class="lines">@@ -48,6 +48,8 @@
</span><span class="cx">
</span><span class="cx"> static const std::chrono::seconds memoryUsageMeasurementDelay { 10 };
</span><span class="cx">
</span><ins>+static const std::chrono::minutes delayBeforeProcessMayBecomeInactive { 60 };
+
</ins><span class="cx"> static const double postPageLoadCPUUsageDomainReportingThreshold { 20.0 }; // Reporting pages using over 20% CPU is roughly equivalent to reporting the 10% worst pages.
</span><span class="cx"> #if !PLATFORM(IOS)
</span><span class="cx"> static const uint64_t postPageLoadMemoryUsageDomainReportingThreshold { 2048 * MB };
</span><span class="lines">@@ -69,6 +71,7 @@
</span><span class="cx"> , m_perActivityStateCPUUsageTimer(*this, &PerformanceMonitor::measurePerActivityStateCPUUsage)
</span><span class="cx"> , m_postPageLoadMemoryUsageTimer(*this, &PerformanceMonitor::measurePostLoadMemoryUsage)
</span><span class="cx"> , m_postBackgroundingMemoryUsageTimer(*this, &PerformanceMonitor::measurePostBackgroundingMemoryUsage)
</span><ins>+ , m_processMayBecomeInactiveTimer(*this, &PerformanceMonitor::processMayBecomeInactiveTimerFired)
</ins><span class="cx"> {
</span><span class="cx"> ASSERT(!page.isUtilityPage());
</span><span class="cx">
</span><span class="lines">@@ -127,6 +130,14 @@
</span><span class="cx"> else if (m_page.isOnlyNonUtilityPage())
</span><span class="cx"> m_postBackgroundingMemoryUsageTimer.startOneShot(memoryUsageMeasurementDelay);
</span><span class="cx"> }
</span><ins>+
+ if (newState & ActivityState::IsVisible && newState & ActivityState::WindowIsActive) {
+ m_processMayBecomeInactive = false;
+ m_processMayBecomeInactiveTimer.stop();
+ } else if (!m_processMayBecomeInactive && !m_processMayBecomeInactiveTimer.isActive())
+ m_processMayBecomeInactiveTimer.startOneShot(delayBeforeProcessMayBecomeInactive);
+
+ updateProcessStateForMemoryPressure();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> enum class ReportingReason { HighCPUUsage, HighMemoryUsage };
</span><span class="lines">@@ -282,4 +293,28 @@
</span><span class="cx"> m_perActivityStateCPUTime = WTFMove(cpuTime);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void PerformanceMonitor::processMayBecomeInactiveTimerFired()
+{
+ m_processMayBecomeInactive = true;
+ updateProcessStateForMemoryPressure();
+}
+
+void PerformanceMonitor::updateProcessStateForMemoryPressure()
+{
+ bool hasAudiblePages = false;
+ bool mayBecomeInactive = true;
+
+ Page::forEachPage([&] (Page& page) {
+ if (!page.performanceMonitor())
+ return;
+ if (!page.performanceMonitor()->m_processMayBecomeInactive)
+ mayBecomeInactive = false;
+ if (page.activityState() & ActivityState::IsAudible)
+ hasAudiblePages = true;
+ });
+
+ bool isActiveProcess = !mayBecomeInactive || hasAudiblePages;
+ MemoryPressureHandler::singleton().setProcessState(isActiveProcess ? WebsamProcessState::Active : WebsamProcessState::Inactive);
+}
+
</ins><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCorepagePerformanceMonitorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/PerformanceMonitor.h (214293 => 214294)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/PerformanceMonitor.h        2017-03-23 02:44:57 UTC (rev 214293)
+++ trunk/Source/WebCore/page/PerformanceMonitor.h        2017-03-23 04:14:03 UTC (rev 214294)
</span><span class="lines">@@ -47,9 +47,10 @@
</span><span class="cx"> void measurePostBackgroundingCPUUsage();
</span><span class="cx"> void measurePerActivityStateCPUUsage();
</span><span class="cx"> void measureCPUUsageInActivityState(ActivityStateForCPUSampling);
</span><del>-
</del><span class="cx"> void measurePostLoadMemoryUsage();
</span><span class="cx"> void measurePostBackgroundingMemoryUsage();
</span><ins>+ void processMayBecomeInactiveTimerFired();
+ static void updateProcessStateForMemoryPressure();
</ins><span class="cx">
</span><span class="cx"> Page& m_page;
</span><span class="cx">
</span><span class="lines">@@ -62,6 +63,9 @@
</span><span class="cx">
</span><span class="cx"> Timer m_postPageLoadMemoryUsageTimer;
</span><span class="cx"> Timer m_postBackgroundingMemoryUsageTimer;
</span><ins>+
+ Timer m_processMayBecomeInactiveTimer;
+ bool m_processMayBecomeInactive { true };
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (214293 => 214294)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2017-03-23 02:44:57 UTC (rev 214293)
+++ trunk/Source/WebKit2/ChangeLog        2017-03-23 04:14:03 UTC (rev 214294)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2017-03-22 Andreas Kling <akling@apple.com>
+
+ Let MemoryPressureHandler track whether the process is active or inactive.
+ <https://webkit.org/b/169990>
+
+ Reviewed by Antti Koivisto.
+
+ * WebProcess/WebProcess.cpp:
+ (WebKit::WebProcess::initializeWebProcess):
+
</ins><span class="cx"> 2017-03-21 Wenson Hsieh <wenson_hsieh@apple.com>
</span><span class="cx">
</span><span class="cx"> Add support for showing the platform data interaction caret
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebProcesscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebProcess.cpp (214293 => 214294)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebProcess.cpp        2017-03-23 02:44:57 UTC (rev 214293)
+++ trunk/Source/WebKit2/WebProcess/WebProcess.cpp        2017-03-23 04:14:03 UTC (rev 214294)
</span><span class="lines">@@ -270,9 +270,6 @@
</span><span class="cx"> memoryPressureHandler.setMemoryKillCallback([] () {
</span><span class="cx"> WebCore::didExceedMemoryLimitAndFailedToRecover();
</span><span class="cx"> });
</span><del>- memoryPressureHandler.setProcessIsEligibleForMemoryKillCallback([] () {
- return WebCore::processIsEligibleForMemoryKill();
- });
</del><span class="cx"> #endif
</span><span class="cx"> memoryPressureHandler.setMemoryPressureStatusChangedCallback([this](bool isUnderMemoryPressure) {
</span><span class="cx"> if (parentProcessConnection())
</span></span></pre>
</div>
</div>
</body>
</html>