[iOS WebKit2] Stay in "memory pressure" mode until told otherwise.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Jun 2014 16:02:03 +0000 (16:02 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Jun 2014 16:02:03 +0000 (16:02 +0000)
<https://webkit.org/b/133671>

When we receive the first memory pressure signal, flip the flag in
MemoryPressureHandler so that isUnderMemoryPressure() returns true
from then on, until the system tells us pressure levels are back
to normal.

The hold-off mechanism is disabled for iOS, that wasn't actually
needed in the first place, since the system is not going to spam
you with tons of notifications.

Also propagate the "critical" flag all the way from the system
to the pressure handler. Note that we don't actually do anything
differently based on the flag yet.

Reviewed by Sam Weinig.

* platform/MemoryPressureHandler.cpp:
(WebCore::MemoryPressureHandler::respondToMemoryPressure):
* platform/MemoryPressureHandler.h:
(WebCore::MemoryPressureHandler::setUnderMemoryPressure):
* platform/cocoa/MemoryPressureHandlerCocoa.mm:
(WebCore::MemoryPressureHandler::install):
(WebCore::MemoryPressureHandler::respondToMemoryPressure):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@169746 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/MemoryPressureHandler.cpp
Source/WebCore/platform/MemoryPressureHandler.h
Source/WebCore/platform/cocoa/MemoryPressureHandlerCocoa.mm

index 27610c7..929894a 100644 (file)
@@ -1,3 +1,31 @@
+2014-06-10  Andreas Kling  <akling@apple.com>
+
+        [iOS WebKit2] Stay in "memory pressure" mode until told otherwise.
+        <https://webkit.org/b/133671>
+
+        When we receive the first memory pressure signal, flip the flag in
+        MemoryPressureHandler so that isUnderMemoryPressure() returns true
+        from then on, until the system tells us pressure levels are back
+        to normal.
+
+        The hold-off mechanism is disabled for iOS, that wasn't actually
+        needed in the first place, since the system is not going to spam
+        you with tons of notifications.
+
+        Also propagate the "critical" flag all the way from the system
+        to the pressure handler. Note that we don't actually do anything
+        differently based on the flag yet.
+
+        Reviewed by Sam Weinig.
+
+        * platform/MemoryPressureHandler.cpp:
+        (WebCore::MemoryPressureHandler::respondToMemoryPressure):
+        * platform/MemoryPressureHandler.h:
+        (WebCore::MemoryPressureHandler::setUnderMemoryPressure):
+        * platform/cocoa/MemoryPressureHandlerCocoa.mm:
+        (WebCore::MemoryPressureHandler::install):
+        (WebCore::MemoryPressureHandler::respondToMemoryPressure):
+
 2014-06-10  Simon Fraser  <simon.fraser@apple.com>
 
         Fix logging of sticky scrolling tree nodes
index 71d3f27..d5202db 100644 (file)
@@ -137,7 +137,7 @@ void MemoryPressureHandler::releaseMemory(bool critical)
 void MemoryPressureHandler::install() { }
 void MemoryPressureHandler::uninstall() { }
 void MemoryPressureHandler::holdOff(unsigned) { }
-void MemoryPressureHandler::respondToMemoryPressure() { }
+void MemoryPressureHandler::respondToMemoryPressure(bool) { }
 void MemoryPressureHandler::platformReleaseMemory(bool) { }
 void MemoryPressureHandler::ReliefLogger::platformLog() { }
 size_t MemoryPressureHandler::ReliefLogger::platformMemoryUsage() { return 0; }
index 4f92cbd..83c812f 100644 (file)
@@ -60,6 +60,7 @@ public:
     }
 
     bool isUnderMemoryPressure() const { return m_underMemoryPressure; }
+    void setUnderMemoryPressure(bool b) { m_underMemoryPressure = b; }
 
 #if PLATFORM(IOS)
     // FIXME: Can we share more of this with OpenSource?
@@ -107,7 +108,7 @@ private:
     MemoryPressureHandler();
     ~MemoryPressureHandler();
 
-    void respondToMemoryPressure();
+    void respondToMemoryPressure(bool critical);
     static void platformReleaseMemory(bool critical);
 
     bool m_installed;
index 91c1af0..58cf10b 100644 (file)
@@ -79,7 +79,7 @@ void MemoryPressureHandler::install()
 
     dispatch_async(dispatch_get_main_queue(), ^{
 #if PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 80000
-        _cache_event_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_MEMORYSTATUS, 0, DISPATCH_MEMORYSTATUS_PRESSURE_WARN | DISPATCH_MEMORYSTATUS_PRESSURE_CRITICAL, dispatch_get_main_queue());
+        _cache_event_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_MEMORYSTATUS, 0, DISPATCH_MEMORYSTATUS_PRESSURE_NORMAL | DISPATCH_MEMORYSTATUS_PRESSURE_WARN | DISPATCH_MEMORYSTATUS_PRESSURE_CRITICAL, dispatch_get_main_queue());
 #elif PLATFORM(MAC) && MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
         _cache_event_source = wkCreateMemoryStatusPressureCriticalDispatchOnMainQueue();
 #else
@@ -88,7 +88,17 @@ void MemoryPressureHandler::install()
         if (_cache_event_source) {
             dispatch_set_context(_cache_event_source, this);
             dispatch_source_set_event_handler(_cache_event_source, ^{
-                memoryPressureHandler().respondToMemoryPressure();
+                bool critical = true;
+#if PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 80000
+                unsigned long status = dispatch_source_get_data(_cache_event_source);
+                critical = status == DISPATCH_MEMORYPRESSURE_CRITICAL;
+                if (status == DISPATCH_MEMORYSTATUS_PRESSURE_NORMAL) {
+                    memoryPressureHandler().setUnderMemoryPressure(false);
+                    return;
+                }
+                memoryPressureHandler().setUnderMemoryPressure(true);
+#endif
+                memoryPressureHandler().respondToMemoryPressure(critical);
             });
             dispatch_resume(_cache_event_source);
         }
@@ -101,7 +111,7 @@ void MemoryPressureHandler::install()
         // This gives us a more consistent picture of live objects at the end of testing.
         gcController().garbageCollectNow();
 
-        memoryPressureHandler().respondToMemoryPressure();
+        memoryPressureHandler().respondToMemoryPressure(true);
         malloc_zone_pressure_relief(nullptr, 0);
     });
 
@@ -152,17 +162,18 @@ void MemoryPressureHandler::holdOff(unsigned seconds)
     });
 }
 
-void MemoryPressureHandler::respondToMemoryPressure()
+void MemoryPressureHandler::respondToMemoryPressure(bool critical)
 {
     uninstall();
 
     double startTime = monotonicallyIncreasingTime();
 
-    m_lowMemoryHandler(false);
+    m_lowMemoryHandler(critical);
 
+#if !PLATFORM(IOS)
     unsigned holdOffTime = (monotonicallyIncreasingTime() - startTime) * s_holdOffMultiplier;
-
     holdOff(std::max(holdOffTime, s_minimumHoldOffTime));
+#endif
 }
 
 #if PLATFORM(IOS) || (PLATFORM(MAC) && MAC_OS_X_VERSION_MIN_REQUIRED >= 1090)