Title: [214320] trunk/Source
Revision
214320
Author
akl...@apple.com
Date
2017-03-23 15:21:31 -0700 (Thu, 23 Mar 2017)

Log Message

Let the UI process do memory kills and replace crashes with diagnostic logging.
<https://webkit.org/b/170016>
<rdar://problem/31091292>

Reviewed by Chris Dumez.

Source/WebCore:

Remove the memory kill code from WebCore that just crashes in favor of controlled
teardown from UI process side in WebKit2.

* page/DiagnosticLoggingKeys.cpp:
(WebCore::DiagnosticLoggingKeys::simulatedProcessCrashKey):
(WebCore::DiagnosticLoggingKeys::exceededActiveMemoryLimitKey):
(WebCore::DiagnosticLoggingKeys::exceededInactiveMemoryLimitKey):
(WebCore::DiagnosticLoggingKeys::exceededBackgroundCPULimitKey):
* page/DiagnosticLoggingKeys.h:
* page/MemoryRelease.cpp:
(WebCore::didExceedMemoryLimitAndFailedToRecover): Deleted.
* page/MemoryRelease.h:

Source/WebKit2:

Have the WebProcess memory kill callback send a notification to the UI process
instead of outright crashing. The UI process then sends a diagnostic logging message
before carefully taking down the web process.

Also add drive-by diagnostic logging for background CPU limit kills.

* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::simulateProcessCrash):
(WebKit::WebProcessProxy::didExceedActiveMemoryLimit):
(WebKit::WebProcessProxy::didExceedInactiveMemoryLimit):
(WebKit::WebProcessProxy::didExceedBackgroundCPULimit):
* UIProcess/WebProcessProxy.h:
* UIProcess/WebProcessProxy.messages.in:
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::initializeWebProcess):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (214319 => 214320)


--- trunk/Source/WebCore/ChangeLog	2017-03-23 21:54:58 UTC (rev 214319)
+++ trunk/Source/WebCore/ChangeLog	2017-03-23 22:21:31 UTC (rev 214320)
@@ -1,3 +1,24 @@
+2017-03-23  Andreas Kling  <akl...@apple.com>
+
+        Let the UI process do memory kills and replace crashes with diagnostic logging.
+        <https://webkit.org/b/170016>
+        <rdar://problem/31091292>
+
+        Reviewed by Chris Dumez.
+
+        Remove the memory kill code from WebCore that just crashes in favor of controlled
+        teardown from UI process side in WebKit2.
+
+        * page/DiagnosticLoggingKeys.cpp:
+        (WebCore::DiagnosticLoggingKeys::simulatedProcessCrashKey):
+        (WebCore::DiagnosticLoggingKeys::exceededActiveMemoryLimitKey):
+        (WebCore::DiagnosticLoggingKeys::exceededInactiveMemoryLimitKey):
+        (WebCore::DiagnosticLoggingKeys::exceededBackgroundCPULimitKey):
+        * page/DiagnosticLoggingKeys.h:
+        * page/MemoryRelease.cpp:
+        (WebCore::didExceedMemoryLimitAndFailedToRecover): Deleted.
+        * page/MemoryRelease.h:
+
 2017-03-23  Youenn Fablet  <you...@apple.com>
 
         Clean RTCPeerConnection.idl after bug 169978

Modified: trunk/Source/WebCore/page/DiagnosticLoggingKeys.cpp (214319 => 214320)


--- trunk/Source/WebCore/page/DiagnosticLoggingKeys.cpp	2017-03-23 21:54:58 UTC (rev 214319)
+++ trunk/Source/WebCore/page/DiagnosticLoggingKeys.cpp	2017-03-23 22:21:31 UTC (rev 214320)
@@ -353,6 +353,26 @@
     return ASCIILiteral("DomainCausingJetsam");
 }
 
+String DiagnosticLoggingKeys::simulatedPageCrashKey()
+{
+    return ASCIILiteral("SimulatedPageCrash");
+}
+
+String DiagnosticLoggingKeys::exceededActiveMemoryLimitKey()
+{
+    return ASCIILiteral("ExceededActiveMemoryLimit");
+}
+
+String DiagnosticLoggingKeys::exceededInactiveMemoryLimitKey()
+{
+    return ASCIILiteral("ExceededInactiveMemoryLimit");
+}
+
+String DiagnosticLoggingKeys::exceededBackgroundCPULimitKey()
+{
+    return ASCIILiteral("ExceededBackgroundCPULimit");
+}
+
 String DiagnosticLoggingKeys::domainVisitedKey()
 {
     return ASCIILiteral("DomainVisited");

Modified: trunk/Source/WebCore/page/DiagnosticLoggingKeys.h (214319 => 214320)


--- trunk/Source/WebCore/page/DiagnosticLoggingKeys.h	2017-03-23 21:54:58 UTC (rev 214319)
+++ trunk/Source/WebCore/page/DiagnosticLoggingKeys.h	2017-03-23 22:21:31 UTC (rev 214320)
@@ -52,6 +52,10 @@
     static String documentLoaderStoppingKey();
     static String domainCausingEnergyDrainKey();
     WEBCORE_EXPORT static String domainCausingJetsamKey();
+    WEBCORE_EXPORT static String simulatedPageCrashKey();
+    WEBCORE_EXPORT static String exceededActiveMemoryLimitKey();
+    WEBCORE_EXPORT static String exceededInactiveMemoryLimitKey();
+    WEBCORE_EXPORT static String exceededBackgroundCPULimitKey();
     static String domainVisitedKey();
     static String engineFailedToLoadKey();
     WEBCORE_EXPORT static String entryRightlyNotWarmedUpKey();

Modified: trunk/Source/WebCore/page/MemoryRelease.cpp (214319 => 214320)


--- trunk/Source/WebCore/page/MemoryRelease.cpp	2017-03-23 21:54:58 UTC (rev 214319)
+++ trunk/Source/WebCore/page/MemoryRelease.cpp	2017-03-23 22:21:31 UTC (rev 214320)
@@ -186,13 +186,6 @@
 #endif
 }
 
-void didExceedMemoryLimitAndFailedToRecover()
-{
-    RELEASE_LOG(MemoryPressure, "Crashing non-visible process due to excessive memory usage + inability to free up memory below panic threshold.");
-    logMemoryStatisticsAtTimeOfDeath();
-    CRASH();
-}
-
 #if !PLATFORM(COCOA)
 void platformReleaseMemory(Critical) { }
 void jettisonExpensiveObjectsOnTopLevelNavigation() { }

Modified: trunk/Source/WebCore/page/MemoryRelease.h (214319 => 214320)


--- trunk/Source/WebCore/page/MemoryRelease.h	2017-03-23 21:54:58 UTC (rev 214319)
+++ trunk/Source/WebCore/page/MemoryRelease.h	2017-03-23 22:21:31 UTC (rev 214320)
@@ -34,6 +34,5 @@
 void jettisonExpensiveObjectsOnTopLevelNavigation();
 WEBCORE_EXPORT void registerMemoryReleaseNotifyCallbacks();
 WEBCORE_EXPORT void logMemoryStatisticsAtTimeOfDeath();
-WEBCORE_EXPORT NO_RETURN_DUE_TO_CRASH void didExceedMemoryLimitAndFailedToRecover();
 
 } // namespace WebCore

Modified: trunk/Source/WebKit2/ChangeLog (214319 => 214320)


--- trunk/Source/WebKit2/ChangeLog	2017-03-23 21:54:58 UTC (rev 214319)
+++ trunk/Source/WebKit2/ChangeLog	2017-03-23 22:21:31 UTC (rev 214320)
@@ -1,3 +1,27 @@
+2017-03-23  Andreas Kling  <akl...@apple.com>
+
+        Let the UI process do memory kills and replace crashes with diagnostic logging.
+        <https://webkit.org/b/170016>
+        <rdar://problem/31091292>
+
+        Reviewed by Chris Dumez.
+
+        Have the WebProcess memory kill callback send a notification to the UI process
+        instead of outright crashing. The UI process then sends a diagnostic logging message
+        before carefully taking down the web process.
+
+        Also add drive-by diagnostic logging for background CPU limit kills.
+
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::simulateProcessCrash):
+        (WebKit::WebProcessProxy::didExceedActiveMemoryLimit):
+        (WebKit::WebProcessProxy::didExceedInactiveMemoryLimit):
+        (WebKit::WebProcessProxy::didExceedBackgroundCPULimit):
+        * UIProcess/WebProcessProxy.h:
+        * UIProcess/WebProcessProxy.messages.in:
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::initializeWebProcess):
+
 2017-03-23  Tim Horton  <timothy_hor...@apple.com>
 
         Test DataDetectors supported schemes in lowercase

Modified: trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp (214319 => 214320)


--- trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp	2017-03-23 21:54:58 UTC (rev 214319)
+++ trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp	2017-03-23 22:21:31 UTC (rev 214320)
@@ -50,6 +50,7 @@
 #include "WebProcessProxyMessages.h"
 #include "WebUserContentControllerProxy.h"
 #include "WebsiteData.h"
+#include <WebCore/DiagnosticLoggingKeys.h>
 #include <WebCore/SuddenTermination.h>
 #include <WebCore/URL.h>
 #include <stdio.h>
@@ -1127,6 +1128,39 @@
     return vector;
 }
 
+static String diagnosticLoggingKeyForSimulatedCrashReason(SimulatedCrashReason reason)
+{
+    switch (reason) {
+    case SimulatedCrashReason::ExceededActiveMemoryLimit:
+        return DiagnosticLoggingKeys::exceededActiveMemoryLimitKey();
+    case SimulatedCrashReason::ExceededInactiveMemoryLimit:
+        return DiagnosticLoggingKeys::exceededInactiveMemoryLimitKey();
+    case SimulatedCrashReason::ExceededBackgroundCPULimit:
+        return DiagnosticLoggingKeys::exceededBackgroundCPULimitKey();
+    }
+}
+
+void WebProcessProxy::simulateProcessCrash(SimulatedCrashReason reason)
+{
+    for (auto& page : pagesCopy(pages())) {
+        page->logDiagnosticMessage(DiagnosticLoggingKeys::simulatedPageCrashKey(), diagnosticLoggingKeyForSimulatedCrashReason(reason), ShouldSample::No);
+        page->terminateProcess();
+        page->processDidCrash();
+    }
+}
+
+void WebProcessProxy::didExceedActiveMemoryLimit()
+{
+    RELEASE_LOG(PerformanceLogging, "%p - WebProcessProxy::didExceedActiveMemoryLimit() Terminating WebProcess that has exceeded the active memory limit", this);
+    simulateProcessCrash(SimulatedCrashReason::ExceededActiveMemoryLimit);
+}
+
+void WebProcessProxy::didExceedInactiveMemoryLimit()
+{
+    RELEASE_LOG(PerformanceLogging, "%p - WebProcessProxy::didExceedInactiveMemoryLimit() Terminating WebProcess that has exceeded the inactive memory limit", this);
+    simulateProcessCrash(SimulatedCrashReason::ExceededInactiveMemoryLimit);
+}
+
 void WebProcessProxy::didExceedBackgroundCPULimit()
 {
     for (auto& page : pages()) {
@@ -1140,11 +1174,7 @@
     }
 
     RELEASE_LOG(PerformanceLogging, "%p - WebProcessProxy::didExceedBackgroundCPULimit() Terminating background WebProcess that has exceeded the background CPU limit", this);
-
-    for (auto& page : pagesCopy(pages())) {
-        page->terminateProcess();
-        page->processDidCrash();
-    }
+    simulateProcessCrash(SimulatedCrashReason::ExceededBackgroundCPULimit);
 }
 
 void WebProcessProxy::updateBackgroundResponsivenessTimer()

Modified: trunk/Source/WebKit2/UIProcess/WebProcessProxy.h (214319 => 214320)


--- trunk/Source/WebKit2/UIProcess/WebProcessProxy.h	2017-03-23 21:54:58 UTC (rev 214319)
+++ trunk/Source/WebKit2/UIProcess/WebProcessProxy.h	2017-03-23 22:21:31 UTC (rev 214320)
@@ -55,6 +55,12 @@
 
 namespace WebKit {
 
+enum class SimulatedCrashReason {
+    ExceededActiveMemoryLimit,
+    ExceededInactiveMemoryLimit,
+    ExceededBackgroundCPULimit,
+};
+
 class NetworkProcessProxy;
 class UserMediaCaptureManagerProxy;
 class WebBackForwardListItem;
@@ -165,7 +171,10 @@
     bool isUnderMemoryPressure() const { return m_isUnderMemoryPressure; }
 
     void processTerminated();
+
     void didExceedBackgroundCPULimit();
+    void didExceedActiveMemoryLimit();
+    void didExceedInactiveMemoryLimit();
 
 private:
     explicit WebProcessProxy(WebProcessPool&, WebsiteDataStore*);
@@ -238,6 +247,8 @@
 
     bool canTerminateChildProcess();
 
+    void simulateProcessCrash(SimulatedCrashReason);
+
     ResponsivenessTimer m_responsivenessTimer;
     BackgroundProcessResponsivenessTimer m_backgroundResponsivenessTimer;
     

Modified: trunk/Source/WebKit2/UIProcess/WebProcessProxy.messages.in (214319 => 214320)


--- trunk/Source/WebKit2/UIProcess/WebProcessProxy.messages.in	2017-03-23 21:54:58 UTC (rev 214319)
+++ trunk/Source/WebKit2/UIProcess/WebProcessProxy.messages.in	2017-03-23 22:21:31 UTC (rev 214320)
@@ -45,6 +45,8 @@
 
     SetIsHoldingLockedFiles(bool isHoldingLockedFiles)
 
+    DidExceedActiveMemoryLimit()
+    DidExceedInactiveMemoryLimit()
     DidExceedBackgroundCPULimit()
 
     RetainIconForPageURL(String pageURL)

Modified: trunk/Source/WebKit2/WebProcess/WebProcess.cpp (214319 => 214320)


--- trunk/Source/WebKit2/WebProcess/WebProcess.cpp	2017-03-23 21:54:58 UTC (rev 214319)
+++ trunk/Source/WebKit2/WebProcess/WebProcess.cpp	2017-03-23 22:21:31 UTC (rev 214320)
@@ -267,8 +267,12 @@
         });
 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101200
         memoryPressureHandler.setShouldUsePeriodicMemoryMonitor(true);
-        memoryPressureHandler.setMemoryKillCallback([] () {
-            WebCore::didExceedMemoryLimitAndFailedToRecover();
+        memoryPressureHandler.setMemoryKillCallback([this] () {
+            WebCore::logMemoryStatisticsAtTimeOfDeath();
+            if (MemoryPressureHandler::singleton().processState() == WebsamProcessState::Active)
+                parentProcessConnection()->send(Messages::WebProcessProxy::DidExceedActiveMemoryLimit(), 0);
+            else
+                parentProcessConnection()->send(Messages::WebProcessProxy::DidExceedInactiveMemoryLimit(), 0);
         });
 #endif
         memoryPressureHandler.setMemoryPressureStatusChangedCallback([this](bool isUnderMemoryPressure) {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to