Title: [87228] trunk/Source
Revision
87228
Author
[email protected]
Date
2011-05-24 16:43:15 -0700 (Tue, 24 May 2011)

Log Message

2011-05-24  Michael Saboff  <[email protected]>

        Reviewed by Geoffrey Garen.

        Improve handling in WebCore of low memory situations
        https://bugs.webkit.org/show_bug.cgi?id=61222

        Added call to enable memory pressure handling.

        * WebView/WebView.mm:
        (-[WebView _commonInitializationWithFrameName:groupName:usesDocumentViews:]):
        * WebView/WebViewInternal.h:
2011-05-24  Michael Saboff  <[email protected]>

        Reviewed by Geoffrey Garen.

        Improve handling in WebCore of low memory situations
        https://bugs.webkit.org/show_bug.cgi?id=61222

        Added new class, MemoryPressureHandler, to platform to respond to low
        system memory events. Added Mac specific implementation that reduces the
        page cache, NSURL cache, WebCore cache by half their current usage
        and then garbage collects.  This can allow Safari to continue operating
        in a low memory situation with minimal paging.
        Split up prune operations in MemoryCache to allow for pruning to a
        specific actual size to support this change.

        No tests added as the functionality of WebKit wasn't changed.

        * GNUmakefile.list.am:
        * WebCore.exp.in:
        * WebCore.gypi:
        * WebCore.pro:
        * WebCore.vcproj/WebCore.vcproj:
        * WebCore.xcodeproj/project.pbxproj:
        * loader/cache/MemoryCache.cpp:
        (WebCore::MemoryCache::pruneLiveResources):
        (WebCore::MemoryCache::forcePruneLiveResources):
        (WebCore::MemoryCache::pruneLiveResourcesToTarget):
        (WebCore::MemoryCache::pruneDeadResources):
        (WebCore::MemoryCache::forcePruneDeadResources):
        (WebCore::MemoryCache::pruneDeadResourcesToTarget):
        * loader/cache/MemoryCache.h:
        (WebCore::MemoryCache::forcePrune):
        * platform/MemoryPressureHandler.cpp: Added.
        (WebCore::memoryPressureHandler):
        (WebCore::MemoryPressureHandler::MemoryPressureHandler):
        (WebCore::MemoryPressureHandler::install):
        (WebCore::MemoryPressureHandler::respondToMemoryPressure):
        * platform/MemoryPressureHandler.h: Added.
        * platform/mac/MemoryPressureHandler.mm: Added.
        (WebCore::MemoryPressureHandler::install):
        (WebCore::MemoryPressureHandler::respondToMemoryPressure):
2011-05-24  Michael Saboff  <[email protected]>

        Reviewed by Geoffrey Garen.

        Improve handling in WebCore of low memory situations
        https://bugs.webkit.org/show_bug.cgi?id=61222

        Added call to enable memory pressure handling for Mac case.

        * WebProcess/WebProcess.cpp:
        (WebKit::WebProcess::initializeWebProcess):
        * WebProcess/WebProcess.h:
        * WebProcess/mac/WebProcessMac.mm:
        (WebKit::WebProcess::platformInitializeWebProcess):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (87227 => 87228)


--- trunk/Source/WebCore/ChangeLog	2011-05-24 23:19:55 UTC (rev 87227)
+++ trunk/Source/WebCore/ChangeLog	2011-05-24 23:43:15 UTC (rev 87228)
@@ -1,3 +1,45 @@
+2011-05-24  Michael Saboff  <[email protected]>
+
+        Reviewed by Geoffrey Garen.
+
+        Improve handling in WebCore of low memory situations
+        https://bugs.webkit.org/show_bug.cgi?id=61222
+
+        Added new class, MemoryPressureHandler, to platform to respond to low
+        system memory events. Added Mac specific implementation that reduces the
+        page cache, NSURL cache, WebCore cache by half their current usage
+        and then garbage collects.  This can allow Safari to continue operating
+        in a low memory situation with minimal paging.
+        Split up prune operations in MemoryCache to allow for pruning to a
+        specific actual size to support this change.
+
+        No tests added as the functionality of WebKit wasn't changed.
+
+        * GNUmakefile.list.am:
+        * WebCore.exp.in:
+        * WebCore.gypi:
+        * WebCore.pro:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * loader/cache/MemoryCache.cpp:
+        (WebCore::MemoryCache::pruneLiveResources):
+        (WebCore::MemoryCache::forcePruneLiveResources):
+        (WebCore::MemoryCache::pruneLiveResourcesToTarget):
+        (WebCore::MemoryCache::pruneDeadResources):
+        (WebCore::MemoryCache::forcePruneDeadResources):
+        (WebCore::MemoryCache::pruneDeadResourcesToTarget):
+        * loader/cache/MemoryCache.h:
+        (WebCore::MemoryCache::forcePrune):
+        * platform/MemoryPressureHandler.cpp: Added.
+        (WebCore::memoryPressureHandler):
+        (WebCore::MemoryPressureHandler::MemoryPressureHandler):
+        (WebCore::MemoryPressureHandler::install):
+        (WebCore::MemoryPressureHandler::respondToMemoryPressure):
+        * platform/MemoryPressureHandler.h: Added.
+        * platform/mac/MemoryPressureHandler.mm: Added.
+        (WebCore::MemoryPressureHandler::install):
+        (WebCore::MemoryPressureHandler::respondToMemoryPressure):
+
 2011-05-24  Kent Tamura  <[email protected]>
 
         Reviewed by Dimitri Glazkov.

Modified: trunk/Source/WebCore/GNUmakefile.list.am (87227 => 87228)


--- trunk/Source/WebCore/GNUmakefile.list.am	2011-05-24 23:19:55 UTC (rev 87227)
+++ trunk/Source/WebCore/GNUmakefile.list.am	2011-05-24 23:43:15 UTC (rev 87228)
@@ -2539,6 +2539,8 @@
 	Source/WebCore/platform/Logging.h \
 	Source/WebCore/platform/MIMETypeRegistry.cpp \
 	Source/WebCore/platform/MIMETypeRegistry.h \
+	Source/WebCore/platform/MemoryPressureHandler.cpp \
+	Source/WebCore/platform/MemoryPressureHandler.h \
 	Source/WebCore/platform/mock/DeviceOrientationClientMock.cpp \
 	Source/WebCore/platform/mock/DeviceOrientationClientMock.h \
 	Source/WebCore/platform/mock/GeolocationClientMock.cpp \

Modified: trunk/Source/WebCore/WebCore.exp.in (87227 => 87228)


--- trunk/Source/WebCore/WebCore.exp.in	2011-05-24 23:19:55 UTC (rev 87227)
+++ trunk/Source/WebCore/WebCore.exp.in	2011-05-24 23:43:15 UTC (rev 87228)
@@ -545,6 +545,8 @@
 __ZN7WebCore20makeRGBA32FromFloatsEffff
 __ZN7WebCore20protocolIsJavaScriptERKN3WTF6StringE
 __ZN7WebCore21BackForwardController11itemAtIndexEi
+__ZN7WebCore21memoryPressureHandlerEv
+__ZN7WebCore21MemoryPressureHandler7installEv
 __ZN7WebCore21PlatformKeyboardEvent24disambiguateKeyDownEventENS0_4TypeEb
 __ZN7WebCore21PlatformKeyboardEventC1EP7NSEvent
 __ZN7WebCore21ResourceLoadScheduler20servePendingRequestsENS_20ResourceLoadPriorityE

Modified: trunk/Source/WebCore/WebCore.gypi (87227 => 87228)


--- trunk/Source/WebCore/WebCore.gypi	2011-05-24 23:19:55 UTC (rev 87227)
+++ trunk/Source/WebCore/WebCore.gypi	2011-05-24 23:43:15 UTC (rev 87228)
@@ -763,6 +763,7 @@
             'platform/LocalizationStrategy.h',
             'platform/LocalizedStrings.h',
             'platform/Logging.h',
+            'platform/MemoryPressureHandler.h',
             'platform/MIMETypeRegistry.h',
             'platform/NotImplemented.h',
             'platform/PlatformGestureEvent.h',
@@ -3583,6 +3584,7 @@
             'platform/LinkHash.cpp',
             'platform/LocalizedStrings.cpp',
             'platform/Logging.cpp',
+            'platform/MemoryPressureHandler.cpp',
             'platform/MIMETypeRegistry.cpp',
             'platform/Pasteboard.h',
             'platform/PlatformStrategies.cpp',

Modified: trunk/Source/WebCore/WebCore.pro (87227 => 87228)


--- trunk/Source/WebCore/WebCore.pro	2011-05-24 23:19:55 UTC (rev 87227)
+++ trunk/Source/WebCore/WebCore.pro	2011-05-24 23:43:15 UTC (rev 87228)
@@ -1021,6 +1021,7 @@
     platform/leveldb/LevelDBSlice.h \
     platform/LinkHash.cpp \
     platform/Logging.cpp \
+    platform/MemoryPressureHandler.cpp \
     platform/MIMETypeRegistry.cpp \
     platform/mock/DeviceOrientationClientMock.cpp \
     platform/mock/GeolocationClientMock.cpp \
@@ -1997,6 +1998,7 @@
     platform/LinkHash.h \
     platform/Logging.h \
     platform/Language.h \
+    platfory/MemoryPressureHandler.h \
     platform/MIMETypeRegistry.h \
     platform/network/AuthenticationChallengeBase.h \
     platform/network/AuthenticationClient.h \

Modified: trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj (87227 => 87228)


--- trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2011-05-24 23:19:55 UTC (rev 87227)
+++ trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2011-05-24 23:43:15 UTC (rev 87228)
@@ -26094,6 +26094,14 @@
 				>
 			</File>
 			<File
+				RelativePath="..\platform\MemoryPressureHandler.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\platform\MemoryPressureHandler.h"
+				>
+			</File>
+			<File
 				RelativePath="..\platform\NotImplemented.h"
 				>
 			</File>

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (87227 => 87228)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2011-05-24 23:19:55 UTC (rev 87227)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2011-05-24 23:43:15 UTC (rev 87228)
@@ -1490,6 +1490,9 @@
 		656D37410ADBA5DE00A4554D /* MainResourceLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 656D37290ADBA5DE00A4554D /* MainResourceLoader.h */; };
 		656D37430ADBA5DE00A4554D /* NetscapePlugInStreamLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 656D372B0ADBA5DE00A4554D /* NetscapePlugInStreamLoader.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		656D37480ADBA5DE00A4554D /* SubresourceLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 656D37300ADBA5DE00A4554D /* SubresourceLoader.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		6571DCC81385E6A400702DD0 /* MemoryPressureHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 657EDA071385CB97004E0645 /* MemoryPressureHandler.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		657EDA081385CB97004E0645 /* MemoryPressureHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 657EDA061385CB97004E0645 /* MemoryPressureHandler.cpp */; };
+		657EDA0B1385CBD8004E0645 /* MemoryPressureHandlerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 657EDA0A1385CBD8004E0645 /* MemoryPressureHandlerMac.mm */; };
 		6582A16309999D6D00BEEB6D /* SystemTimeMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6582A15509999D6D00BEEB6D /* SystemTimeMac.cpp */; };
 		658436860AE01B7400E53753 /* FrameLoadRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 658436850AE01B7400E53753 /* FrameLoadRequest.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		6593923709AE4346002C531F /* KURL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6593923509AE4346002C531F /* KURL.cpp */; };
@@ -8068,6 +8071,9 @@
 		656D37290ADBA5DE00A4554D /* MainResourceLoader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MainResourceLoader.h; sourceTree = "<group>"; };
 		656D372B0ADBA5DE00A4554D /* NetscapePlugInStreamLoader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = NetscapePlugInStreamLoader.h; sourceTree = "<group>"; };
 		656D37300ADBA5DE00A4554D /* SubresourceLoader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SubresourceLoader.h; sourceTree = "<group>"; };
+		657EDA061385CB97004E0645 /* MemoryPressureHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MemoryPressureHandler.cpp; sourceTree = "<group>"; };
+		657EDA071385CB97004E0645 /* MemoryPressureHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MemoryPressureHandler.h; sourceTree = "<group>"; };
+		657EDA0A1385CBD8004E0645 /* MemoryPressureHandlerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MemoryPressureHandlerMac.mm; sourceTree = "<group>"; };
 		6582A15509999D6D00BEEB6D /* SystemTimeMac.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SystemTimeMac.cpp; sourceTree = "<group>"; };
 		658436850AE01B7400E53753 /* FrameLoadRequest.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FrameLoadRequest.h; sourceTree = "<group>"; };
 		6593923509AE4346002C531F /* KURL.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = KURL.cpp; sourceTree = "<group>"; };
@@ -14149,6 +14155,7 @@
 				06E81EEB0AB5DA9700C87837 /* LocalCurrentGraphicsContext.mm */,
 				BC25B528131C6D3900180E10 /* LocalizedStringsMac.mm */,
 				1402645D0AFDC19B005919E2 /* LoggingMac.mm */,
+				657EDA0A1385CBD8004E0645 /* MemoryPressureHandlerMac.mm */,
 				BC772C5D0C4EB3440083285F /* MIMETypeRegistryMac.mm */,
 				A7D3C5230B576B4B002CA450 /* PasteboardHelper.h */,
 				4B2709810AF2E5E00065127F /* PasteboardMac.mm */,
@@ -18633,6 +18640,8 @@
 				935207BD09BD410A00F2038D /* LocalizedStrings.h */,
 				A8239DFE09B3CF8A00B60641 /* Logging.cpp */,
 				A8239DFF09B3CF8A00B60641 /* Logging.h */,
+				657EDA061385CB97004E0645 /* MemoryPressureHandler.cpp */,
+				657EDA071385CB97004E0645 /* MemoryPressureHandler.h */,
 				BC772C4C0C4EB3040083285F /* MIMETypeRegistry.cpp */,
 				BC772C4D0C4EB3040083285F /* MIMETypeRegistry.h */,
 				98EB1F941313FE0500D0E1EA /* NotImplemented.h */,
@@ -22920,6 +22929,7 @@
 				E1BE512E0CF6C512002EA959 /* XSLTUnicodeSort.h in Headers */,
 				977E2E0F12F0FC9C00C13379 /* XSSFilter.h in Headers */,
 				FD537353137B651800008DCE /* ZeroPole.h in Headers */,
+				6571DCC81385E6A400702DD0 /* MemoryPressureHandler.h in Headers */,
 				598365DD1355F557001B185D /* JSPositionCallback.h in Headers */,
 				598365DF1355F562001B185D /* JSPositionErrorCallback.h in Headers */,
 				B1E5457B1346291F0092A545 /* GeneratedStream.h in Headers */,
@@ -25604,6 +25614,8 @@
 				E1BE512D0CF6C512002EA959 /* XSLTUnicodeSort.cpp in Sources */,
 				977E2E0E12F0FC9C00C13379 /* XSSFilter.cpp in Sources */,
 				FD537352137B651800008DCE /* ZeroPole.cpp in Sources */,
+				657EDA081385CB97004E0645 /* MemoryPressureHandler.cpp in Sources */,
+				657EDA0B1385CBD8004E0645 /* MemoryPressureHandlerMac.mm in Sources */,
 				598365E41355F604001B185D /* JSPositionCallback.cpp in Sources */,
 				598365E61355F60D001B185D /* JSPositionErrorCallback.cpp in Sources */,
 				B1E5457A1346291F0092A545 /* GeneratedStream.cpp in Sources */,

Modified: trunk/Source/WebCore/loader/cache/MemoryCache.cpp (87227 => 87228)


--- trunk/Source/WebCore/loader/cache/MemoryCache.cpp	2011-05-24 23:19:55 UTC (rev 87227)
+++ trunk/Source/WebCore/loader/cache/MemoryCache.cpp	2011-05-24 23:43:15 UTC (rev 87228)
@@ -172,6 +172,26 @@
         return;
 
     unsigned targetSize = static_cast<unsigned>(capacity * cTargetPrunePercentage); // Cut by a percentage to avoid immediately pruning again.
+
+    pruneLiveResourcesToSize(targetSize);
+}
+
+void MemoryCache::PruneLiveResourcesToPercentage(float prunePercentage)
+{
+    if (!m_pruneEnabled)
+        return;
+
+    if (prunePercentage < 0.0f  || prunePercentage > 0.95f)
+        return;
+
+    unsigned currentSize = m_liveSize + m_deadSize;
+    unsigned targetSize = static_cast<unsigned>(currentSize * prunePercentage);
+
+    pruneLiveResourcesToSize(targetSize);
+}
+
+void MemoryCache::pruneLiveResourcesToSize(unsigned targetSize)
+{
     double currentTime = FrameView::currentPaintTimeStamp();
     if (!currentTime) // In case prune is called directly, outside of a Frame paint.
         currentTime = WTF::currentTime();
@@ -216,8 +236,27 @@
         return;
 
     unsigned targetSize = static_cast<unsigned>(capacity * cTargetPrunePercentage); // Cut by a percentage to avoid immediately pruning again.
+    pruneDeadResourcesToSize(targetSize);
+}
+
+void MemoryCache::PruneDeadResourcesToPercentage(float prunePercentage)
+{
+    if (!m_pruneEnabled)
+        return;
+
+    if (prunePercentage < 0.0f  || prunePercentage > 0.95f)
+        return;
+
+    unsigned currentSize = m_liveSize + m_deadSize;
+    unsigned targetSize = static_cast<unsigned>(currentSize * prunePercentage);
+
+    pruneDeadResourcesToSize(targetSize);
+}
+
+void MemoryCache::pruneDeadResourcesToSize(unsigned targetSize)
+{ 
     int size = m_allResources.size();
-    
+ 
     if (!m_inPruneDeadResources) {
         // See if we have any purged resources we can evict.
         for (int i = 0; i < size; i++) {

Modified: trunk/Source/WebCore/loader/cache/MemoryCache.h (87227 => 87228)


--- trunk/Source/WebCore/loader/cache/MemoryCache.h	2011-05-24 23:19:55 UTC (rev 87227)
+++ trunk/Source/WebCore/loader/cache/MemoryCache.h	2011-05-24 23:43:15 UTC (rev 87228)
@@ -139,6 +139,12 @@
         pruneLiveResources();
     }
 
+    void pruneToPercentage(float targetPercentLive)
+    {
+        PruneDeadResourcesToPercentage(targetPercentLive); // Prune dead first, in case it was "borrowing" capacity from live.
+        PruneLiveResourcesToPercentage(targetPercentLive);
+    }
+
     void setDeadDecodedDataDeletionInterval(double interval) { m_deadDecodedDataDeletionInterval = interval; }
     double deadDecodedDataDeletionInterval() const { return m_deadDecodedDataDeletionInterval; }
 
@@ -182,10 +188,16 @@
 
     unsigned liveCapacity() const;
     unsigned deadCapacity() const;
-    
-    void pruneDeadResources(); // Flush decoded and encoded data from resources not referenced by Web pages.
-    void pruneLiveResources(); // Flush decoded data from resources still referenced by Web pages.
 
+    // pruneDead*() - Flush decoded and encoded data from resources not referenced by Web pages.
+    // pruneLive*() - Flush decoded data from resources still referenced by Web pages.
+    void pruneDeadResources(); // Automatically decide how much to prune.
+    void pruneLiveResources();
+    void PruneDeadResourcesToPercentage(float prunePercentage);
+    void PruneLiveResourcesToPercentage(float prunePercentage);
+    void pruneDeadResourcesToSize(unsigned targetSize);
+    void pruneLiveResourcesToSize(unsigned targetSize);
+
     bool makeResourcePurgeable(CachedResource*);
     void evict(CachedResource*);
 

Added: trunk/Source/WebCore/platform/MemoryPressureHandler.cpp (0 => 87228)


--- trunk/Source/WebCore/platform/MemoryPressureHandler.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/MemoryPressureHandler.cpp	2011-05-24 23:43:15 UTC (rev 87228)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "MemoryPressureHandler.h"
+
+#include <wtf/StdLibExtras.h>
+
+namespace WebCore {
+
+MemoryPressureHandler& memoryPressureHandler()
+{
+    DEFINE_STATIC_LOCAL(MemoryPressureHandler, staticMemoryPressureHandler, ());
+    return staticMemoryPressureHandler;
+}
+
+MemoryPressureHandler::MemoryPressureHandler() { }
+
+#if !PLATFORM(MAC) || defined(BUILDING_ON_LEOPARD) || defined(BUILDING_ON_SNOW_LEOPARD)
+void MemoryPressureHandler::install() { }
+
+void MemoryPressureHandler::respondToMemoryPressure() { }
+#endif
+ 
+} // namespace WebCore

Added: trunk/Source/WebCore/platform/MemoryPressureHandler.h (0 => 87228)


--- trunk/Source/WebCore/platform/MemoryPressureHandler.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/MemoryPressureHandler.h	2011-05-24 23:43:15 UTC (rev 87228)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef MemoryPressureHandler_h
+#define MemoryPressureHandler_h
+
+#include <wtf/Platform.h>
+
+namespace WebCore {
+
+class MemoryPressureHandler {
+public:
+    friend MemoryPressureHandler& memoryPressureHandler();
+
+    void install();
+
+private:
+    MemoryPressureHandler();
+    ~MemoryPressureHandler();
+
+    void respondToMemoryPressure();
+};
+ 
+// Function to obtain the global memory pressure object.
+MemoryPressureHandler& memoryPressureHandler();
+
+} // namespace WebCore
+
+#endif // MemoryPressureHandler_h

Added: trunk/Source/WebCore/platform/mac/MemoryPressureHandlerMac.mm (0 => 87228)


--- trunk/Source/WebCore/platform/mac/MemoryPressureHandlerMac.mm	                        (rev 0)
+++ trunk/Source/WebCore/platform/mac/MemoryPressureHandlerMac.mm	2011-05-24 23:43:15 UTC (rev 87228)
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "MemoryPressureHandler.h"
+#import <WebCore/GCController.h>
+#import <WebCore/MemoryCache.h>
+#import <WebCore/PageCache.h>
+#import <wtf/FastMalloc.h>
+
+#if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
+#import <dispatch/dispatch.h>
+
+#ifndef DISPATCH_SOURCE_TYPE_VM
+#define DISPATCH_SOURCE_TYPE_VM (&_dispatch_source_type_vm)
+DISPATCH_EXPORT const struct dispatch_source_type_s _dispatch_source_type_vm;
+#endif
+
+#ifdef DISPATCH_VM_PRESSURE
+enum {
+ DISPATCH_VM_PRESSURE = 0x80000000,
+};
+#endif
+
+#endif
+
+namespace WebCore {
+
+#if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
+
+static dispatch_source_t _cache_event_source = 0;
+#ifndef NDEBUG
+static dispatch_source_t _cache_event_source2 = 0;
+#endif
+
+void MemoryPressureHandler::install()
+{
+    if (!_cache_event_source) {
+        dispatch_async(dispatch_get_main_queue(), ^{
+            _cache_event_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_VM, 0, DISPATCH_VM_PRESSURE, dispatch_get_main_queue());
+            if (_cache_event_source) {
+                dispatch_set_context(_cache_event_source, this);
+                dispatch_source_set_event_handler(_cache_event_source, ^{ memoryPressureHandler().respondToMemoryPressure();});
+                dispatch_resume(_cache_event_source);
+            }
+        });
+    }
+
+#ifndef NDEBUG
+    if (!_cache_event_source2) {
+        dispatch_async(dispatch_get_main_queue(), ^{
+            _cache_event_source2 = dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, SIGUSR2, 0, dispatch_get_main_queue());
+            if (_cache_event_source2) {
+                dispatch_set_context(_cache_event_source2, this);
+                dispatch_source_set_event_handler(_cache_event_source2, ^{ memoryPressureHandler().respondToMemoryPressure();});
+                dispatch_resume(_cache_event_source2);
+                signal((int)SIGUSR2, SIG_IGN);
+            }
+        });
+    }
+#endif
+}
+
+void MemoryPressureHandler::respondToMemoryPressure()
+{
+    int savedPageCacheCapacity = pageCache()->capacity();
+    pageCache()->setCapacity(pageCache()->pageCount()>>1);
+    pageCache()->setCapacity(savedPageCacheCapacity);
+    pageCache()->releaseAutoreleasedPagesNow();
+
+    NSURLCache *nsurlCache = [NSURLCache sharedURLCache];
+    NSUInteger savedNsurlCacheMemoryCapacity = [nsurlCache memoryCapacity];
+    [nsurlCache setMemoryCapacity:[nsurlCache currentMemoryUsage]>>1];
+    [nsurlCache setMemoryCapacity:savedNsurlCacheMemoryCapacity];
+ 
+    memoryCache()->pruneToPercentage(0.5f);
+
+    gcController().garbageCollectNow();
+
+    WTF::releaseFastMallocFreeMemory();
+}
+#endif
+
+} // namespace WebCore

Modified: trunk/Source/WebKit/mac/ChangeLog (87227 => 87228)


--- trunk/Source/WebKit/mac/ChangeLog	2011-05-24 23:19:55 UTC (rev 87227)
+++ trunk/Source/WebKit/mac/ChangeLog	2011-05-24 23:43:15 UTC (rev 87228)
@@ -1,3 +1,16 @@
+2011-05-24  Michael Saboff  <[email protected]>
+
+        Reviewed by Geoffrey Garen.
+
+        Improve handling in WebCore of low memory situations
+        https://bugs.webkit.org/show_bug.cgi?id=61222
+
+        Added call to enable memory pressure handling.
+
+        * WebView/WebView.mm:
+        (-[WebView _commonInitializationWithFrameName:groupName:usesDocumentViews:]):
+        * WebView/WebViewInternal.h:
+
 2011-05-24  Jay Civelli  <[email protected]>
 
         Rubberstamped by David Kilzer.

Modified: trunk/Source/WebKit/mac/WebView/WebView.mm (87227 => 87228)


--- trunk/Source/WebKit/mac/WebView/WebView.mm	2011-05-24 23:19:55 UTC (rev 87227)
+++ trunk/Source/WebKit/mac/WebView/WebView.mm	2011-05-24 23:43:15 UTC (rev 87228)
@@ -138,6 +138,7 @@
 #import <WebCore/JSElement.h>
 #import <WebCore/JSNodeList.h>
 #import <WebCore/Logging.h>
+#import <WebCore/MemoryPressureHandler.h>
 #import <WebCore/MIMETypeRegistry.h>
 #import <WebCore/NodeList.h>
 #import <WebCore/Page.h>
@@ -798,6 +799,8 @@
     [self _preferencesChanged:[self preferences]];
     [[self preferences] _postPreferencesChangedAPINotification];
 
+    memoryPressureHandler().install();
+
     if (!WebKitLinkedOnOrAfter(WEBKIT_FIRST_VERSION_WITH_LOCAL_RESOURCE_SECURITY_RESTRICTION)) {
         // Originally, we allowed all local loads.
         SecurityOrigin::setLocalLoadPolicy(SecurityOrigin::AllowLocalLoadsForAll);

Modified: trunk/Source/WebKit2/ChangeLog (87227 => 87228)


--- trunk/Source/WebKit2/ChangeLog	2011-05-24 23:19:55 UTC (rev 87227)
+++ trunk/Source/WebKit2/ChangeLog	2011-05-24 23:43:15 UTC (rev 87228)
@@ -1,3 +1,18 @@
+2011-05-24  Michael Saboff  <[email protected]>
+
+        Reviewed by Geoffrey Garen.
+
+        Improve handling in WebCore of low memory situations
+        https://bugs.webkit.org/show_bug.cgi?id=61222
+
+        Added call to enable memory pressure handling for Mac case.
+
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::initializeWebProcess):
+        * WebProcess/WebProcess.h:
+        * WebProcess/mac/WebProcessMac.mm:
+        (WebKit::WebProcess::platformInitializeWebProcess):
+
 2011-05-24  Brady Eidson  <[email protected]>
 
         Reviewed by Darin Adler.

Modified: trunk/Source/WebKit2/WebProcess/WebProcess.cpp (87227 => 87228)


--- trunk/Source/WebKit2/WebProcess/WebProcess.cpp	2011-05-24 23:19:55 UTC (rev 87227)
+++ trunk/Source/WebKit2/WebProcess/WebProcess.cpp	2011-05-24 23:43:15 UTC (rev 87228)
@@ -58,6 +58,7 @@
 #include <WebCore/Language.h>
 #include <WebCore/Logging.h>
 #include <WebCore/MemoryCache.h>
+#include <WebCore/MemoryPressureHandler.h>
 #include <WebCore/Page.h>
 #include <WebCore/PageCache.h>
 #include <WebCore/PageGroup.h>
@@ -164,6 +165,8 @@
 
     platformInitializeWebProcess(parameters, arguments);
 
+    memoryPressureHandler().install();
+
     RefPtr<APIObject> injectedBundleInitializationUserData;
     InjectedBundleUserMessageDecoder messageDecoder(injectedBundleInitializationUserData);
     if (!arguments->decode(messageDecoder))
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to