Title: [112910] trunk/Source/WebCore
Revision
112910
Author
msab...@apple.com
Date
2012-04-02 11:13:37 -0700 (Mon, 02 Apr 2012)

Log Message

WebKit should throttle memory pressure notifications in proportion to handler time
https://bugs.webkit.org/show_bug.cgi?id=82674

Reviewed by Geoffrey Garen.

Changed the MemoryPressureHandler hold off timer to start timing after 
respondToMemoryPressure runs.  The delay time is now 20 times longer than the
time it took for respondToMemoryPressure to run with a minimum of 5 seconds.
This throttles the response to low memory events in the extreme case where
we are spending most of our time paging / swapping.
This is a Mac only change.

No additional tests. This passes existing test and was verified using
manual tests on a small memory system with many websites open.

* platform/mac/MemoryPressureHandlerMac.mm:
(WebCore):
(WebCore::MemoryPressureHandler::holdOff):
(WebCore::MemoryPressureHandler::respondToMemoryPressure):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (112909 => 112910)


--- trunk/Source/WebCore/ChangeLog	2012-04-02 18:08:03 UTC (rev 112909)
+++ trunk/Source/WebCore/ChangeLog	2012-04-02 18:13:37 UTC (rev 112910)
@@ -1,3 +1,25 @@
+2012-04-02  Michael Saboff  <msab...@apple.com>
+
+        WebKit should throttle memory pressure notifications in proportion to handler time
+        https://bugs.webkit.org/show_bug.cgi?id=82674
+
+        Reviewed by Geoffrey Garen.
+
+        Changed the MemoryPressureHandler hold off timer to start timing after 
+        respondToMemoryPressure runs.  The delay time is now 20 times longer than the
+        time it took for respondToMemoryPressure to run with a minimum of 5 seconds.
+        This throttles the response to low memory events in the extreme case where
+        we are spending most of our time paging / swapping.
+        This is a Mac only change.
+
+        No additional tests. This passes existing test and was verified using
+        manual tests on a small memory system with many websites open.
+
+        * platform/mac/MemoryPressureHandlerMac.mm:
+        (WebCore):
+        (WebCore::MemoryPressureHandler::holdOff):
+        (WebCore::MemoryPressureHandler::respondToMemoryPressure):
+
 2012-04-02  Sheriff Bot  <webkit.review....@gmail.com>
 
         Unreviewed, rolling out r112163.

Modified: trunk/Source/WebCore/platform/mac/MemoryPressureHandlerMac.mm (112909 => 112910)


--- trunk/Source/WebCore/platform/mac/MemoryPressureHandlerMac.mm	2012-04-02 18:08:03 UTC (rev 112909)
+++ trunk/Source/WebCore/platform/mac/MemoryPressureHandlerMac.mm	2012-04-02 18:13:37 UTC (rev 112910)
@@ -30,6 +30,7 @@
 #import <WebCore/FontCache.h>
 #import <WebCore/MemoryCache.h>
 #import <WebCore/PageCache.h>
+#import <wtf/CurrentTime.h>
 #import <wtf/FastMalloc.h>
 
 #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) && !PLATFORM(IOS)
@@ -46,10 +47,14 @@
 static dispatch_source_t _timer_event_source = 0;
 static int _notifyToken;
 
-// Disable memory event reception for 5 seconds after receiving an event. 
-// This value seems reasonable and testing verifies that it throttles frequent
+// Disable memory event reception for a minimum of s_minimumHoldOffTime
+// seconds after receiving an event.  Don't let events fire any sooner than
+// s_holdOffMultiplier times the last cleanup processing time.  Effectively 
+// this is 1 / s_holdOffMultiplier percent of the time.
+// These value seems reasonable and testing verifies that it throttles frequent
 // low memory events, greatly reducing CPU usage.
-static const time_t s_secondsBetweenMemoryCleanup = 5;
+static const time_t s_minimumHoldOffTime = 5;
+static const time_t s_holdOffMultiplier = 20;
 
 void MemoryPressureHandler::install()
 {
@@ -93,13 +98,11 @@
 
 void MemoryPressureHandler::holdOff(unsigned seconds)
 {
-    uninstall();
-
     dispatch_async(dispatch_get_main_queue(), ^{
         _timer_event_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue());
         if (_timer_event_source) {
             dispatch_set_context(_timer_event_source, this);
-            dispatch_source_set_timer(_timer_event_source, dispatch_time(DISPATCH_TIME_NOW, seconds * NSEC_PER_SEC), DISPATCH_TIME_FOREVER, 1 * s_secondsBetweenMemoryCleanup);
+            dispatch_source_set_timer(_timer_event_source, dispatch_time(DISPATCH_TIME_NOW, seconds * NSEC_PER_SEC), DISPATCH_TIME_FOREVER, 1 * s_minimumHoldOffTime);
             dispatch_source_set_event_handler(_timer_event_source, ^{
                 dispatch_source_cancel(_timer_event_source);
                 dispatch_release(_timer_event_source);
@@ -113,9 +116,23 @@
 
 void MemoryPressureHandler::respondToMemoryPressure()
 {
-    holdOff(s_secondsBetweenMemoryCleanup);
+    double startTime, endTime;
+    unsigned holdOffTime;
 
+    uninstall();
+
+    startTime = monotonicallyIncreasingTime();
+
     releaseMemory(false);
+
+    endTime = monotonicallyIncreasingTime();
+
+    holdOffTime = (unsigned)((endTime - startTime) * (double)s_holdOffMultiplier);
+
+    if (holdOffTime < s_minimumHoldOffTime)
+        holdOffTime = s_minimumHoldOffTime;
+
+    holdOff(holdOffTime);
 }
 #endif // !PLATFORM(IOS)
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to