Title: [279155] trunk/Source/WebKit
Revision
279155
Author
[email protected]
Date
2021-06-22 16:48:33 -0700 (Tue, 22 Jun 2021)

Log Message

[macOS] Suspend WebProcesses that are in the process cache
https://bugs.webkit.org/show_bug.cgi?id=227269

Reviewed by Geoffrey Garen.

Suspend WebProcesses that are in the process cache on macOS to make sure they use no CPU.

* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::setIsInProcessCache):
(WebKit::WebProcessProxy::platformSuspendProcess):
(WebKit::WebProcessProxy::platformResumeProcess):
* UIProcess/WebProcessProxy.h:
* UIProcess/mac/WebProcessProxyMac.mm:
(WebKit::WebProcessProxy::platformSuspendProcess):
(WebKit::WebProcessProxy::platformResumeProcess):
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::setIsInProcessCache):
* WebProcess/WebProcess.h:
* WebProcess/WebProcess.messages.in:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (279154 => 279155)


--- trunk/Source/WebKit/ChangeLog	2021-06-22 22:06:54 UTC (rev 279154)
+++ trunk/Source/WebKit/ChangeLog	2021-06-22 23:48:33 UTC (rev 279155)
@@ -1,3 +1,25 @@
+2021-06-22  Chris Dumez  <[email protected]>
+
+        [macOS] Suspend WebProcesses that are in the process cache
+        https://bugs.webkit.org/show_bug.cgi?id=227269
+
+        Reviewed by Geoffrey Garen.
+
+        Suspend WebProcesses that are in the process cache on macOS to make sure they use no CPU.
+
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::setIsInProcessCache):
+        (WebKit::WebProcessProxy::platformSuspendProcess):
+        (WebKit::WebProcessProxy::platformResumeProcess):
+        * UIProcess/WebProcessProxy.h:
+        * UIProcess/mac/WebProcessProxyMac.mm:
+        (WebKit::WebProcessProxy::platformSuspendProcess):
+        (WebKit::WebProcessProxy::platformResumeProcess):
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::setIsInProcessCache):
+        * WebProcess/WebProcess.h:
+        * WebProcess/WebProcess.messages.in:
+
 2021-06-22  Jer Noble  <[email protected]>
 
         Further unreviewed build fix after r279133: remove even more things.

Modified: trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp (279154 => 279155)


--- trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp	2021-06-22 22:06:54 UTC (rev 279154)
+++ trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp	2021-06-22 23:48:33 UTC (rev 279155)
@@ -283,8 +283,14 @@
     ASSERT(m_isInProcessCache != value);
     m_isInProcessCache = value;
 
-    send(Messages::WebProcess::SetIsInProcessCache(m_isInProcessCache), 0);
+    if (!m_isInProcessCache)
+        platformResumeProcess();
 
+    sendWithAsyncReply(Messages::WebProcess::SetIsInProcessCache(m_isInProcessCache), [weakThis = makeWeakPtr(*this), isEnteringProcessCache = value]() mutable {
+        if (isEnteringProcessCache && weakThis && weakThis->m_isInProcessCache)
+            weakThis->platformSuspendProcess();
+    });
+
     if (m_isInProcessCache) {
         // WebProcessProxy objects normally keep the process pool alive but we do not want this to be the case
         // for cached processes or it would leak the pool.
@@ -1954,6 +1960,16 @@
     PAL::systemBeep();
 }
 
+#if !PLATFORM(MAC)
+void WebProcessProxy::platformSuspendProcess()
+{
+}
+
+void WebProcessProxy::platformResumeProcess()
+{
+}
+#endif
+
 } // namespace WebKit
 
 #undef MESSAGE_CHECK

Modified: trunk/Source/WebKit/UIProcess/WebProcessProxy.h (279154 => 279155)


--- trunk/Source/WebKit/UIProcess/WebProcessProxy.h	2021-06-22 22:06:54 UTC (rev 279154)
+++ trunk/Source/WebKit/UIProcess/WebProcessProxy.h	2021-06-22 23:48:33 UTC (rev 279155)
@@ -471,6 +471,9 @@
 
     void processDidTerminateOrFailedToLaunch(ProcessTerminationReason);
 
+    void platformSuspendProcess();
+    void platformResumeProcess();
+
     // IPC::Connection::Client
     friend class WebConnectionToWebProcess;
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;

Modified: trunk/Source/WebKit/UIProcess/mac/WebProcessProxyMac.mm (279154 => 279155)


--- trunk/Source/WebKit/UIProcess/mac/WebProcessProxyMac.mm	2021-06-22 22:06:54 UTC (rev 279154)
+++ trunk/Source/WebKit/UIProcess/mac/WebProcessProxyMac.mm	2021-06-22 23:48:33 UTC (rev 279155)
@@ -31,6 +31,7 @@
 
 #import "WKFullKeyboardAccessWatcher.h"
 #import <Kernel/kern/cs_blobs.h>
+#import <signal.h>
 #import <wtf/ProcessPrivilege.h>
 #import <wtf/spi/cocoa/SecuritySPI.h>
 
@@ -78,6 +79,24 @@
     processPool().setDisplayLinkPreferredFramesPerSecond(*connection(), observerID, displayID, preferredFramesPerSecond);
 }
 
+void WebProcessProxy::platformSuspendProcess()
+{
+    RELEASE_LOG(Process, "%p - [PID=%i] WebProcessProxy::platformSuspendProcess", this, processIdentifier());
+    ALLOW_DEPRECATED_DECLARATIONS_BEGIN
+    if (auto* connection = this->connection())
+        xpc_connection_kill(connection->xpcConnection(), SIGSTOP);
+    ALLOW_DEPRECATED_DECLARATIONS_END
+}
+
+void WebProcessProxy::platformResumeProcess()
+{
+    RELEASE_LOG(Process, "%p - [PID=%i] WebProcessProxy::platformResumeProcess", this, processIdentifier());
+    ALLOW_DEPRECATED_DECLARATIONS_BEGIN
+    if (auto* connection = this->connection())
+        xpc_connection_kill(connection->xpcConnection(), SIGCONT);
+    ALLOW_DEPRECATED_DECLARATIONS_END
+}
+
 } // namespace WebKit
 
 #endif // PLATFORM(MAC)

Modified: trunk/Source/WebKit/WebProcess/WebProcess.cpp (279154 => 279155)


--- trunk/Source/WebKit/WebProcess/WebProcess.cpp	2021-06-22 22:06:54 UTC (rev 279154)
+++ trunk/Source/WebKit/WebProcess/WebProcess.cpp	2021-06-22 23:48:33 UTC (rev 279155)
@@ -605,7 +605,7 @@
     m_hasSuspendedPageProxy = hasSuspendedPageProxy;
 }
 
-void WebProcess::setIsInProcessCache(bool isInProcessCache)
+void WebProcess::setIsInProcessCache(bool isInProcessCache, CompletionHandler<void()>&& completionHandler)
 {
 #if PLATFORM(COCOA)
     if (isInProcessCache) {
@@ -620,6 +620,8 @@
 #else
     UNUSED_PARAM(isInProcessCache);
 #endif
+
+    completionHandler();
 }
 
 void WebProcess::markIsNoLongerPrewarmed()

Modified: trunk/Source/WebKit/WebProcess/WebProcess.h (279154 => 279155)


--- trunk/Source/WebKit/WebProcess/WebProcess.h	2021-06-22 22:06:54 UTC (rev 279154)
+++ trunk/Source/WebKit/WebProcess/WebProcess.h	2021-06-22 23:48:33 UTC (rev 279155)
@@ -420,7 +420,7 @@
     void platformTerminate();
 
     void setHasSuspendedPageProxy(bool);
-    void setIsInProcessCache(bool);
+    void setIsInProcessCache(bool, CompletionHandler<void()>&&);
     void markIsNoLongerPrewarmed();
 
     void registerURLSchemeAsEmptyDocument(const String&);

Modified: trunk/Source/WebKit/WebProcess/WebProcess.messages.in (279154 => 279155)


--- trunk/Source/WebKit/WebProcess/WebProcess.messages.in	2021-06-22 22:06:54 UTC (rev 279154)
+++ trunk/Source/WebKit/WebProcess/WebProcess.messages.in	2021-06-22 23:48:33 UTC (rev 279155)
@@ -105,7 +105,7 @@
 #endif
 
     SetHasSuspendedPageProxy(bool hasSuspendedPageProxy);
-    SetIsInProcessCache(bool isInProcessCache)
+    SetIsInProcessCache(bool isInProcessCache) -> () Async
     MarkIsNoLongerPrewarmed()
     GetActivePagesOriginsForTesting() -> (Vector<String> activeOrigins) Async
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to