Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1600)

Unified Diff: Source/platform/graphics/ImageDecodingStore.cpp

Issue 110273002: Refine memory accounting in ImageDecodingStore for discardable entries. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Store accounting information in CacheEntry Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/platform/graphics/ImageDecodingStore.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/graphics/ImageDecodingStore.cpp
diff --git a/Source/platform/graphics/ImageDecodingStore.cpp b/Source/platform/graphics/ImageDecodingStore.cpp
index 9add9aa07b6532dd382da1166ff97038fb1559fd..20ac6898866cc1da8cecbc0f5f17626a9d3cb982 100644
--- a/Source/platform/graphics/ImageDecodingStore.cpp
+++ b/Source/platform/graphics/ImageDecodingStore.cpp
@@ -32,6 +32,9 @@ namespace WebCore {
namespace {
+// Allow up to 128 non-accounted discardable entries. Non-accounted entries are
+// entries that do not contribute to the memory usage of the cache.
+static const size_t maxNonAccountedDiscardableEntries = 128;
// 32MB memory limit for cache.
static const size_t defaultCacheLimitInBytes = 32768 * 1024;
static ImageDecodingStore* s_instance = 0;
@@ -46,7 +49,8 @@ static void setInstance(ImageDecodingStore* imageDecodingStore)
} // namespace
ImageDecodingStore::ImageDecodingStore()
- : m_cacheLimitInBytes(defaultCacheLimitInBytes)
+ : m_discardableEntriesCount(0)
+ , m_cacheLimitInBytes(defaultCacheLimitInBytes)
, m_memoryUsageInBytes(0)
{
}
@@ -345,10 +349,12 @@ bool ImageDecodingStore::lockCacheEntryInternal(ImageCacheEntry* cacheEntry, con
template<class T, class U, class V>
void ImageDecodingStore::insertCacheInternal(PassOwnPtr<T> cacheEntry, U* cacheMap, V* identifierMap)
{
- // Usage of discardable memory is not counted because we want to use more
- // than the cache limit allows. Cache limit only applies to non-discardable
- // objects.
- if (!cacheEntry->isDiscardable())
+ if (cacheEntry->isDiscardable()) {
+ ++m_discardableEntriesCount;
+ if (m_discardableEntriesCount <= maxNonAccountedDiscardableEntries)
+ cacheEntry->disableAccounting();
+ }
+ if (cacheEntry->isAccountingEnabled())
incrementMemoryUsage(cacheEntry->memoryUsageInBytes());
// m_orderedCacheList is used to support LRU operations to reorder cache
@@ -368,7 +374,11 @@ void ImageDecodingStore::insertCacheInternal(PassOwnPtr<T> cacheEntry, U* cacheM
template<class T, class U, class V>
void ImageDecodingStore::removeFromCacheInternal(const T* cacheEntry, U* cacheMap, V* identifierMap, Vector<OwnPtr<CacheEntry> >* deletionList)
{
- if (!cacheEntry->isDiscardable())
+ if (cacheEntry->isDiscardable()) {
+ ASSERT(m_discardableEntriesCount > 0);
+ --m_discardableEntriesCount;
+ }
+ if (cacheEntry->isAccountingEnabled())
decrementMemoryUsage(cacheEntry->memoryUsageInBytes());
// Remove entry from identifier map.
« no previous file with comments | « Source/platform/graphics/ImageDecodingStore.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698