зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1614619 - Eviction algorithm should first evict entries of a content type that’s above a limit r=valentin
This patch implements limit for media content type in the cache. When we need to evict something from the cache and media is over the limit, it's evicted first. Differential Revision: https://phabricator.services.mozilla.com/D64548 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
4ed5d9375b
Коммит
3ab8b4b548
|
@ -774,6 +774,13 @@
|
|||
value: 2
|
||||
mirror: always
|
||||
|
||||
# A percentage limit for media content type in the disk cache. When some entries
|
||||
# need to be evicted and media is over the limit, it's evicted first.
|
||||
- name: browser.cache.disk.content_type_media_limit
|
||||
type: RelaxedAtomicInt32
|
||||
value: 50
|
||||
mirror: always
|
||||
|
||||
- name: browser.contentblocking.database.enabled
|
||||
type: bool
|
||||
value: false
|
||||
|
|
|
@ -1254,6 +1254,25 @@ nsresult CacheIndex::GetEntryForEviction(bool aIgnoreEmptyEntries,
|
|||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
if (index->mIndexStats.Size() == 0) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
int32_t mediaUsage =
|
||||
round(static_cast<double>(index->mIndexStats.SizeByType(
|
||||
nsICacheEntry::CONTENT_TYPE_MEDIA)) *
|
||||
100.0 / static_cast<double>(index->mIndexStats.Size()));
|
||||
int32_t mediaUsageLimit =
|
||||
StaticPrefs::browser_cache_disk_content_type_media_limit();
|
||||
bool evictMedia = false;
|
||||
if (mediaUsage > mediaUsageLimit) {
|
||||
LOG(
|
||||
("CacheIndex::GetEntryForEviction() - media content type is over the "
|
||||
"limit [mediaUsage=%d, mediaUsageLimit=%d]",
|
||||
mediaUsage, mediaUsageLimit));
|
||||
evictMedia = true;
|
||||
}
|
||||
|
||||
SHA1Sum::Hash hash;
|
||||
CacheIndexRecord* foundRecord = nullptr;
|
||||
uint32_t skipped = 0;
|
||||
|
@ -1268,6 +1287,11 @@ nsresult CacheIndex::GetEntryForEviction(bool aIgnoreEmptyEntries,
|
|||
|
||||
++skipped;
|
||||
|
||||
if (evictMedia && CacheIndexEntry::GetContentType(rec) !=
|
||||
nsICacheEntry::CONTENT_TYPE_MEDIA) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (IsForcedValidEntry(&hash)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -1290,9 +1314,10 @@ nsresult CacheIndex::GetEntryForEviction(bool aIgnoreEmptyEntries,
|
|||
*aCnt = skipped;
|
||||
|
||||
LOG(
|
||||
("CacheIndex::GetEntryForEviction() - returning entry from frecency "
|
||||
"array [hash=%08x%08x%08x%08x%08x, cnt=%u, frecency=%u]",
|
||||
LOGSHA1(&hash), *aCnt, foundRecord->mFrecency));
|
||||
("CacheIndex::GetEntryForEviction() - returning entry "
|
||||
"[hash=%08x%08x%08x%08x%08x, cnt=%u, frecency=%u, contentType=%u]",
|
||||
LOGSHA1(&hash), *aCnt, foundRecord->mFrecency,
|
||||
CacheIndexEntry::GetContentType(foundRecord)));
|
||||
|
||||
memcpy(aHash, &hash, sizeof(SHA1Sum::Hash));
|
||||
|
||||
|
|
|
@ -228,15 +228,16 @@ class CacheIndexEntry : public PLDHashEntryHdr {
|
|||
uint16_t GetOnStopTime() const { return mRec->mOnStopTime; }
|
||||
|
||||
void SetContentType(uint8_t aType) { mRec->mContentType = aType; }
|
||||
uint8_t GetContentType() const {
|
||||
if (mRec->mContentType >= nsICacheEntry::CONTENT_TYPE_LAST) {
|
||||
uint8_t GetContentType() const { return GetContentType(mRec.get()); }
|
||||
static uint8_t GetContentType(CacheIndexRecord* aRec) {
|
||||
if (aRec->mContentType >= nsICacheEntry::CONTENT_TYPE_LAST) {
|
||||
LOG(
|
||||
("CacheIndexEntry::GetContentType() - Found invalid content type "
|
||||
"[hash=%08x%08x%08x%08x%08x, contentType=%u]",
|
||||
LOGSHA1(mRec->mHash), mRec->mContentType));
|
||||
LOGSHA1(aRec->mHash), aRec->mContentType));
|
||||
return nsICacheEntry::CONTENT_TYPE_UNKNOWN;
|
||||
}
|
||||
return mRec->mContentType;
|
||||
return aRec->mContentType;
|
||||
}
|
||||
|
||||
// Sets filesize in kilobytes.
|
||||
|
|
Загрузка…
Ссылка в новой задаче