Title: [238870] tags/Safari-607.1.16/Source
Revision
238870
Author
alanc...@apple.com
Date
2018-12-04 12:01:00 -0800 (Tue, 04 Dec 2018)

Log Message

Cherry-pick r238867. rdar://problem/46456681

    Regression(r238817) PSON Page Cache API tests are failing
    https://bugs.webkit.org/show_bug.cgi?id=192348

    Reviewed by Alex Christensen.

    Source/WebCore:

    * page/MemoryRelease.cpp:
    (WebCore::releaseCriticalMemory):
    (WebCore::releaseMemory):
    * page/MemoryRelease.h:

    Source/WebKit:

    Before suspending a WebProcess on iOS, we normally fake a memory pressure signal
    so that the suspended process uses as little memory as possible while suspended.
    Among other things, this will clear the page cache. This is an issue in the case
    of process-swap on navigation because we keep suspended web processes around to
    keep Page Cache functional.

    To address the issue, when a WebProcess is about to get suspended, we check if
    the process has any suspended WebPage (WebPage used for PSON PageCache support)
    and we bypass the PageCache clearing if it does.

    Our API tests did not catch this before r238817 because the NavigationState's
    assertion was preventing the old WebProcesses from suspending for 3 seconds,
    which was enough for those tests to complete.

    * UIProcess/SuspendedPageProxy.cpp:
    (WebKit::SuspendedPageProxy::SuspendedPageProxy):
    (WebKit::SuspendedPageProxy::didFinishLoad):
    * UIProcess/SuspendedPageProxy.h:
    Take a background assertion until the suspension load is complete, to make sure
    the suspension load has a chance to complete before the process gets suspended.

    * WebProcess/WebProcess.cpp:
    (WebKit::WebProcess::initializeWebProcess):
    (WebKit::WebProcess::hasPageRequiringPageCacheWhileSuspended const):
    (WebKit::WebProcess::actualPrepareToSuspend):
    * WebProcess/WebProcess.h:

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

Modified Paths

Diff

Modified: tags/Safari-607.1.16/Source/WebCore/ChangeLog (238869 => 238870)


--- tags/Safari-607.1.16/Source/WebCore/ChangeLog	2018-12-04 20:00:55 UTC (rev 238869)
+++ tags/Safari-607.1.16/Source/WebCore/ChangeLog	2018-12-04 20:01:00 UTC (rev 238870)
@@ -1,3 +1,62 @@
+2018-12-04  Alan Coon  <alanc...@apple.com>
+
+        Cherry-pick r238867. rdar://problem/46456681
+
+    Regression(r238817) PSON Page Cache API tests are failing
+    https://bugs.webkit.org/show_bug.cgi?id=192348
+    
+    Reviewed by Alex Christensen.
+    
+    Source/WebCore:
+    
+    * page/MemoryRelease.cpp:
+    (WebCore::releaseCriticalMemory):
+    (WebCore::releaseMemory):
+    * page/MemoryRelease.h:
+    
+    Source/WebKit:
+    
+    Before suspending a WebProcess on iOS, we normally fake a memory pressure signal
+    so that the suspended process uses as little memory as possible while suspended.
+    Among other things, this will clear the page cache. This is an issue in the case
+    of process-swap on navigation because we keep suspended web processes around to
+    keep Page Cache functional.
+    
+    To address the issue, when a WebProcess is about to get suspended, we check if
+    the process has any suspended WebPage (WebPage used for PSON PageCache support)
+    and we bypass the PageCache clearing if it does.
+    
+    Our API tests did not catch this before r238817 because the NavigationState's
+    assertion was preventing the old WebProcesses from suspending for 3 seconds,
+    which was enough for those tests to complete.
+    
+    * UIProcess/SuspendedPageProxy.cpp:
+    (WebKit::SuspendedPageProxy::SuspendedPageProxy):
+    (WebKit::SuspendedPageProxy::didFinishLoad):
+    * UIProcess/SuspendedPageProxy.h:
+    Take a background assertion until the suspension load is complete, to make sure
+    the suspension load has a chance to complete before the process gets suspended.
+    
+    * WebProcess/WebProcess.cpp:
+    (WebKit::WebProcess::initializeWebProcess):
+    (WebKit::WebProcess::hasPageRequiringPageCacheWhileSuspended const):
+    (WebKit::WebProcess::actualPrepareToSuspend):
+    * WebProcess/WebProcess.h:
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@238867 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2018-12-04  Chris Dumez  <cdu...@apple.com>
+
+            Regression(r238817) PSON Page Cache API tests are failing
+            https://bugs.webkit.org/show_bug.cgi?id=192348
+
+            Reviewed by Alex Christensen.
+
+            * page/MemoryRelease.cpp:
+            (WebCore::releaseCriticalMemory):
+            (WebCore::releaseMemory):
+            * page/MemoryRelease.h:
+
 2018-12-03  Alan Coon  <alanc...@apple.com>
 
         Cherry-pick r238815. rdar://problem/46383932

Modified: tags/Safari-607.1.16/Source/WebCore/page/MemoryRelease.cpp (238869 => 238870)


--- tags/Safari-607.1.16/Source/WebCore/page/MemoryRelease.cpp	2018-12-04 20:00:55 UTC (rev 238869)
+++ tags/Safari-607.1.16/Source/WebCore/page/MemoryRelease.cpp	2018-12-04 20:01:00 UTC (rev 238870)
@@ -75,11 +75,13 @@
     InlineStyleSheetOwner::clearCache();
 }
 
-static void releaseCriticalMemory(Synchronous synchronous)
+static void releaseCriticalMemory(Synchronous synchronous, MaintainPageCache maintainPageCache)
 {
     // Right now, the only reason we call release critical memory while not under memory pressure is if the process is about to be suspended.
-    PruningReason pruningReason = MemoryPressureHandler::singleton().isUnderMemoryPressure() ? PruningReason::MemoryPressure : PruningReason::ProcessSuspended;
-    PageCache::singleton().pruneToSizeNow(0, pruningReason);
+    if (maintainPageCache == MaintainPageCache::No) {
+        PruningReason pruningReason = MemoryPressureHandler::singleton().isUnderMemoryPressure() ? PruningReason::MemoryPressure : PruningReason::ProcessSuspended;
+        PageCache::singleton().pruneToSizeNow(0, pruningReason);
+    }
 
     MemoryCache::singleton().pruneLiveResourcesToSize(0, /*shouldDestroyDecodedDataForAllLiveResources*/ true);
 
@@ -111,7 +113,7 @@
     }
 }
 
-void releaseMemory(Critical critical, Synchronous synchronous)
+void releaseMemory(Critical critical, Synchronous synchronous, MaintainPageCache maintainPageCache)
 {
     TraceScope scope(MemoryPressureHandlerStart, MemoryPressureHandlerEnd, static_cast<uint64_t>(critical), static_cast<uint64_t>(synchronous));
 
@@ -118,7 +120,7 @@
     if (critical == Critical::Yes) {
         // Return unused pages back to the OS now as this will likely give us a little memory to work with.
         WTF::releaseFastMallocFreeMemory();
-        releaseCriticalMemory(synchronous);
+        releaseCriticalMemory(synchronous, maintainPageCache);
     }
 
     releaseNoncriticalMemory();

Modified: tags/Safari-607.1.16/Source/WebCore/page/MemoryRelease.h (238869 => 238870)


--- tags/Safari-607.1.16/Source/WebCore/page/MemoryRelease.h	2018-12-04 20:00:55 UTC (rev 238869)
+++ tags/Safari-607.1.16/Source/WebCore/page/MemoryRelease.h	2018-12-04 20:01:00 UTC (rev 238870)
@@ -29,7 +29,9 @@
 
 namespace WebCore {
 
-WEBCORE_EXPORT void releaseMemory(Critical, Synchronous);
+enum class MaintainPageCache : bool { No, Yes };
+
+WEBCORE_EXPORT void releaseMemory(Critical, Synchronous, MaintainPageCache = MaintainPageCache::No);
 void platformReleaseMemory(Critical);
 void jettisonExpensiveObjectsOnTopLevelNavigation();
 WEBCORE_EXPORT void registerMemoryReleaseNotifyCallbacks();

Modified: tags/Safari-607.1.16/Source/WebKit/ChangeLog (238869 => 238870)


--- tags/Safari-607.1.16/Source/WebKit/ChangeLog	2018-12-04 20:00:55 UTC (rev 238869)
+++ tags/Safari-607.1.16/Source/WebKit/ChangeLog	2018-12-04 20:01:00 UTC (rev 238870)
@@ -1,5 +1,86 @@
 2018-12-04  Alan Coon  <alanc...@apple.com>
 
+        Cherry-pick r238867. rdar://problem/46456681
+
+    Regression(r238817) PSON Page Cache API tests are failing
+    https://bugs.webkit.org/show_bug.cgi?id=192348
+    
+    Reviewed by Alex Christensen.
+    
+    Source/WebCore:
+    
+    * page/MemoryRelease.cpp:
+    (WebCore::releaseCriticalMemory):
+    (WebCore::releaseMemory):
+    * page/MemoryRelease.h:
+    
+    Source/WebKit:
+    
+    Before suspending a WebProcess on iOS, we normally fake a memory pressure signal
+    so that the suspended process uses as little memory as possible while suspended.
+    Among other things, this will clear the page cache. This is an issue in the case
+    of process-swap on navigation because we keep suspended web processes around to
+    keep Page Cache functional.
+    
+    To address the issue, when a WebProcess is about to get suspended, we check if
+    the process has any suspended WebPage (WebPage used for PSON PageCache support)
+    and we bypass the PageCache clearing if it does.
+    
+    Our API tests did not catch this before r238817 because the NavigationState's
+    assertion was preventing the old WebProcesses from suspending for 3 seconds,
+    which was enough for those tests to complete.
+    
+    * UIProcess/SuspendedPageProxy.cpp:
+    (WebKit::SuspendedPageProxy::SuspendedPageProxy):
+    (WebKit::SuspendedPageProxy::didFinishLoad):
+    * UIProcess/SuspendedPageProxy.h:
+    Take a background assertion until the suspension load is complete, to make sure
+    the suspension load has a chance to complete before the process gets suspended.
+    
+    * WebProcess/WebProcess.cpp:
+    (WebKit::WebProcess::initializeWebProcess):
+    (WebKit::WebProcess::hasPageRequiringPageCacheWhileSuspended const):
+    (WebKit::WebProcess::actualPrepareToSuspend):
+    * WebProcess/WebProcess.h:
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@238867 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2018-12-04  Chris Dumez  <cdu...@apple.com>
+
+            Regression(r238817) PSON Page Cache API tests are failing
+            https://bugs.webkit.org/show_bug.cgi?id=192348
+
+            Reviewed by Alex Christensen.
+
+            Before suspending a WebProcess on iOS, we normally fake a memory pressure signal
+            so that the suspended process uses as little memory as possible while suspended.
+            Among other things, this will clear the page cache. This is an issue in the case
+            of process-swap on navigation because we keep suspended web processes around to
+            keep Page Cache functional.
+
+            To address the issue, when a WebProcess is about to get suspended, we check if
+            the process has any suspended WebPage (WebPage used for PSON PageCache support)
+            and we bypass the PageCache clearing if it does.
+
+            Our API tests did not catch this before r238817 because the NavigationState's
+            assertion was preventing the old WebProcesses from suspending for 3 seconds,
+            which was enough for those tests to complete.
+
+            * UIProcess/SuspendedPageProxy.cpp:
+            (WebKit::SuspendedPageProxy::SuspendedPageProxy):
+            (WebKit::SuspendedPageProxy::didFinishLoad):
+            * UIProcess/SuspendedPageProxy.h:
+            Take a background assertion until the suspension load is complete, to make sure
+            the suspension load has a chance to complete before the process gets suspended.
+
+            * WebProcess/WebProcess.cpp:
+            (WebKit::WebProcess::initializeWebProcess):
+            (WebKit::WebProcess::hasPageRequiringPageCacheWhileSuspended const):
+            (WebKit::WebProcess::actualPrepareToSuspend):
+            * WebProcess/WebProcess.h:
+
+2018-12-04  Alan Coon  <alanc...@apple.com>
+
         Cherry-pick r238818. rdar://problem/45928708
 
     Swipe snapshot stays up too long swiping around on apple.com (waiting for first paint)

Modified: tags/Safari-607.1.16/Source/WebKit/UIProcess/SuspendedPageProxy.cpp (238869 => 238870)


--- tags/Safari-607.1.16/Source/WebKit/UIProcess/SuspendedPageProxy.cpp	2018-12-04 20:00:55 UTC (rev 238869)
+++ tags/Safari-607.1.16/Source/WebKit/UIProcess/SuspendedPageProxy.cpp	2018-12-04 20:01:00 UTC (rev 238870)
@@ -79,6 +79,9 @@
     , m_process(WTFMove(process))
     , m_mainFrameID(mainFrameID)
     , m_registrableDomain(toRegistrableDomain(URL(URL(), item.url())))
+#if PLATFORM(IOS_FAMILY)
+    , m_suspensionToken(m_process->throttler().backgroundActivityToken())
+#endif
 {
     item.setSuspendedPage(this);
     m_process->addMessageReceiver(Messages::WebPageProxy::messageReceiverName(), m_page.pageID(), *this);
@@ -129,6 +132,10 @@
 
     m_process->send(Messages::WebProcess::UpdateActivePages(), 0);
 
+#if PLATFORM(IOS_FAMILY)
+    m_suspensionToken = nullptr;
+#endif
+
     if (auto finishedSuspendingHandler = WTFMove(m_finishedSuspendingHandler))
         finishedSuspendingHandler();
 }

Modified: tags/Safari-607.1.16/Source/WebKit/UIProcess/SuspendedPageProxy.h (238869 => 238870)


--- tags/Safari-607.1.16/Source/WebKit/UIProcess/SuspendedPageProxy.h	2018-12-04 20:00:55 UTC (rev 238869)
+++ tags/Safari-607.1.16/Source/WebKit/UIProcess/SuspendedPageProxy.h	2018-12-04 20:01:00 UTC (rev 238870)
@@ -26,6 +26,7 @@
 #pragma once
 
 #include "Connection.h"
+#include "ProcessThrottler.h"
 #include "WebBackForwardListItem.h"
 #include <WebCore/SecurityOriginData.h>
 #include <wtf/RefCounted.h>
@@ -68,6 +69,9 @@
 
     bool m_finishedSuspending { false };
     CompletionHandler<void()> m_finishedSuspendingHandler;
+#if PLATFORM(IOS_FAMILY)
+    ProcessThrottler::BackgroundActivityToken m_suspensionToken;
+#endif
 };
 
 } // namespace WebKit

Modified: tags/Safari-607.1.16/Source/WebKit/WebProcess/WebProcess.cpp (238869 => 238870)


--- tags/Safari-607.1.16/Source/WebKit/WebProcess/WebProcess.cpp	2018-12-04 20:00:55 UTC (rev 238869)
+++ tags/Safari-607.1.16/Source/WebKit/WebProcess/WebProcess.cpp	2018-12-04 20:01:00 UTC (rev 238870)
@@ -280,8 +280,9 @@
     m_suppressMemoryPressureHandler = parameters.shouldSuppressMemoryPressureHandler;
     if (!m_suppressMemoryPressureHandler) {
         auto& memoryPressureHandler = MemoryPressureHandler::singleton();
-        memoryPressureHandler.setLowMemoryHandler([] (Critical critical, Synchronous synchronous) {
-            WebCore::releaseMemory(critical, synchronous);
+        memoryPressureHandler.setLowMemoryHandler([this] (Critical critical, Synchronous synchronous) {
+            auto maintainPageCache = m_isSuspending && hasPageRequiringPageCacheWhileSuspended() ? WebCore::MaintainPageCache::Yes : WebCore::MaintainPageCache::No;
+            WebCore::releaseMemory(critical, synchronous, maintainPageCache);
         });
 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101200) || PLATFORM(GTK) || PLATFORM(WPE)
         memoryPressureHandler.setShouldUsePeriodicMemoryMonitor(true);
@@ -429,6 +430,15 @@
     RELEASE_LOG(Process, "%p - WebProcess::initializeWebProcess: Presenting process = %d", this, WebCore::presentingApplicationPID());
 }
 
+bool WebProcess::hasPageRequiringPageCacheWhileSuspended() const
+{
+    for (auto& page : m_pageMap.values()) {
+        if (page->isSuspended())
+            return true;
+    }
+    return false;
+}
+
 void WebProcess::markIsNoLongerPrewarmed()
 {
 #if PLATFORM(MAC)
@@ -1376,6 +1386,8 @@
 
 void WebProcess::actualPrepareToSuspend(ShouldAcknowledgeWhenReadyToSuspend shouldAcknowledgeWhenReadyToSuspend)
 {
+    SetForScope<bool> suspensionScope(m_isSuspending, true);
+
     if (!m_suppressMemoryPressureHandler)
         MemoryPressureHandler::singleton().releaseMemory(Critical::Yes, Synchronous::Yes);
 

Modified: tags/Safari-607.1.16/Source/WebKit/WebProcess/WebProcess.h (238869 => 238870)


--- tags/Safari-607.1.16/Source/WebKit/WebProcess/WebProcess.h	2018-12-04 20:00:55 UTC (rev 238869)
+++ tags/Safari-607.1.16/Source/WebKit/WebProcess/WebProcess.h	2018-12-04 20:01:00 UTC (rev 238870)
@@ -348,6 +348,8 @@
     enum class ShouldAcknowledgeWhenReadyToSuspend { No, Yes };
     void actualPrepareToSuspend(ShouldAcknowledgeWhenReadyToSuspend);
 
+    bool hasPageRequiringPageCacheWhileSuspended() const;
+
     void ensureAutomationSessionProxy(const String& sessionIdentifier);
     void destroyAutomationSessionProxy();
 
@@ -476,6 +478,7 @@
 #if PLATFORM(WAYLAND)
     std::unique_ptr<WaylandCompositorDisplay> m_waylandCompositorDisplay;
 #endif
+    bool m_isSuspending { false };
 };
 
 } // namespace WebKit
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to