Title: [177738] trunk/Source
Revision
177738
Author
[email protected]
Date
2014-12-25 13:09:40 -0800 (Thu, 25 Dec 2014)

Log Message

[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.

Source/WebCore:

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):

Source/WebKit2:

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):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (177737 => 177738)


--- trunk/Source/WebCore/ChangeLog	2014-12-25 18:55:21 UTC (rev 177737)
+++ trunk/Source/WebCore/ChangeLog	2014-12-25 21:09:40 UTC (rev 177738)
@@ -1,3 +1,36 @@
+2014-12-25  Chris Dumez  <[email protected]>
+
+        [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):
+
 2014-12-25  Gyuyoung Kim  <[email protected]>
 
         Use std::unique_ptr<> in WebCore/dom, plugin, and graphics

Modified: trunk/Source/WebCore/WebCore.exp.in (177737 => 177738)


--- trunk/Source/WebCore/WebCore.exp.in	2014-12-25 18:55:21 UTC (rev 177737)
+++ trunk/Source/WebCore/WebCore.exp.in	2014-12-25 21:09:40 UTC (rev 177738)
@@ -1559,6 +1559,7 @@
 __ZN7WebCore9LayerPoolC1Ev
 __ZN7WebCore9LayerPoolD1Ev
 __ZN7WebCore9PageCache11setCapacityEi
+__ZN7WebCore9PageCache18pruneToCapacityNowEiNS_13PruningReasonE
 __ZN7WebCore9PageCache33markPagesForVistedLinkStyleRecalcEv
 __ZN7WebCore9PageCache6removeEPNS_11HistoryItemE
 __ZN7WebCore9PageGroup16syncLocalStorageEv

Modified: trunk/Source/WebCore/history/HistoryItem.cpp (177737 => 177738)


--- trunk/Source/WebCore/history/HistoryItem.cpp	2014-12-25 18:55:21 UTC (rev 177737)
+++ trunk/Source/WebCore/history/HistoryItem.cpp	2014-12-25 21:09:40 UTC (rev 177738)
@@ -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: trunk/Source/WebCore/history/HistoryItem.h (177737 => 177738)


--- trunk/Source/WebCore/history/HistoryItem.h	2014-12-25 18:55:21 UTC (rev 177737)
+++ trunk/Source/WebCore/history/HistoryItem.h	2014-12-25 21:09:40 UTC (rev 177738)
@@ -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: trunk/Source/WebCore/history/PageCache.cpp (177737 => 177738)


--- trunk/Source/WebCore/history/PageCache.cpp	2014-12-25 18:55:21 UTC (rev 177737)
+++ trunk/Source/WebCore/history/PageCache.cpp	2014-12-25 21:09:40 UTC (rev 177738)
@@ -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>
 
@@ -370,11 +371,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)
@@ -382,7 +382,7 @@
     ASSERT(capacity >= 0);
     m_capacity = std::max(capacity, 0);
 
-    prune();
+    prune(PruningReason::None);
 }
 
 int PageCache::frameCount() const
@@ -433,6 +433,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);
@@ -445,11 +462,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)
@@ -465,8 +482,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;
     }
 
@@ -491,8 +508,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;
 }
@@ -510,11 +527,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: trunk/Source/WebCore/history/PageCache.h (177737 => 177738)


--- trunk/Source/WebCore/history/PageCache.h	2014-12-25 18:55:21 UTC (rev 177737)
+++ trunk/Source/WebCore/history/PageCache.h	2014-12-25 21:09:40 UTC (rev 177738)
@@ -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);
+        WEBCORE_EXPORT 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: trunk/Source/WebCore/loader/FrameLoader.cpp (177737 => 177738)


--- trunk/Source/WebCore/loader/FrameLoader.cpp	2014-12-25 18:55:21 UTC (rev 177737)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp	2014-12-25 21:09:40 UTC (rev 177738)
@@ -1766,11 +1766,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: trunk/Source/WebCore/platform/FeatureCounterKeys.h (177737 => 177738)


--- trunk/Source/WebCore/platform/FeatureCounterKeys.h	2014-12-25 18:55:21 UTC (rev 177737)
+++ trunk/Source/WebCore/platform/FeatureCounterKeys.h	2014-12-25 21:09:40 UTC (rev 177738)
@@ -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: trunk/Source/WebCore/platform/MemoryPressureHandler.cpp (177737 => 177738)


--- trunk/Source/WebCore/platform/MemoryPressureHandler.cpp	2014-12-25 18:55:21 UTC (rev 177737)
+++ trunk/Source/WebCore/platform/MemoryPressureHandler.cpp	2014-12-25 21:09:40 UTC (rev 177738)
@@ -101,9 +101,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: trunk/Source/WebKit2/ChangeLog (177737 => 177738)


--- trunk/Source/WebKit2/ChangeLog	2014-12-25 18:55:21 UTC (rev 177737)
+++ trunk/Source/WebKit2/ChangeLog	2014-12-25 21:09:40 UTC (rev 177738)
@@ -1,3 +1,17 @@
+2014-12-25  Chris Dumez  <[email protected]>
+
+        [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):
+
 2014-12-25  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r177712 and r177717.

Modified: trunk/Source/WebKit2/WebProcess/WebProcess.cpp (177737 => 177738)


--- trunk/Source/WebKit2/WebProcess/WebProcess.cpp	2014-12-25 18:55:21 UTC (rev 177737)
+++ trunk/Source/WebKit2/WebProcess/WebProcess.cpp	2014-12-25 21:09:40 UTC (rev 177738)
@@ -1128,9 +1128,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
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to