<https://webkit.org/b/134811>
Split memory pressure relief into critical and non-critical sections.
Non-critical relief is for clearing out things that are really not
essential, e.g unused font data, text measurement caches, etc.
On iOS, only flip the "WebKit is under memory pressure" flag when we
are under *critical* memroy pressure, rather than doing it early on
and gimping ourselves because other processes are too big.
Also added logging for when we transition in/out of system pressure.
Reviewed by Geoffrey Garen.
* platform/MemoryPressureHandler.cpp:
(WebCore::MemoryPressureHandler::releaseNoncriticalMemory):
(WebCore::MemoryPressureHandler::releaseCriticalMemory):
(WebCore::MemoryPressureHandler::releaseMemory):
* platform/MemoryPressureHandler.h:
(WebCore::MemoryPressureHandler::ReliefLogger::loggingEnabled):
* platform/cocoa/MemoryPressureHandlerCocoa.mm:
(WebCore::MemoryPressureHandler::install):
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@170973
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2014-07-10 Andreas Kling <akling@apple.com>
+
+ [iOS WebKit2] Some memory pressure relief tweaks.
+ <https://webkit.org/b/134811>
+
+ Split memory pressure relief into critical and non-critical sections.
+ Non-critical relief is for clearing out things that are really not
+ essential, e.g unused font data, text measurement caches, etc.
+
+ On iOS, only flip the "WebKit is under memory pressure" flag when we
+ are under *critical* memroy pressure, rather than doing it early on
+ and gimping ourselves because other processes are too big.
+
+ Also added logging for when we transition in/out of system pressure.
+
+ Reviewed by Geoffrey Garen.
+
+ * platform/MemoryPressureHandler.cpp:
+ (WebCore::MemoryPressureHandler::releaseNoncriticalMemory):
+ (WebCore::MemoryPressureHandler::releaseCriticalMemory):
+ (WebCore::MemoryPressureHandler::releaseMemory):
+ * platform/MemoryPressureHandler.h:
+ (WebCore::MemoryPressureHandler::ReliefLogger::loggingEnabled):
+ * platform/cocoa/MemoryPressureHandlerCocoa.mm:
+ (WebCore::MemoryPressureHandler::install):
+
2014-07-10 Beth Dakin <bdakin@apple.com>
Need Setting/WKPreference that allows clients to prevent scrollbars from drawing
{
}
-void MemoryPressureHandler::releaseMemory(bool critical)
+void MemoryPressureHandler::releaseNoncriticalMemory()
+{
+ {
+ ReliefLogger log("Purge inactive FontData");
+ fontCache().purgeInactiveFontData();
+ }
+
+ {
+ ReliefLogger log("Clear WidthCaches");
+ clearWidthCaches();
+ }
+
+ {
+ ReliefLogger log("Discard Selector Query Cache");
+ for (auto* document : Document::allDocuments())
+ document->clearSelectorQueryCache();
+ }
+
+ {
+ ReliefLogger log("Clearing JS string cache");
+ JSDOMWindow::commonVM().stringCache.clear();
+ }
+}
+
+void MemoryPressureHandler::releaseCriticalMemory()
{
{
ReliefLogger log("Empty the PageCache");
}
{
- ReliefLogger log("Purge inactive FontData");
- fontCache().purgeInactiveFontData();
- }
-
- {
ReliefLogger log("Prune MemoryCache");
memoryCache()->pruneToPercentage(0);
}
}
{
- ReliefLogger log("Clear WidthCaches");
- clearWidthCaches();
- }
-
- {
ReliefLogger log("Discard StyleResolvers");
for (auto* document : Document::allDocuments())
document->clearStyleResolver();
}
{
- ReliefLogger log("Discard Selector Query Cache");
- for (auto* document : Document::allDocuments())
- document->clearSelectorQueryCache();
- }
-
- {
ReliefLogger log("Discard all JIT-compiled code");
gcController().discardAllCompiledCode();
}
+}
- {
- ReliefLogger log("Clearing JS string cache");
- JSDOMWindow::commonVM().stringCache.clear();
- }
+void MemoryPressureHandler::releaseMemory(bool critical)
+{
+ releaseNoncriticalMemory();
+
+ if (critical)
+ releaseCriticalMemory();
platformReleaseMemory(critical);
const char* logString() const { return m_logString; }
static void setLoggingEnabled(bool enabled) { s_loggingEnabled = enabled; }
+ static bool loggingEnabled() { return s_loggingEnabled; }
private:
size_t platformMemoryUsage();
static void releaseMemory(bool critical);
private:
+ static void releaseNoncriticalMemory();
+ static void releaseCriticalMemory();
+
void uninstall();
void holdOff(unsigned);
#if PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 80000
unsigned long status = dispatch_source_get_data(_cache_event_source);
critical = status == DISPATCH_MEMORYPRESSURE_CRITICAL;
+ bool wasCritical = memoryPressureHandler().isUnderMemoryPressure();
+ memoryPressureHandler().setUnderMemoryPressure(critical);
if (status == DISPATCH_MEMORYSTATUS_PRESSURE_NORMAL) {
- memoryPressureHandler().setUnderMemoryPressure(false);
+ if (ReliefLogger::loggingEnabled())
+ NSLog(@"System is no longer under (%s) memory pressure.", wasCritical ? "critical" : "non-critical");
return;
}
- memoryPressureHandler().setUnderMemoryPressure(true);
+
+ if (ReliefLogger::loggingEnabled())
+ NSLog(@"Got memory pressure notification (%s)", critical ? "critical" : "non-critical");
#endif
memoryPressureHandler().respondToMemoryPressure(critical);
});