- Revision
- 196943
- Author
- [email protected]
- Date
- 2016-02-22 10:31:03 -0800 (Mon, 22 Feb 2016)
Log Message
Add mechanism to disable memory pressure handling
https://bugs.webkit.org/show_bug.cgi?id=154254
<rdar://problem/24662616>
Patch by Keith Rollin <[email protected]> on 2016-02-22
Reviewed by Chris Dumez.
Add a mechanism to disable WebKit's response to memory pressure
triggers. This was asked for by another group for testing purposes.
In order to disable WebKit's memory pressure handling, execute the
following from the command line:
defaults write com.apple.Safari WebKitSuppressMemoryPressureHandler -bool true
To revert to standard behavior, delete the key or set it to False.
This flag is used when a new sub-process is being spawned. The value
is read and stored in an initialization parameter block, which is then
sent to the new sub-process.
In actuality, only the UI, WebContent, and Network processes heed the
flag. The Plugin process isn't instrumented to heed this flag for
three reasons. First, the Plugin process installs its memory pressure
handler in initializeProcess, not initializePluginProcess. This is
contrary to when the other processes install their handlers, which is
in initialize<PluginType>Process, not initializeProcess. So in order
to accomodate the Plugin process, we'd need to modify
ChildProcessInitializationParameters. Doing this is awkward at best,
but also seems to be opposed to what's supposed to be done in
initializeProcess and conveyed in
ChildProcessInitializationParameters. And even if we did add a boolean
to this structure and added support for conveying it through the XPC
port, it would end up being a Plugin process-only boolean in a general
parameter block, which seems asymmetric with the other processes.
Second, there's no convenient Cocoa function called in the flow that
spawns the Plugin process, meaning that there's no convenient place to
call NSUserDefaults to get the flag's value. And third, the Plugin
process doesn't elegantly respond to the memory pressure trigger
anyway. It might terminate itself, but that's it. As for the Database
process, it doesn't seem to support responding to memory pressure at
all, so we don't send it a flag telling it to ignore it.
Internally, the memory pressure handler is suppressed by not calling
MemoryPressureHandler::install() if the flag is set. In the case of
the Network process, the flag is saved so that it can be checked later
in other places that manually kick off the memory pressure handling
procedure.
Source/WebKit/mac:
* WebView/WebView.mm:
(-[WebView _commonInitializationWithFrameName:groupName:]):
(WebInstallMemoryPressureHandler):
Source/WebKit2:
* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::lowMemoryHandler):
(WebKit::NetworkProcess::initializeNetworkProcess):
* NetworkProcess/NetworkProcess.h:
* NetworkProcess/NetworkProcessCreationParameters.cpp:
(WebKit::NetworkProcessCreationParameters::encode):
(WebKit::NetworkProcessCreationParameters::decode):
* NetworkProcess/NetworkProcessCreationParameters.h:
* Shared/WebProcessCreationParameters.cpp:
(WebKit::WebProcessCreationParameters::encode):
(WebKit::WebProcessCreationParameters::decode):
* Shared/WebProcessCreationParameters.h:
* UIProcess/Cocoa/WebProcessPoolCocoa.mm:
(WebKit::WebProcessPool::platformInitializeWebProcess):
(WebKit::WebProcessPool::platformInitializeNetworkProcess):
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::initializeWebProcess):
Modified Paths
Diff
Modified: trunk/Source/WebKit/mac/ChangeLog (196942 => 196943)
--- trunk/Source/WebKit/mac/ChangeLog 2016-02-22 18:22:27 UTC (rev 196942)
+++ trunk/Source/WebKit/mac/ChangeLog 2016-02-22 18:31:03 UTC (rev 196943)
@@ -1,3 +1,57 @@
+2016-02-22 Keith Rollin <[email protected]>
+
+ Add mechanism to disable memory pressure handling
+ https://bugs.webkit.org/show_bug.cgi?id=154254
+ <rdar://problem/24662616>
+
+ Reviewed by Chris Dumez.
+
+ Add a mechanism to disable WebKit's response to memory pressure
+ triggers. This was asked for by another group for testing purposes.
+
+ In order to disable WebKit's memory pressure handling, execute the
+ following from the command line:
+
+ defaults write com.apple.Safari WebKitSuppressMemoryPressureHandler -bool true
+
+ To revert to standard behavior, delete the key or set it to False.
+
+ This flag is used when a new sub-process is being spawned. The value
+ is read and stored in an initialization parameter block, which is then
+ sent to the new sub-process.
+
+ In actuality, only the UI, WebContent, and Network processes heed the
+ flag. The Plugin process isn't instrumented to heed this flag for
+ three reasons. First, the Plugin process installs its memory pressure
+ handler in initializeProcess, not initializePluginProcess. This is
+ contrary to when the other processes install their handlers, which is
+ in initialize<PluginType>Process, not initializeProcess. So in order
+ to accomodate the Plugin process, we'd need to modify
+ ChildProcessInitializationParameters. Doing this is awkward at best,
+ but also seems to be opposed to what's supposed to be done in
+ initializeProcess and conveyed in
+ ChildProcessInitializationParameters. And even if we did add a boolean
+ to this structure and added support for conveying it through the XPC
+ port, it would end up being a Plugin process-only boolean in a general
+ parameter block, which seems asymmetric with the other processes.
+ Second, there's no convenient Cocoa function called in the flow that
+ spawns the Plugin process, meaning that there's no convenient place to
+ call NSUserDefaults to get the flag's value. And third, the Plugin
+ process doesn't elegantly respond to the memory pressure trigger
+ anyway. It might terminate itself, but that's it. As for the Database
+ process, it doesn't seem to support responding to memory pressure at
+ all, so we don't send it a flag telling it to ignore it.
+
+ Internally, the memory pressure handler is suppressed by not calling
+ MemoryPressureHandler::install() if the flag is set. In the case of
+ the Network process, the flag is saved so that it can be checked later
+ in other places that manually kick off the memory pressure handling
+ procedure.
+
+ * WebView/WebView.mm:
+ (-[WebView _commonInitializationWithFrameName:groupName:]):
+ (WebInstallMemoryPressureHandler):
+
2016-02-22 Jer Noble <[email protected]>
Enable AVFoundationNSURLSessionEnabled by default
Modified: trunk/Source/WebKit/mac/WebView/WebView.mm (196942 => 196943)
--- trunk/Source/WebKit/mac/WebView/WebView.mm 2016-02-22 18:22:27 UTC (rev 196942)
+++ trunk/Source/WebKit/mac/WebView/WebView.mm 2016-02-22 18:31:03 UTC (rev 196943)
@@ -1101,7 +1101,8 @@
_private->page->settings().setFontFallbackPrefersPictographs(true);
#endif
- MemoryPressureHandler::singleton().install();
+ if (![[NSUserDefaults standardUserDefaults] boolForKey:@"WebKitSuppressMemoryPressureHandler"])
+ MemoryPressureHandler::singleton().install();
if (!WebKitLinkedOnOrAfter(WEBKIT_FIRST_VERSION_WITH_LOCAL_RESOURCE_SECURITY_RESTRICTION)) {
// Originally, we allowed all local loads.
@@ -8945,5 +8946,6 @@
void WebInstallMemoryPressureHandler(void)
{
- MemoryPressureHandler::singleton().install();
+ if (![[NSUserDefaults standardUserDefaults] boolForKey:@"WebKitSuppressMemoryPressureHandler"])
+ MemoryPressureHandler::singleton().install();
}
Modified: trunk/Source/WebKit2/ChangeLog (196942 => 196943)
--- trunk/Source/WebKit2/ChangeLog 2016-02-22 18:22:27 UTC (rev 196942)
+++ trunk/Source/WebKit2/ChangeLog 2016-02-22 18:31:03 UTC (rev 196943)
@@ -1,3 +1,71 @@
+2016-02-22 Keith Rollin <[email protected]>
+
+ Add mechanism to disable memory pressure handling
+ https://bugs.webkit.org/show_bug.cgi?id=154254
+ <rdar://problem/24662616>
+
+ Reviewed by Chris Dumez.
+
+ Add a mechanism to disable WebKit's response to memory pressure
+ triggers. This was asked for by another group for testing purposes.
+
+ In order to disable WebKit's memory pressure handling, execute the
+ following from the command line:
+
+ defaults write com.apple.Safari WebKitSuppressMemoryPressureHandler -bool true
+
+ To revert to standard behavior, delete the key or set it to False.
+
+ This flag is used when a new sub-process is being spawned. The value
+ is read and stored in an initialization parameter block, which is then
+ sent to the new sub-process.
+
+ In actuality, only the UI, WebContent, and Network processes heed the
+ flag. The Plugin process isn't instrumented to heed this flag for
+ three reasons. First, the Plugin process installs its memory pressure
+ handler in initializeProcess, not initializePluginProcess. This is
+ contrary to when the other processes install their handlers, which is
+ in initialize<PluginType>Process, not initializeProcess. So in order
+ to accomodate the Plugin process, we'd need to modify
+ ChildProcessInitializationParameters. Doing this is awkward at best,
+ but also seems to be opposed to what's supposed to be done in
+ initializeProcess and conveyed in
+ ChildProcessInitializationParameters. And even if we did add a boolean
+ to this structure and added support for conveying it through the XPC
+ port, it would end up being a Plugin process-only boolean in a general
+ parameter block, which seems asymmetric with the other processes.
+ Second, there's no convenient Cocoa function called in the flow that
+ spawns the Plugin process, meaning that there's no convenient place to
+ call NSUserDefaults to get the flag's value. And third, the Plugin
+ process doesn't elegantly respond to the memory pressure trigger
+ anyway. It might terminate itself, but that's it. As for the Database
+ process, it doesn't seem to support responding to memory pressure at
+ all, so we don't send it a flag telling it to ignore it.
+
+ Internally, the memory pressure handler is suppressed by not calling
+ MemoryPressureHandler::install() if the flag is set. In the case of
+ the Network process, the flag is saved so that it can be checked later
+ in other places that manually kick off the memory pressure handling
+ procedure.
+
+ * NetworkProcess/NetworkProcess.cpp:
+ (WebKit::NetworkProcess::lowMemoryHandler):
+ (WebKit::NetworkProcess::initializeNetworkProcess):
+ * NetworkProcess/NetworkProcess.h:
+ * NetworkProcess/NetworkProcessCreationParameters.cpp:
+ (WebKit::NetworkProcessCreationParameters::encode):
+ (WebKit::NetworkProcessCreationParameters::decode):
+ * NetworkProcess/NetworkProcessCreationParameters.h:
+ * Shared/WebProcessCreationParameters.cpp:
+ (WebKit::WebProcessCreationParameters::encode):
+ (WebKit::WebProcessCreationParameters::decode):
+ * Shared/WebProcessCreationParameters.h:
+ * UIProcess/Cocoa/WebProcessPoolCocoa.mm:
+ (WebKit::WebProcessPool::platformInitializeWebProcess):
+ (WebKit::WebProcessPool::platformInitializeNetworkProcess):
+ * WebProcess/WebProcess.cpp:
+ (WebKit::WebProcess::initializeWebProcess):
+
2016-02-22 Anders Carlsson <[email protected]>
Get rid of WKPluginSiteDataManager
Modified: trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp (196942 => 196943)
--- trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp 2016-02-22 18:22:27 UTC (rev 196942)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp 2016-02-22 18:31:03 UTC (rev 196943)
@@ -175,6 +175,9 @@
void NetworkProcess::lowMemoryHandler(Critical critical)
{
+ if (m_suppressMemoryPressureHandler)
+ return;
+
platformLowMemoryHandler(critical);
WTF::releaseFastMallocFreeMemory();
}
@@ -185,11 +188,14 @@
WTF::setCurrentThreadIsUserInitiated();
- auto& memoryPressureHandler = MemoryPressureHandler::singleton();
- memoryPressureHandler.setLowMemoryHandler([this] (Critical critical, Synchronous) {
- lowMemoryHandler(critical);
- });
- memoryPressureHandler.install();
+ m_suppressMemoryPressureHandler = parameters.shouldSuppressMemoryPressureHandler;
+ if (!m_suppressMemoryPressureHandler) {
+ auto& memoryPressureHandler = MemoryPressureHandler::singleton();
+ memoryPressureHandler.setLowMemoryHandler([this] (Critical critical, Synchronous) {
+ lowMemoryHandler(critical);
+ });
+ memoryPressureHandler.install();
+ }
m_diskCacheIsDisabledForTesting = parameters.shouldUseTestingNetworkSession;
Modified: trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h (196942 => 196943)
--- trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h 2016-02-22 18:22:27 UTC (rev 196942)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h 2016-02-22 18:31:03 UTC (rev 196943)
@@ -179,6 +179,7 @@
bool m_hasSetCacheModel;
CacheModel m_cacheModel;
int64_t m_diskCacheSizeOverride { -1 };
+ bool m_suppressMemoryPressureHandler { false };
bool m_diskCacheIsDisabledForTesting;
bool m_canHandleHTTPSServerTrustEvaluation;
Modified: trunk/Source/WebKit2/NetworkProcess/NetworkProcessCreationParameters.cpp (196942 => 196943)
--- trunk/Source/WebKit2/NetworkProcess/NetworkProcessCreationParameters.cpp 2016-02-22 18:22:27 UTC (rev 196942)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkProcessCreationParameters.cpp 2016-02-22 18:31:03 UTC (rev 196943)
@@ -64,6 +64,7 @@
encoder << containerCachesDirectoryExtensionHandle;
encoder << parentBundleDirectoryExtensionHandle;
#endif
+ encoder << shouldSuppressMemoryPressureHandler;
encoder << shouldUseTestingNetworkSession;
encoder << urlSchemesRegisteredForCustomProtocols;
#if PLATFORM(COCOA)
@@ -126,6 +127,8 @@
if (!decoder.decode(result.parentBundleDirectoryExtensionHandle))
return false;
#endif
+ if (!decoder.decode(result.shouldSuppressMemoryPressureHandler))
+ return false;
if (!decoder.decode(result.shouldUseTestingNetworkSession))
return false;
if (!decoder.decode(result.urlSchemesRegisteredForCustomProtocols))
Modified: trunk/Source/WebKit2/NetworkProcess/NetworkProcessCreationParameters.h (196942 => 196943)
--- trunk/Source/WebKit2/NetworkProcess/NetworkProcessCreationParameters.h 2016-02-22 18:22:27 UTC (rev 196942)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkProcessCreationParameters.h 2016-02-22 18:31:03 UTC (rev 196943)
@@ -73,6 +73,7 @@
SandboxExtension::Handle containerCachesDirectoryExtensionHandle;
SandboxExtension::Handle parentBundleDirectoryExtensionHandle;
#endif
+ bool shouldSuppressMemoryPressureHandler { false };
bool shouldUseTestingNetworkSession;
Vector<String> urlSchemesRegisteredForCustomProtocols;
Modified: trunk/Source/WebKit2/Shared/WebProcessCreationParameters.cpp (196942 => 196943)
--- trunk/Source/WebKit2/Shared/WebProcessCreationParameters.cpp 2016-02-22 18:22:27 UTC (rev 196942)
+++ trunk/Source/WebKit2/Shared/WebProcessCreationParameters.cpp 2016-02-22 18:31:03 UTC (rev 196943)
@@ -97,6 +97,7 @@
encoder.encodeEnum(cacheModel);
encoder << shouldAlwaysUseComplexTextCodePath;
encoder << shouldEnableMemoryPressureReliefLogging;
+ encoder << shouldSuppressMemoryPressureHandler;
encoder << shouldUseFontSmoothing;
encoder << fontWhitelist;
encoder << iconDatabaseEnabled;
@@ -215,6 +216,8 @@
return false;
if (!decoder.decode(parameters.shouldEnableMemoryPressureReliefLogging))
return false;
+ if (!decoder.decode(parameters.shouldSuppressMemoryPressureHandler))
+ return false;
if (!decoder.decode(parameters.shouldUseFontSmoothing))
return false;
if (!decoder.decode(parameters.fontWhitelist))
Modified: trunk/Source/WebKit2/Shared/WebProcessCreationParameters.h (196942 => 196943)
--- trunk/Source/WebKit2/Shared/WebProcessCreationParameters.h 2016-02-22 18:22:27 UTC (rev 196942)
+++ trunk/Source/WebKit2/Shared/WebProcessCreationParameters.h 2016-02-22 18:31:03 UTC (rev 196943)
@@ -105,6 +105,7 @@
bool shouldAlwaysUseComplexTextCodePath;
bool shouldEnableMemoryPressureReliefLogging;
+ bool shouldSuppressMemoryPressureHandler { false };
bool shouldUseFontSmoothing;
Vector<String> fontWhitelist;
Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebProcessPoolCocoa.mm (196942 => 196943)
--- trunk/Source/WebKit2/UIProcess/Cocoa/WebProcessPoolCocoa.mm 2016-02-22 18:22:27 UTC (rev 196942)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebProcessPoolCocoa.mm 2016-02-22 18:31:03 UTC (rev 196943)
@@ -84,6 +84,8 @@
#endif
#endif
+static NSString * const WebKitSuppressMemoryPressureHandlerDefaultsKey = @"WebKitSuppressMemoryPressureHandler";
+
#if PLATFORM(MAC)
NSString *WebKitTabSuspension = @"WebKitTabSuspension";
#endif
@@ -178,13 +180,16 @@
parameters.accessibilityEnhancedUserInterfaceEnabled = false;
#endif
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+
#if PLATFORM(MAC)
- parameters.shouldEnableTabSuspension = [[NSUserDefaults standardUserDefaults] boolForKey:WebKitTabSuspension];
+ parameters.shouldEnableTabSuspension = [defaults boolForKey:WebKitTabSuspension];
#endif
- parameters.shouldEnableJIT = [[NSUserDefaults standardUserDefaults] boolForKey:WebKitJSCJITEnabledDefaultsKey];
- parameters.shouldEnableFTLJIT = [[NSUserDefaults standardUserDefaults] boolForKey:WebKitJSCFTLJITEnabledDefaultsKey];
- parameters.shouldEnableMemoryPressureReliefLogging = [[NSUserDefaults standardUserDefaults] boolForKey:@"LogMemoryJetsamDetails"];
+ parameters.shouldEnableJIT = [defaults boolForKey:WebKitJSCJITEnabledDefaultsKey];
+ parameters.shouldEnableFTLJIT = [defaults boolForKey:WebKitJSCFTLJITEnabledDefaultsKey];
+ parameters.shouldEnableMemoryPressureReliefLogging = [defaults boolForKey:@"LogMemoryJetsamDetails"];
+ parameters.shouldSuppressMemoryPressureHandler = [defaults boolForKey:WebKitSuppressMemoryPressureHandlerDefaultsKey];
#if PLATFORM(MAC)
parameters.shouldRewriteConstAsVar = applicationIsIBooks();
@@ -260,6 +265,8 @@
#endif
#endif
+ parameters.shouldSuppressMemoryPressureHandler = [defaults boolForKey:WebKitSuppressMemoryPressureHandlerDefaultsKey];
+
#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100
RetainPtr<CFDataRef> cookieStorageData = adoptCF(CFHTTPCookieStorageCreateIdentifyingData(kCFAllocatorDefault, [[NSHTTPCookieStorage sharedHTTPCookieStorage] _cookieStorage]));
ASSERT(parameters.uiProcessCookieStorageIdentifier.isEmpty());
Modified: trunk/Source/WebKit2/UIProcess/ios/WebMemoryPressureHandlerIOS.mm (196942 => 196943)
--- trunk/Source/WebKit2/UIProcess/ios/WebMemoryPressureHandlerIOS.mm 2016-02-22 18:22:27 UTC (rev 196942)
+++ trunk/Source/WebKit2/UIProcess/ios/WebMemoryPressureHandlerIOS.mm 2016-02-22 18:31:03 UTC (rev 196943)
@@ -44,6 +44,9 @@
// Right now it cannot because WebKit1 and WebKit2 need to be able to coexist in the UI process,
// and you can only have one WebCore::MemoryPressureHandler.
+ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"WebKitSuppressMemoryPressureHandler"])
+ return;
+
_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_MEMORYPRESSURE, 0, DISPATCH_MEMORYPRESSURE_WARN, dispatch_get_main_queue());
dispatch_set_context(_source, this);
dispatch_source_set_event_handler(_source, ^{
Modified: trunk/Source/WebKit2/WebProcess/WebProcess.cpp (196942 => 196943)
--- trunk/Source/WebKit2/WebProcess/WebProcess.cpp 2016-02-22 18:22:27 UTC (rev 196942)
+++ trunk/Source/WebKit2/WebProcess/WebProcess.cpp 2016-02-22 18:31:03 UTC (rev 196943)
@@ -252,7 +252,9 @@
WTF::setCurrentThreadIsUserInitiated();
- MemoryPressureHandler::singleton().install();
+ m_suppressMemoryPressureHandler = parameters.shouldSuppressMemoryPressureHandler;
+ if (!m_suppressMemoryPressureHandler)
+ MemoryPressureHandler::singleton().install();
if (!parameters.injectedBundlePath.isEmpty())
m_injectedBundle = InjectedBundle::create(parameters, transformHandlesToObjects(parameters.initializationUserData.object()).get());
@@ -1175,7 +1177,9 @@
void WebProcess::actualPrepareToSuspend(ShouldAcknowledgeWhenReadyToSuspend shouldAcknowledgeWhenReadyToSuspend)
{
- MemoryPressureHandler::singleton().releaseMemory(Critical::Yes, Synchronous::Yes);
+ if (!m_suppressMemoryPressureHandler)
+ MemoryPressureHandler::singleton().releaseMemory(Critical::Yes, Synchronous::Yes);
+
setAllLayerTreeStatesFrozen(true);
if (markAllLayersVolatileIfPossible()) {
Modified: trunk/Source/WebKit2/WebProcess/WebProcess.h (196942 => 196943)
--- trunk/Source/WebKit2/WebProcess/WebProcess.h 2016-02-22 18:22:27 UTC (rev 196942)
+++ trunk/Source/WebKit2/WebProcess/WebProcess.h 2016-02-22 18:31:03 UTC (rev 196943)
@@ -364,6 +364,7 @@
#endif
ShouldAcknowledgeWhenReadyToSuspend m_shouldAcknowledgeWhenReadyToSuspend;
+ bool m_suppressMemoryPressureHandler { false };
};
} // namespace WebKit