Title: [179287] branches/safari-600.1.4.15-branch/Source

Diff

Modified: branches/safari-600.1.4.15-branch/Source/WebCore/ChangeLog (179286 => 179287)


--- branches/safari-600.1.4.15-branch/Source/WebCore/ChangeLog	2015-01-28 21:45:00 UTC (rev 179286)
+++ branches/safari-600.1.4.15-branch/Source/WebCore/ChangeLog	2015-01-28 21:49:34 UTC (rev 179287)
@@ -1,5 +1,42 @@
 2015-01-28  Lucas Forschler  <lforsch...@apple.com>
 
+        Merge r177738
+
+    2014-12-25  Chris Dumez  <cdu...@apple.com>
+
+            [iOS] Log better using FeatureCounter why PageCache is failing due to pruned resources
+            https://bugs.webkit.org/show_bug.cgi?id=139921
+
+            Reviewed by Gavin Barraclough and Alexey Proskuryakov.
+
+            Log better using FeatureCounter why PageCache is failing due to pruned
+            resources. In particular, we now distinguish if the resource was pruned
+            due to:
+            - Memory pressure
+            - Page cache capacity reached
+            - WebProcess suspended (WK2)
+
+            * WebCore.exp.in:
+            * history/HistoryItem.cpp:
+            (WebCore::HistoryItem::HistoryItem):
+            * history/HistoryItem.h:
+            * history/PageCache.cpp:
+            (WebCore::PageCache::pruneToCapacityNow):
+            (WebCore::PageCache::setCapacity):
+            (WebCore::pruningReasonToFeatureCounterKey):
+            (WebCore::PageCache::add):
+            (WebCore::PageCache::take):
+            (WebCore::PageCache::get):
+            (WebCore::PageCache::prune):
+            * history/PageCache.h:
+            * loader/FrameLoader.cpp:
+            (WebCore::FrameLoader::commitProvisionalLoad):
+            * platform/FeatureCounterKeys.h:
+            * platform/MemoryPressureHandler.cpp:
+            (WebCore::MemoryPressureHandler::releaseCriticalMemory):
+
+2015-01-28  Lucas Forschler  <lforsch...@apple.com>
+
         Merge r177681
 
     2014-12-22  Chris Dumez  <cdu...@apple.com>

Modified: branches/safari-600.1.4.15-branch/Source/WebCore/WebCore.exp.in (179286 => 179287)


--- branches/safari-600.1.4.15-branch/Source/WebCore/WebCore.exp.in	2015-01-28 21:45:00 UTC (rev 179286)
+++ branches/safari-600.1.4.15-branch/Source/WebCore/WebCore.exp.in	2015-01-28 21:49:34 UTC (rev 179287)
@@ -1495,6 +1495,7 @@
 __ZN7WebCore9LayerPoolC1Ev
 __ZN7WebCore9LayerPoolD1Ev
 __ZN7WebCore9PageCache11setCapacityEi
+__ZN7WebCore9PageCache18pruneToCapacityNowEiNS_13PruningReasonE
 __ZN7WebCore9PageCache33markPagesForVistedLinkStyleRecalcEv
 __ZN7WebCore9PageCache6removeEPNS_11HistoryItemE
 __ZN7WebCore9PageGroup13isLinkVisitedEy

Modified: branches/safari-600.1.4.15-branch/Source/WebCore/history/HistoryItem.cpp (179286 => 179287)


--- branches/safari-600.1.4.15-branch/Source/WebCore/history/HistoryItem.cpp	2015-01-28 21:45:00 UTC (rev 179286)
+++ branches/safari-600.1.4.15-branch/Source/WebCore/history/HistoryItem.cpp	2015-01-28 21:49:34 UTC (rev 179287)
@@ -61,9 +61,9 @@
     , m_isTargetItem(false)
     , m_itemSequenceNumber(generateSequenceNumber())
     , m_documentSequenceNumber(generateSequenceNumber())
-    , m_next(0)
-    , m_prev(0)
-    , m_wasPruned(false)
+    , m_next(nullptr)
+    , m_prev(nullptr)
+    , m_pruningReason(PruningReason::None)
 #if PLATFORM(IOS)
     , m_scale(0)
     , m_scaleIsInitial(false)
@@ -81,9 +81,9 @@
     , m_isTargetItem(false)
     , m_itemSequenceNumber(generateSequenceNumber())
     , m_documentSequenceNumber(generateSequenceNumber())
-    , m_next(0)
-    , m_prev(0)
-    , m_wasPruned(false)
+    , m_next(nullptr)
+    , m_prev(nullptr)
+    , m_pruningReason(PruningReason::None)
 #if PLATFORM(IOS)
     , m_scale(0)
     , m_scaleIsInitial(false)
@@ -103,9 +103,9 @@
     , m_isTargetItem(false)
     , m_itemSequenceNumber(generateSequenceNumber())
     , m_documentSequenceNumber(generateSequenceNumber())
-    , m_next(0)
-    , m_prev(0)
-    , m_wasPruned(false)
+    , m_next(nullptr)
+    , m_prev(nullptr)
+    , m_pruningReason(PruningReason::None)
 #if PLATFORM(IOS)
     , m_scale(0)
     , m_scaleIsInitial(false)
@@ -126,9 +126,9 @@
     , m_isTargetItem(false)
     , m_itemSequenceNumber(generateSequenceNumber())
     , m_documentSequenceNumber(generateSequenceNumber())
-    , m_next(0)
-    , m_prev(0)
-    , m_wasPruned(false)
+    , m_next(nullptr)
+    , m_prev(nullptr)
+    , m_pruningReason(PruningReason::None)
 #if PLATFORM(IOS)
     , m_scale(0)
     , m_scaleIsInitial(false)
@@ -160,6 +160,9 @@
     , m_itemSequenceNumber(item.m_itemSequenceNumber)
     , m_documentSequenceNumber(item.m_documentSequenceNumber)
     , m_formContentType(item.m_formContentType)
+    , m_next(nullptr)
+    , m_prev(nullptr)
+    , m_pruningReason(PruningReason::None)
 #if PLATFORM(IOS)
     , m_scale(item.m_scale)
     , m_scaleIsInitial(item.m_scaleIsInitial)

Modified: branches/safari-600.1.4.15-branch/Source/WebCore/history/HistoryItem.h (179286 => 179287)


--- branches/safari-600.1.4.15-branch/Source/WebCore/history/HistoryItem.h	2015-01-28 21:45:00 UTC (rev 179286)
+++ branches/safari-600.1.4.15-branch/Source/WebCore/history/HistoryItem.h	2015-01-28 21:49:34 UTC (rev 179287)
@@ -53,6 +53,7 @@
 class Image;
 class ResourceRequest;
 class URL;
+enum class PruningReason;
 
 typedef Vector<RefPtr<HistoryItem>> HistoryItemVector;
 
@@ -258,7 +259,7 @@
     HistoryItem* m_next;
     HistoryItem* m_prev;
     std::unique_ptr<CachedPage> m_cachedPage;
-    bool m_wasPruned;
+    PruningReason m_pruningReason;
 
 #if PLATFORM(IOS)
     FloatRect m_exposedContentRect;

Modified: branches/safari-600.1.4.15-branch/Source/WebCore/history/PageCache.cpp (179286 => 179287)


--- branches/safari-600.1.4.15-branch/Source/WebCore/history/PageCache.cpp	2015-01-28 21:45:00 UTC (rev 179286)
+++ branches/safari-600.1.4.15-branch/Source/WebCore/history/PageCache.cpp	2015-01-28 21:49:34 UTC (rev 179287)
@@ -51,6 +51,7 @@
 #include "SharedWorkerRepository.h"
 #include "SubframeLoader.h"
 #include <wtf/CurrentTime.h>
+#include <wtf/TemporaryChange.h>
 #include <wtf/text/CString.h>
 #include <wtf/text/StringConcatenate.h>
 
@@ -383,11 +384,10 @@
             || loadType == FrameLoadType::IndexedBackForward);
 }
 
-void PageCache::pruneToCapacityNow(int capacity)
+void PageCache::pruneToCapacityNow(int capacity, PruningReason pruningReason)
 {
-    int savedCapacity = m_capacity;
-    setCapacity(capacity);
-    setCapacity(savedCapacity);
+    TemporaryChange<int>(m_capacity, std::max(capacity, 0));
+    prune(pruningReason);
 }
 
 void PageCache::setCapacity(int capacity)
@@ -395,7 +395,7 @@
     ASSERT(capacity >= 0);
     m_capacity = std::max(capacity, 0);
 
-    prune();
+    prune(PruningReason::None);
 }
 
 int PageCache::frameCount() const
@@ -446,6 +446,23 @@
 }
 #endif
 
+static const char* pruningReasonToFeatureCounterKey(PruningReason pruningReason)
+{
+    switch (pruningReason) {
+    case PruningReason::MemoryPressure:
+        return FeatureCounterPageCacheFailurePrunedMemoryPressureKey;
+    case PruningReason::ProcessSuspended:
+        return FeatureCounterPageCacheFailurePrunedProcessedSuspendedKey;
+    case PruningReason::ReachedCapacity:
+        return FeatureCounterPageCacheFailurePrunedCapacityReachedKey;
+    case PruningReason::None:
+        ASSERT_NOT_REACHED();
+        return nullptr;
+    }
+    ASSERT_NOT_REACHED();
+    return nullptr;
+}
+
 void PageCache::add(PassRefPtr<HistoryItem> prpItem, Page& page)
 {
     ASSERT(prpItem);
@@ -458,11 +475,11 @@
         remove(item);
 
     item->m_cachedPage = std::make_unique<CachedPage>(page);
-    item->m_wasPruned = false;
+    item->m_pruningReason = PruningReason::None;
     addToLRUList(item);
     ++m_size;
     
-    prune();
+    prune(PruningReason::ReachedCapacity);
 }
 
 std::unique_ptr<CachedPage> PageCache::take(HistoryItem* item, Page* page)
@@ -478,8 +495,8 @@
     item->deref(); // Balanced in add().
 
     if (!cachedPage) {
-        if (item->m_wasPruned)
-            FEATURE_COUNTER_INCREMENT_KEY(page, FeatureCounterPageCacheFailureWasPrunedKey);
+        if (item->m_pruningReason != PruningReason::None)
+            FEATURE_COUNTER_INCREMENT_KEY(page, pruningReasonToFeatureCounterKey(item->m_pruningReason));
         return nullptr;
     }
 
@@ -504,8 +521,8 @@
         LOG(PageCache, "Not restoring page for %s from back/forward cache because cache entry has expired", item->url().string().ascii().data());
         FEATURE_COUNTER_INCREMENT_KEY(page, FeatureCounterPageCacheFailureExpiredKey);
         pageCache()->remove(item);
-    } else if (item->m_wasPruned)
-        FEATURE_COUNTER_INCREMENT_KEY(page, FeatureCounterPageCacheFailureWasPrunedKey);
+    } else if (item->m_pruningReason != PruningReason::None)
+        FEATURE_COUNTER_INCREMENT_KEY(page, pruningReasonToFeatureCounterKey(item->m_pruningReason));
 
     return nullptr;
 }
@@ -523,11 +540,11 @@
     item->deref(); // Balanced in add().
 }
 
-void PageCache::prune()
+void PageCache::prune(PruningReason pruningReason)
 {
     while (m_size > m_capacity) {
         ASSERT(m_tail && m_tail->m_cachedPage);
-        m_tail->m_wasPruned = true;
+        m_tail->m_pruningReason = pruningReason;
         remove(m_tail);
     }
 }

Modified: branches/safari-600.1.4.15-branch/Source/WebCore/history/PageCache.h (179286 => 179287)


--- branches/safari-600.1.4.15-branch/Source/WebCore/history/PageCache.h	2015-01-28 21:45:00 UTC (rev 179286)
+++ branches/safari-600.1.4.15-branch/Source/WebCore/history/PageCache.h	2015-01-28 21:49:34 UTC (rev 179287)
@@ -37,6 +37,8 @@
     class Frame;
     class HistoryItem;
     class Page;
+
+    enum class PruningReason { None, ProcessSuspended, MemoryPressure, ReachedCapacity };
     
     class PageCache {
         WTF_MAKE_NONCOPYABLE(PageCache); WTF_MAKE_FAST_ALLOCATED;
@@ -62,7 +64,7 @@
         void markPagesForFullStyleRecalc(Page*);
 
         // Used when memory is low to prune some cached pages.
-        void pruneToCapacityNow(int capacity);
+        void pruneToCapacityNow(int capacity, PruningReason);
 
 #if ENABLE(VIDEO_TRACK)
         void markPagesForCaptionPreferencesChanged();
@@ -81,7 +83,7 @@
         void addToLRUList(HistoryItem*); // Adds to the head of the list.
         void removeFromLRUList(HistoryItem*);
 
-        void prune();
+        void prune(PruningReason);
 
         int m_capacity;
         int m_size;

Modified: branches/safari-600.1.4.15-branch/Source/WebCore/loader/FrameLoader.cpp (179286 => 179287)


--- branches/safari-600.1.4.15-branch/Source/WebCore/loader/FrameLoader.cpp	2015-01-28 21:45:00 UTC (rev 179286)
+++ branches/safari-600.1.4.15-branch/Source/WebCore/loader/FrameLoader.cpp	2015-01-28 21:49:34 UTC (rev 179287)
@@ -1809,11 +1809,11 @@
             LOG(MemoryPressure, "Pruning page cache because under memory pressure at: %s", __PRETTY_FUNCTION__);
             LOG(PageCache, "Pruning page cache to 0 due to memory pressure");
             // Don't cache any page if we are under memory pressure.
-            pageCache()->pruneToCapacityNow(0);
+            pageCache()->pruneToCapacityNow(0, PruningReason::MemoryPressure);
         } else if (systemMemoryLevel() <= memoryLevelThresholdToPrunePageCache) {
             LOG(MemoryPressure, "Pruning page cache because system memory level is %d at: %s", systemMemoryLevel(), __PRETTY_FUNCTION__);
             LOG(PageCache, "Pruning page cache to %d due to low memory (level %d less or equal to %d threshold)", pageCache()->capacity() / 2, systemMemoryLevel(), memoryLevelThresholdToPrunePageCache);
-            pageCache()->pruneToCapacityNow(pageCache()->capacity() / 2);
+            pageCache()->pruneToCapacityNow(pageCache()->capacity() / 2, PruningReason::MemoryPressure);
         }
     }
 #endif

Modified: branches/safari-600.1.4.15-branch/Source/WebCore/platform/FeatureCounterKeys.h (179286 => 179287)


--- branches/safari-600.1.4.15-branch/Source/WebCore/platform/FeatureCounterKeys.h	2015-01-28 21:45:00 UTC (rev 179286)
+++ branches/safari-600.1.4.15-branch/Source/WebCore/platform/FeatureCounterKeys.h	2015-01-28 21:49:34 UTC (rev 179287)
@@ -59,7 +59,9 @@
 static const char FeatureCounterPageCacheFailureReloadFromOriginKey[] = "com.apple.WebKit.pageCache.failure.reloadFromOrigin";
 static const char FeatureCounterPageCacheFailureSameLoadKey[] = "com.apple.WebKit.pageCache.failure.sameLoad";
 static const char FeatureCounterPageCacheFailureExpiredKey[] = "com.apple.WebKit.pageCache.failure.expired";
-static const char FeatureCounterPageCacheFailureWasPrunedKey[] = "com.apple.WebKit.pageCache.failure.wasPruned";
+static const char FeatureCounterPageCacheFailurePrunedMemoryPressureKey[] = "com.apple.WebKit.pageCache.failure.pruned.memoryPressure";
+static const char FeatureCounterPageCacheFailurePrunedCapacityReachedKey[] = "com.apple.WebKit.pageCache.failure.pruned.capacityReached";
+static const char FeatureCounterPageCacheFailurePrunedProcessedSuspendedKey[] = "com.apple.WebKit.pageCache.failure.pruned.processSuspended";
 static const char FeatureCounterPageCacheFailureKey[] = "com.apple.WebKit.pageCache.failure";
 static const char FeatureCounterPageCacheSuccessKey[] = "com.apple.WebKit.pageCache.success";
 

Modified: branches/safari-600.1.4.15-branch/Source/WebCore/platform/MemoryPressureHandler.cpp (179286 => 179287)


--- branches/safari-600.1.4.15-branch/Source/WebCore/platform/MemoryPressureHandler.cpp	2015-01-28 21:45:00 UTC (rev 179286)
+++ branches/safari-600.1.4.15-branch/Source/WebCore/platform/MemoryPressureHandler.cpp	2015-01-28 21:49:34 UTC (rev 179287)
@@ -96,9 +96,9 @@
 {
     {
         ReliefLogger log("Empty the PageCache");
-        int savedPageCacheCapacity = pageCache()->capacity();
-        pageCache()->setCapacity(0);
-        pageCache()->setCapacity(savedPageCacheCapacity);
+        // 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().isUnderMemoryPressure() ? PruningReason::MemoryPressure : PruningReason::ProcessSuspended;
+        pageCache()->pruneToCapacityNow(0, pruningReason);
     }
 
     {

Modified: branches/safari-600.1.4.15-branch/Source/WebKit2/ChangeLog (179286 => 179287)


--- branches/safari-600.1.4.15-branch/Source/WebKit2/ChangeLog	2015-01-28 21:45:00 UTC (rev 179286)
+++ branches/safari-600.1.4.15-branch/Source/WebKit2/ChangeLog	2015-01-28 21:49:34 UTC (rev 179287)
@@ -1,3 +1,21 @@
+2015-01-28  Lucas Forschler  <lforsch...@apple.com>
+
+        Merge r177738
+
+    2014-12-25  Chris Dumez  <cdu...@apple.com>
+
+            [iOS] Log better using FeatureCounter why PageCache is failing due to pruned resources
+            https://bugs.webkit.org/show_bug.cgi?id=139921
+
+            Reviewed by Gavin Barraclough and Alexey Proskuryakov.
+
+            Call PageCache::pruneToCapacityNow() instead of multiple calls to
+            setCapacity() as it does exactly what we want. Also pass the new
+            PrunedReason argument so help us do better logging.
+
+            * WebProcess/WebProcess.cpp:
+            (WebKit::WebProcess::releasePageCache):
+
 2015-01-27  Lucas Forschler  <lforsch...@apple.com>
 
         Merge r177666

Modified: branches/safari-600.1.4.15-branch/Source/WebKit2/WebProcess/WebProcess.cpp (179286 => 179287)


--- branches/safari-600.1.4.15-branch/Source/WebKit2/WebProcess/WebProcess.cpp	2015-01-28 21:45:00 UTC (rev 179286)
+++ branches/safari-600.1.4.15-branch/Source/WebKit2/WebProcess/WebProcess.cpp	2015-01-28 21:49:34 UTC (rev 179287)
@@ -1135,9 +1135,7 @@
 
 void WebProcess::releasePageCache()
 {
-    int savedPageCacheCapacity = pageCache()->capacity();
-    pageCache()->setCapacity(0);
-    pageCache()->setCapacity(savedPageCacheCapacity);
+    pageCache()->pruneToCapacityNow(0, PruningReason::MemoryPressure);
 }
 
 #if !PLATFORM(COCOA)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to