Skip to content
This repository was archived by the owner on Jun 24, 2022. It is now read-only.

Commit 6257928

Browse files
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): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@214320 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 237c568 commit 6257928

File tree

10 files changed

+123
-15
lines changed

10 files changed

+123
-15
lines changed

Source/WebCore/ChangeLog

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
2017-03-23 Andreas Kling <[email protected]>
2+
3+
Let the UI process do memory kills and replace crashes with diagnostic logging.
4+
<https://webkit.org/b/170016>
5+
<rdar://problem/31091292>
6+
7+
Reviewed by Chris Dumez.
8+
9+
Remove the memory kill code from WebCore that just crashes in favor of controlled
10+
teardown from UI process side in WebKit2.
11+
12+
* page/DiagnosticLoggingKeys.cpp:
13+
(WebCore::DiagnosticLoggingKeys::simulatedProcessCrashKey):
14+
(WebCore::DiagnosticLoggingKeys::exceededActiveMemoryLimitKey):
15+
(WebCore::DiagnosticLoggingKeys::exceededInactiveMemoryLimitKey):
16+
(WebCore::DiagnosticLoggingKeys::exceededBackgroundCPULimitKey):
17+
* page/DiagnosticLoggingKeys.h:
18+
* page/MemoryRelease.cpp:
19+
(WebCore::didExceedMemoryLimitAndFailedToRecover): Deleted.
20+
* page/MemoryRelease.h:
21+
122
2017-03-23 Youenn Fablet <[email protected]>
223

324
Clean RTCPeerConnection.idl after bug 169978

Source/WebCore/page/DiagnosticLoggingKeys.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,26 @@ String DiagnosticLoggingKeys::domainCausingJetsamKey()
353353
return ASCIILiteral("DomainCausingJetsam");
354354
}
355355

356+
String DiagnosticLoggingKeys::simulatedPageCrashKey()
357+
{
358+
return ASCIILiteral("SimulatedPageCrash");
359+
}
360+
361+
String DiagnosticLoggingKeys::exceededActiveMemoryLimitKey()
362+
{
363+
return ASCIILiteral("ExceededActiveMemoryLimit");
364+
}
365+
366+
String DiagnosticLoggingKeys::exceededInactiveMemoryLimitKey()
367+
{
368+
return ASCIILiteral("ExceededInactiveMemoryLimit");
369+
}
370+
371+
String DiagnosticLoggingKeys::exceededBackgroundCPULimitKey()
372+
{
373+
return ASCIILiteral("ExceededBackgroundCPULimit");
374+
}
375+
356376
String DiagnosticLoggingKeys::domainVisitedKey()
357377
{
358378
return ASCIILiteral("DomainVisited");

Source/WebCore/page/DiagnosticLoggingKeys.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ class DiagnosticLoggingKeys {
5252
static String documentLoaderStoppingKey();
5353
static String domainCausingEnergyDrainKey();
5454
WEBCORE_EXPORT static String domainCausingJetsamKey();
55+
WEBCORE_EXPORT static String simulatedPageCrashKey();
56+
WEBCORE_EXPORT static String exceededActiveMemoryLimitKey();
57+
WEBCORE_EXPORT static String exceededInactiveMemoryLimitKey();
58+
WEBCORE_EXPORT static String exceededBackgroundCPULimitKey();
5559
static String domainVisitedKey();
5660
static String engineFailedToLoadKey();
5761
WEBCORE_EXPORT static String entryRightlyNotWarmedUpKey();

Source/WebCore/page/MemoryRelease.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,6 @@ void logMemoryStatisticsAtTimeOfDeath()
186186
#endif
187187
}
188188

189-
void didExceedMemoryLimitAndFailedToRecover()
190-
{
191-
RELEASE_LOG(MemoryPressure, "Crashing non-visible process due to excessive memory usage + inability to free up memory below panic threshold.");
192-
logMemoryStatisticsAtTimeOfDeath();
193-
CRASH();
194-
}
195-
196189
#if !PLATFORM(COCOA)
197190
void platformReleaseMemory(Critical) { }
198191
void jettisonExpensiveObjectsOnTopLevelNavigation() { }

Source/WebCore/page/MemoryRelease.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,5 @@ void platformReleaseMemory(Critical);
3434
void jettisonExpensiveObjectsOnTopLevelNavigation();
3535
WEBCORE_EXPORT void registerMemoryReleaseNotifyCallbacks();
3636
WEBCORE_EXPORT void logMemoryStatisticsAtTimeOfDeath();
37-
WEBCORE_EXPORT NO_RETURN_DUE_TO_CRASH void didExceedMemoryLimitAndFailedToRecover();
3837

3938
} // namespace WebCore

Source/WebKit2/ChangeLog

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
2017-03-23 Andreas Kling <[email protected]>
2+
3+
Let the UI process do memory kills and replace crashes with diagnostic logging.
4+
<https://webkit.org/b/170016>
5+
<rdar://problem/31091292>
6+
7+
Reviewed by Chris Dumez.
8+
9+
Have the WebProcess memory kill callback send a notification to the UI process
10+
instead of outright crashing. The UI process then sends a diagnostic logging message
11+
before carefully taking down the web process.
12+
13+
Also add drive-by diagnostic logging for background CPU limit kills.
14+
15+
* UIProcess/WebProcessProxy.cpp:
16+
(WebKit::WebProcessProxy::simulateProcessCrash):
17+
(WebKit::WebProcessProxy::didExceedActiveMemoryLimit):
18+
(WebKit::WebProcessProxy::didExceedInactiveMemoryLimit):
19+
(WebKit::WebProcessProxy::didExceedBackgroundCPULimit):
20+
* UIProcess/WebProcessProxy.h:
21+
* UIProcess/WebProcessProxy.messages.in:
22+
* WebProcess/WebProcess.cpp:
23+
(WebKit::WebProcess::initializeWebProcess):
24+
125
2017-03-23 Tim Horton <[email protected]>
226

327
Test DataDetectors supported schemes in lowercase

Source/WebKit2/UIProcess/WebProcessProxy.cpp

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "WebProcessProxyMessages.h"
5151
#include "WebUserContentControllerProxy.h"
5252
#include "WebsiteData.h"
53+
#include <WebCore/DiagnosticLoggingKeys.h>
5354
#include <WebCore/SuddenTermination.h>
5455
#include <WebCore/URL.h>
5556
#include <stdio.h>
@@ -1127,6 +1128,39 @@ static Vector<RefPtr<WebPageProxy>> pagesCopy(WTF::IteratorRange<WebProcessProxy
11271128
return vector;
11281129
}
11291130

1131+
static String diagnosticLoggingKeyForSimulatedCrashReason(SimulatedCrashReason reason)
1132+
{
1133+
switch (reason) {
1134+
case SimulatedCrashReason::ExceededActiveMemoryLimit:
1135+
return DiagnosticLoggingKeys::exceededActiveMemoryLimitKey();
1136+
case SimulatedCrashReason::ExceededInactiveMemoryLimit:
1137+
return DiagnosticLoggingKeys::exceededInactiveMemoryLimitKey();
1138+
case SimulatedCrashReason::ExceededBackgroundCPULimit:
1139+
return DiagnosticLoggingKeys::exceededBackgroundCPULimitKey();
1140+
}
1141+
}
1142+
1143+
void WebProcessProxy::simulateProcessCrash(SimulatedCrashReason reason)
1144+
{
1145+
for (auto& page : pagesCopy(pages())) {
1146+
page->logDiagnosticMessage(DiagnosticLoggingKeys::simulatedPageCrashKey(), diagnosticLoggingKeyForSimulatedCrashReason(reason), ShouldSample::No);
1147+
page->terminateProcess();
1148+
page->processDidCrash();
1149+
}
1150+
}
1151+
1152+
void WebProcessProxy::didExceedActiveMemoryLimit()
1153+
{
1154+
RELEASE_LOG(PerformanceLogging, "%p - WebProcessProxy::didExceedActiveMemoryLimit() Terminating WebProcess that has exceeded the active memory limit", this);
1155+
simulateProcessCrash(SimulatedCrashReason::ExceededActiveMemoryLimit);
1156+
}
1157+
1158+
void WebProcessProxy::didExceedInactiveMemoryLimit()
1159+
{
1160+
RELEASE_LOG(PerformanceLogging, "%p - WebProcessProxy::didExceedInactiveMemoryLimit() Terminating WebProcess that has exceeded the inactive memory limit", this);
1161+
simulateProcessCrash(SimulatedCrashReason::ExceededInactiveMemoryLimit);
1162+
}
1163+
11301164
void WebProcessProxy::didExceedBackgroundCPULimit()
11311165
{
11321166
for (auto& page : pages()) {
@@ -1140,11 +1174,7 @@ void WebProcessProxy::didExceedBackgroundCPULimit()
11401174
}
11411175

11421176
RELEASE_LOG(PerformanceLogging, "%p - WebProcessProxy::didExceedBackgroundCPULimit() Terminating background WebProcess that has exceeded the background CPU limit", this);
1143-
1144-
for (auto& page : pagesCopy(pages())) {
1145-
page->terminateProcess();
1146-
page->processDidCrash();
1147-
}
1177+
simulateProcessCrash(SimulatedCrashReason::ExceededBackgroundCPULimit);
11481178
}
11491179

11501180
void WebProcessProxy::updateBackgroundResponsivenessTimer()

Source/WebKit2/UIProcess/WebProcessProxy.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ struct PluginInfo;
5555

5656
namespace WebKit {
5757

58+
enum class SimulatedCrashReason {
59+
ExceededActiveMemoryLimit,
60+
ExceededInactiveMemoryLimit,
61+
ExceededBackgroundCPULimit,
62+
};
63+
5864
class NetworkProcessProxy;
5965
class UserMediaCaptureManagerProxy;
6066
class WebBackForwardListItem;
@@ -165,7 +171,10 @@ class WebProcessProxy : public ChildProcessProxy, public ResponsivenessTimer::Cl
165171
bool isUnderMemoryPressure() const { return m_isUnderMemoryPressure; }
166172

167173
void processTerminated();
174+
168175
void didExceedBackgroundCPULimit();
176+
void didExceedActiveMemoryLimit();
177+
void didExceedInactiveMemoryLimit();
169178

170179
private:
171180
explicit WebProcessProxy(WebProcessPool&, WebsiteDataStore*);
@@ -238,6 +247,8 @@ class WebProcessProxy : public ChildProcessProxy, public ResponsivenessTimer::Cl
238247

239248
bool canTerminateChildProcess();
240249

250+
void simulateProcessCrash(SimulatedCrashReason);
251+
241252
ResponsivenessTimer m_responsivenessTimer;
242253
BackgroundProcessResponsivenessTimer m_backgroundResponsivenessTimer;
243254

Source/WebKit2/UIProcess/WebProcessProxy.messages.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ messages -> WebProcessProxy LegacyReceiver {
4545

4646
SetIsHoldingLockedFiles(bool isHoldingLockedFiles)
4747

48+
DidExceedActiveMemoryLimit()
49+
DidExceedInactiveMemoryLimit()
4850
DidExceedBackgroundCPULimit()
4951

5052
RetainIconForPageURL(String pageURL)

Source/WebKit2/WebProcess/WebProcess.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,12 @@ void WebProcess::initializeWebProcess(WebProcessCreationParameters&& parameters)
267267
});
268268
#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101200
269269
memoryPressureHandler.setShouldUsePeriodicMemoryMonitor(true);
270-
memoryPressureHandler.setMemoryKillCallback([] () {
271-
WebCore::didExceedMemoryLimitAndFailedToRecover();
270+
memoryPressureHandler.setMemoryKillCallback([this] () {
271+
WebCore::logMemoryStatisticsAtTimeOfDeath();
272+
if (MemoryPressureHandler::singleton().processState() == WebsamProcessState::Active)
273+
parentProcessConnection()->send(Messages::WebProcessProxy::DidExceedActiveMemoryLimit(), 0);
274+
else
275+
parentProcessConnection()->send(Messages::WebProcessProxy::DidExceedInactiveMemoryLimit(), 0);
272276
});
273277
#endif
274278
memoryPressureHandler.setMemoryPressureStatusChangedCallback([this](bool isUnderMemoryPressure) {

0 commit comments

Comments
 (0)