Title: [276339] trunk/Source/WebKit
- Revision
- 276339
- Author
- [email protected]
- Date
- 2021-04-20 17:58:51 -0700 (Tue, 20 Apr 2021)
Log Message
If an idle GPUProcess doesn't exit under memory pressure because it just launched, check again later
https://bugs.webkit.org/show_bug.cgi?id=224829
Reviewed by Darin Adler.
In r276305, I made it so that the GPUProcess does not exit under memory pressure when idle
if it launched less than 5 seconds ago. This gives the WebProcess time to schedule work with
the GPUProcess after launching it and makes sure we don't repeatedly / frequently exit &
relaunch the GPUProcess.
In this patch, I am tweaking the policy so that if we could have exited but didn't because
the GPUProcess was too young (less than 5 seconds old), then I schedule a timer for this
5 second deadline to check again if the GPUProcess could exit (meaning that it is unused).
When the timer fires, the process doesn't have to be under memory pressure still in order
to exit, it just needs to be idle. I figured the fact that we were under memory pressure
less than 5 seconds ago should be enough incentive to exit if idle.
* GPUProcess/GPUProcess.cpp:
(WebKit::GPUProcess::GPUProcess):
(WebKit::GPUProcess::canExitUnderMemoryPressure const):
* GPUProcess/GPUProcess.h:
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (276338 => 276339)
--- trunk/Source/WebKit/ChangeLog 2021-04-21 00:48:09 UTC (rev 276338)
+++ trunk/Source/WebKit/ChangeLog 2021-04-21 00:58:51 UTC (rev 276339)
@@ -1,3 +1,27 @@
+2021-04-20 Chris Dumez <[email protected]>
+
+ If an idle GPUProcess doesn't exit under memory pressure because it just launched, check again later
+ https://bugs.webkit.org/show_bug.cgi?id=224829
+
+ Reviewed by Darin Adler.
+
+ In r276305, I made it so that the GPUProcess does not exit under memory pressure when idle
+ if it launched less than 5 seconds ago. This gives the WebProcess time to schedule work with
+ the GPUProcess after launching it and makes sure we don't repeatedly / frequently exit &
+ relaunch the GPUProcess.
+
+ In this patch, I am tweaking the policy so that if we could have exited but didn't because
+ the GPUProcess was too young (less than 5 seconds old), then I schedule a timer for this
+ 5 second deadline to check again if the GPUProcess could exit (meaning that it is unused).
+ When the timer fires, the process doesn't have to be under memory pressure still in order
+ to exit, it just needs to be idle. I figured the fact that we were under memory pressure
+ less than 5 seconds ago should be enough incentive to exit if idle.
+
+ * GPUProcess/GPUProcess.cpp:
+ (WebKit::GPUProcess::GPUProcess):
+ (WebKit::GPUProcess::canExitUnderMemoryPressure const):
+ * GPUProcess/GPUProcess.h:
+
2021-04-20 Devin Rousso <[email protected]>
Parse `theme_color` in web application manifests and pass it along to `-[WKWebView themeColor]`
Modified: trunk/Source/WebKit/GPUProcess/GPUProcess.cpp (276338 => 276339)
--- trunk/Source/WebKit/GPUProcess/GPUProcess.cpp 2021-04-21 00:48:09 UTC (rev 276338)
+++ trunk/Source/WebKit/GPUProcess/GPUProcess.cpp 2021-04-21 00:58:51 UTC (rev 276339)
@@ -74,8 +74,14 @@
namespace WebKit {
using namespace WebCore;
+// We wouldn't want the GPUProcess to repeatedly exit then relaunch when under memory pressure. In particular, we need to make sure the
+// WebProcess has a change to schedule work after the GPUProcess get launched. For this reason, we make sure that the GPUProcess never
+// idle-exits less than 5 seconds after getting launched. This amount of time should be sufficient for the WebProcess to schedule work
+// work in the GPUProcess.
+constexpr Seconds minimumLifetimeBeforeIdleExit { 5_s };
GPUProcess::GPUProcess(AuxiliaryProcessInitializationParameters&& parameters)
+ : m_idleExitTimer(*this, &GPUProcess::tryExitIfUnused)
{
initialize(WTFMove(parameters));
RELEASE_LOG(Process, "%p - GPUProcess::GPUProcess:", this);
@@ -129,12 +135,6 @@
bool GPUProcess::canExitUnderMemoryPressure() const
{
ASSERT(isMainRunLoop());
- // To avoid exiting the GPUProcess too aggressively while under memory pressure, we don't exit if we've been running
- // for less than 5 seconds. In case of simulated memory pressure, we ignore this rule to avoid generating flakiness
- // in our benchmarks and tests.
- if ((MonotonicTime::now() - m_creationTime) < 5_s && !MemoryPressureHandler::singleton().isSimulatingMemoryPressure())
- return false;
-
for (auto& webProcessConnection : m_webProcessConnections.values()) {
if (!webProcessConnection->allowsExitUnderMemoryPressure())
return false;
@@ -154,9 +154,25 @@
void GPUProcess::tryExitIfUnused()
{
ASSERT(isMainRunLoop());
- if (!canExitUnderMemoryPressure())
+ if (!canExitUnderMemoryPressure()) {
+ m_idleExitTimer.stop();
return;
+ }
+ // To avoid exiting the GPUProcess too aggressively while under memory pressure and make sure the WebProcess gets a
+ // change to schedule work, we don't exit if we've been running for less than |minimumLifetimeBeforeIdleExit|.
+ // In case of simulated memory pressure, we ignore this rule to avoid flakiness in our benchmarks and tests.
+ auto lifetime = MonotonicTime::now() - m_creationTime;
+ if (lifetime < minimumLifetimeBeforeIdleExit && !MemoryPressureHandler::singleton().isSimulatingMemoryPressure()) {
+ RELEASE_LOG(Process, "GPUProcess::tryExitIfUnused: GPUProcess is idle and under memory pressure but it is not exiting because it has just launched");
+ // Check again after the process have lived long enough (minimumLifetimeBeforeIdleExit) to see if the GPUProcess
+ // can idle-exit then.
+ if (!m_idleExitTimer.isActive())
+ m_idleExitTimer.startOneShot(minimumLifetimeBeforeIdleExit - lifetime);
+ return;
+ }
+ m_idleExitTimer.stop();
+
RELEASE_LOG(Process, "GPUProcess::tryExitIfUnused: GPUProcess is exiting because we are under memory pressure and the process is no longer useful.");
parentProcessConnection()->send(Messages::GPUProcessProxy::ProcessIsReadyToExit(), 0);
}
Modified: trunk/Source/WebKit/GPUProcess/GPUProcess.h (276338 => 276339)
--- trunk/Source/WebKit/GPUProcess/GPUProcess.h 2021-04-21 00:48:09 UTC (rev 276338)
+++ trunk/Source/WebKit/GPUProcess/GPUProcess.h 2021-04-21 00:58:51 UTC (rev 276339)
@@ -30,6 +30,7 @@
#include "AuxiliaryProcess.h"
#include "WebPageProxyIdentifier.h"
#include <WebCore/LibWebRTCEnumTraits.h>
+#include <WebCore/Timer.h>
#include <pal/SessionID.h>
#include <wtf/Function.h>
#include <wtf/MemoryPressureHandler.h>
@@ -176,6 +177,7 @@
#endif
};
HashMap<PAL::SessionID, GPUSession> m_sessions;
+ WebCore::Timer m_idleExitTimer;
std::unique_ptr<WebCore::NowPlayingManager> m_nowPlayingManager;
#if ENABLE(GPU_PROCESS) && USE(AUDIO_SESSION)
mutable std::unique_ptr<RemoteAudioSessionProxyManager> m_audioSessionManager;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes