Chromium Code Reviews| Index: Source/core/loader/cache/MemoryCache.cpp |
| diff --git a/Source/core/loader/cache/MemoryCache.cpp b/Source/core/loader/cache/MemoryCache.cpp |
| index 3a2bf6863ddb7ea52c30c71879a129bb9bad2185..f15816c388b9c8084670ee626671210f4f1d3aa3 100644 |
| --- a/Source/core/loader/cache/MemoryCache.cpp |
| +++ b/Source/core/loader/cache/MemoryCache.cpp |
| @@ -52,7 +52,6 @@ namespace WebCore { |
| static MemoryCache* gMemoryCache; |
| static const int cDefaultCacheCapacity = 8192 * 1024; |
| -static const double cMinDelayBeforeLiveDecodedPrune = 1; // Seconds. |
|
Justin Novosad
2013/07/23 16:55:12
This variable should still exist, but it should be
|
| static const float cTargetPrunePercentage = .95f; // Percentage of capacity toward which we prune, to avoid immediately pruning again. |
| static const double cDefaultDecodedDataDeletionInterval = 0; |
| @@ -77,6 +76,7 @@ MemoryCache::MemoryCache() |
| , m_deadDecodedDataDeletionInterval(cDefaultDecodedDataDeletionInterval) |
| , m_liveSize(0) |
| , m_deadSize(0) |
| + , m_delayBeforeLiveDecodedPrune(1) // Seconds. |
| #ifdef MEMORY_CACHE_STATS |
| , m_statsTimer(this, &MemoryCache::dumpStats) |
| #endif |
| @@ -186,32 +186,37 @@ void MemoryCache::pruneLiveResourcesToSize(unsigned targetSize) |
| currentTime = WTF::currentTime(); |
| // Destroy any decoded data in live objects that we can. |
| - // Start from the tail, since this is the least recently accessed of the objects. |
| + // Start from the tail, since this is the lowest priority |
| + // and least recently accessed of the objects. |
| // The list might not be sorted by the m_lastDecodedAccessTime. The impact |
| // of this weaker invariant is minor as the below if statement to check the |
| // elapsedTime will evaluate to false as the currentTime will be a lot |
| // greater than the current->m_lastDecodedAccessTime. |
| // For more details see: https://bugs.webkit.org/show_bug.cgi?id=30209 |
| - CachedResource* current = m_liveDecodedResources.m_tail; |
| - while (current) { |
| - CachedResource* prev = current->m_prevInLiveResourcesList; |
| - ASSERT(current->hasClients()); |
| - if (current->isLoaded() && current->decodedSize()) { |
| - // Check to see if the remaining resources are too new to prune. |
| - double elapsedTime = currentTime - current->m_lastDecodedAccessTime; |
| - if (elapsedTime < cMinDelayBeforeLiveDecodedPrune) |
| - return; |
| - |
| - // Destroy our decoded data. This will remove us from |
| - // m_liveDecodedResources, and possibly move us to a different LRU |
| - // list in m_allResources. |
| - current->destroyDecodedData(); |
| - |
| - if (targetSize && m_liveSize <= targetSize) |
| - return; |
| + |
| + // Start pruning from the lowest priority list. |
| + for (int i = 0; i < 3; i++) { |
| + CachedResource* current = m_liveDecodedResources[i].m_tail; |
| + while (current) { |
| + CachedResource* prev = current->m_prevInLiveResourcesList; |
| + ASSERT(current->hasClients()); |
| + if (current->isLoaded() && current->decodedSize()) { |
| + // Check to see if the remaining resources are too new to prune. |
| + double elapsedTime = currentTime - current->m_lastDecodedAccessTime; |
| + if (elapsedTime < m_delayBeforeLiveDecodedPrune) |
| + return; |
| + |
| + // Destroy our decoded data. This will remove us from |
| + // m_liveDecodedResources, and possibly move us to a different LRU |
| + // list in m_allResources. |
| + current->destroyDecodedData(); |
| + |
| + if (targetSize && m_liveSize <= targetSize) |
| + return; |
| + } |
| + current = prev; |
| } |
| - current = prev; |
| } |
| } |
| @@ -439,10 +444,12 @@ void MemoryCache::removeFromLiveDecodedResourcesList(CachedResource* resource) |
| return; |
| resource->m_inLiveDecodedResourcesList = false; |
| + LRUList* list = &m_liveDecodedResources[resource->decodePriority()]; |
| + |
| #if !ASSERT_DISABLED |
| // Verify that we are in fact in this list. |
| bool found = false; |
| - for (CachedResource* current = m_liveDecodedResources.m_head; current; current = current->m_nextInLiveResourcesList) { |
| + for (CachedResource* current = list->m_head; current; current = current->m_nextInLiveResourcesList) { |
| if (current == resource) { |
| found = true; |
| break; |
| @@ -453,22 +460,22 @@ void MemoryCache::removeFromLiveDecodedResourcesList(CachedResource* resource) |
| CachedResource* next = resource->m_nextInLiveResourcesList; |
| CachedResource* prev = resource->m_prevInLiveResourcesList; |
| - |
| - if (next == 0 && prev == 0 && m_liveDecodedResources.m_head != resource) |
| + |
| + if (!next && !prev && list->m_head != resource) |
| return; |
| - |
| + |
| resource->m_nextInLiveResourcesList = 0; |
| resource->m_prevInLiveResourcesList = 0; |
| if (next) |
| next->m_prevInLiveResourcesList = prev; |
| - else if (m_liveDecodedResources.m_tail == resource) |
| - m_liveDecodedResources.m_tail = prev; |
| + else if (list->m_tail == resource) |
| + list->m_tail = prev; |
| if (prev) |
| prev->m_nextInLiveResourcesList = next; |
| - else if (m_liveDecodedResources.m_head == resource) |
| - m_liveDecodedResources.m_head = next; |
| + else if (list->m_head == resource) |
| + list->m_head = next; |
| } |
| void MemoryCache::insertInLiveDecodedResourcesList(CachedResource* resource) |
| @@ -477,18 +484,19 @@ void MemoryCache::insertInLiveDecodedResourcesList(CachedResource* resource) |
| ASSERT(!resource->m_nextInLiveResourcesList && !resource->m_prevInLiveResourcesList && !resource->m_inLiveDecodedResourcesList); |
| resource->m_inLiveDecodedResourcesList = true; |
| - resource->m_nextInLiveResourcesList = m_liveDecodedResources.m_head; |
| - if (m_liveDecodedResources.m_head) |
| - m_liveDecodedResources.m_head->m_prevInLiveResourcesList = resource; |
| - m_liveDecodedResources.m_head = resource; |
| - |
| + LRUList* list = &m_liveDecodedResources[resource->decodePriority()]; |
| + resource->m_nextInLiveResourcesList = list->m_head; |
| + if (list->m_head) |
| + list->m_head->m_prevInLiveResourcesList = resource; |
| + list->m_head = resource; |
| + |
| if (!resource->m_nextInLiveResourcesList) |
| - m_liveDecodedResources.m_tail = resource; |
| - |
| + list->m_tail = resource; |
| + |
| #if !ASSERT_DISABLED |
| // Verify that we are in now in the list like we should be. |
| bool found = false; |
| - for (CachedResource* current = m_liveDecodedResources.m_head; current; current = current->m_nextInLiveResourcesList) { |
| + for (CachedResource* current = list->m_head; current; current = current->m_nextInLiveResourcesList) { |
| if (current == resource) { |
| found = true; |
| break; |
| @@ -589,7 +597,8 @@ void MemoryCache::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const |
| memoryObjectInfo->setClassName("MemoryCache"); |
| info.addMember(m_resources, "resources"); |
| info.addMember(m_allResources, "allResources"); |
| - info.addMember(m_liveDecodedResources, "liveDecodedResources"); |
| + for (int i = 0; i < 3; ++i) |
| + info.addMember(m_liveDecodedResources[i], "liveDecodedResources"); |
| for (CachedResourceMap::const_iterator i = m_resources.begin(); i != m_resources.end(); ++i) |
| info.addMember(i->value, "cachedResourceItem", WTF::RetainingPointer); |
| } |