Make inactive web processes behave as though under memory pressure.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 5 Apr 2017 22:55:25 +0000 (22:55 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 5 Apr 2017 22:55:25 +0000 (22:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=170042
<rdar://problem/31038445>

Reviewed by Antti Koivisto.

Source/WebCore:

Prevent PerformanceMonitor from marking the process as inactive at startup.
This fixes the API test failure that caused this patch to get rolled out.

* page/PerformanceMonitor.h:

Source/WTF:

Once a web process becomes inactive, let's try to reduce its impact
on memory usage by treating it as if it's under memory pressure until
it becomes active.

* wtf/MemoryPressureHandler.cpp:
(WTF::MemoryPressureHandler::setProcessState):
(WTF::MemoryPressureHandler::isUnderMemoryPressure):
* wtf/MemoryPressureHandler.h:
(WTF::MemoryPressureHandler::isUnderMemoryPressure): Deleted.

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

Source/WTF/ChangeLog
Source/WTF/wtf/MemoryPressureHandler.cpp
Source/WTF/wtf/MemoryPressureHandler.h
Source/WebCore/ChangeLog
Source/WebCore/page/PerformanceMonitor.h

index 14e0936..7f513cc 100644 (file)
@@ -1,3 +1,21 @@
+2017-04-05  Andreas Kling  <akling@apple.com>
+
+        Make inactive web processes behave as though under memory pressure.
+        https://bugs.webkit.org/show_bug.cgi?id=170042
+        <rdar://problem/31038445>
+
+        Reviewed by Antti Koivisto.
+
+        Once a web process becomes inactive, let's try to reduce its impact
+        on memory usage by treating it as if it's under memory pressure until
+        it becomes active.
+
+        * wtf/MemoryPressureHandler.cpp:
+        (WTF::MemoryPressureHandler::setProcessState):
+        (WTF::MemoryPressureHandler::isUnderMemoryPressure):
+        * wtf/MemoryPressureHandler.h:
+        (WTF::MemoryPressureHandler::isUnderMemoryPressure): Deleted.
+
 2017-04-05  Yusuke Suzuki  <utatane.tea@gmail.com>
 
         [JSC] Suppress warnings in GCC
index 4663302..bf9a075 100644 (file)
@@ -171,6 +171,9 @@ void MemoryPressureHandler::setProcessState(WebsamProcessState state)
     if (m_processState == state)
         return;
     m_processState = state;
+    memoryPressureStatusChanged();
+    if (m_processState == WebsamProcessState::Inactive)
+        respondToMemoryPressure(Critical::Yes, Synchronous::No);
 }
 
 void MemoryPressureHandler::beginSimulatedMemoryPressure()
@@ -190,6 +193,17 @@ void MemoryPressureHandler::endSimulatedMemoryPressure()
     memoryPressureStatusChanged();
 }
 
+bool MemoryPressureHandler::isUnderMemoryPressure()
+{
+    auto& memoryPressureHandler = singleton();
+    return memoryPressureHandler.m_underMemoryPressure
+#if PLATFORM(MAC)
+        || memoryPressureHandler.m_memoryUsagePolicy >= MemoryUsagePolicy::Strict
+        || memoryPressureHandler.m_processState == WebsamProcessState::Inactive
+#endif
+        || memoryPressureHandler.m_isSimulatingMemoryPressure;
+}
+
 void MemoryPressureHandler::releaseMemory(Critical critical, Synchronous synchronous)
 {
     if (!m_lowMemoryHandler)
index 44dbc56..61751b1 100644 (file)
@@ -79,14 +79,7 @@ public:
         m_lowMemoryHandler = WTFMove(handler);
     }
 
-    bool isUnderMemoryPressure() const
-    {
-        return m_underMemoryPressure
-#if PLATFORM(MAC)
-            || m_memoryUsagePolicy >= MemoryUsagePolicy::Strict
-#endif
-            || m_isSimulatingMemoryPressure;
-    }
+    WTF_EXPORT_PRIVATE static bool isUnderMemoryPressure();
     void setUnderMemoryPressure(bool);
 
 #if OS(LINUX)
@@ -184,7 +177,7 @@ private:
     };
 #endif
 
-    WebsamProcessState m_processState { WebsamProcessState::Inactive };
+    WebsamProcessState m_processState { WebsamProcessState::Active };
 
     bool m_installed { false };
     LowMemoryHandler m_lowMemoryHandler;
index 065380d..6547f81 100644 (file)
@@ -1,3 +1,16 @@
+2017-04-05  Andreas Kling  <akling@apple.com>
+
+        Make inactive web processes behave as though under memory pressure.
+        https://bugs.webkit.org/show_bug.cgi?id=170042
+        <rdar://problem/31038445>
+
+        Reviewed by Antti Koivisto.
+
+        Prevent PerformanceMonitor from marking the process as inactive at startup.
+        This fixes the API test failure that caused this patch to get rolled out.
+
+        * page/PerformanceMonitor.h:
+
 2017-04-05  Youenn Fablet  <youenn@apple.com>
 
         Switch to kCVPixelFormatType_420YpCbCr8BiPlanarFullRange for Mac video capture format
index c4b4cea..afc2924 100644 (file)
@@ -65,7 +65,7 @@ private:
     Timer m_postBackgroundingMemoryUsageTimer;
 
     Timer m_processMayBecomeInactiveTimer;
-    bool m_processMayBecomeInactive { true };
+    bool m_processMayBecomeInactive { false };
 };
 
 }