diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-19 00:53:02 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-19 00:53:02 +0000 |
commit | d997862f6c876e5fe85304a6f0ab82dbd1acf576 (patch) | |
tree | 20e8b3649a5d0b6d502f586992262b0d50fccbb0 | |
parent | 1f43948cc3e6d925b268d77fdac3c873dd7bb23f (diff) | |
download | chromium_src-d997862f6c876e5fe85304a6f0ab82dbd1acf576.zip chromium_src-d997862f6c876e5fe85304a6f0ab82dbd1acf576.tar.gz chromium_src-d997862f6c876e5fe85304a6f0ab82dbd1acf576.tar.bz2 |
Disk cache: Delete the disk cache if it is substantially bigger
than the desired max size, and adjust eviction to avoid
having long periods without it.
There's a few users with caches that are too big, and it
looks like the problem is that eviction could be stopped
forever, while still adding new items to the cache.
Now we only allow one minute (at a time) with eviction suspended.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/647054
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39407 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | net/disk_cache/backend_impl.cc | 14 | ||||
-rw-r--r-- | net/disk_cache/eviction.cc | 43 | ||||
-rw-r--r-- | net/disk_cache/eviction.h | 2 |
3 files changed, 41 insertions, 18 deletions
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc index 3b3ca6a..f233172 100644 --- a/net/disk_cache/backend_impl.cc +++ b/net/disk_cache/backend_impl.cc @@ -129,12 +129,7 @@ bool DelayedCacheCleanup(const FilePath& full_path) { return false; } -#if defined(OS_WIN) WorkerPool::PostTask(FROM_HERE, new CleanupTask(path, name_str), true); -#elif defined(OS_POSIX) - // TODO(rvargas): Use the worker pool. - MessageLoop::current()->PostTask(FROM_HERE, new CleanupTask(path, name_str)); -#endif return true; } @@ -1165,9 +1160,14 @@ int BackendImpl::NewEntry(Addr address, EntryImpl** entry, bool* dirty) { return ERR_INVALID_ADDRESS; } + Time start = Time::Now(); if (!cache_entry->entry()->Load()) return ERR_READ_FAILURE; + if (IsLoaded()) { + CACHE_UMA(AGE_MS, "LoadTime", GetSizeGroup(), start); + } + if (!cache_entry->SanityCheck()) { LOG(WARNING) << "Messed up entry found."; return ERR_INVALID_ENTRY; @@ -1622,7 +1622,9 @@ bool BackendImpl::CheckIndex() { AdjustMaxCacheSize(data_->header.table_len); - if (data_->header.num_bytes < 0) { + if (data_->header.num_bytes < 0 || + (max_size_ < kint32max - kDefaultCacheSize && + data_->header.num_bytes > max_size_ + kDefaultCacheSize)) { LOG(ERROR) << "Invalid cache (current) size"; return false; } diff --git a/net/disk_cache/eviction.cc b/net/disk_cache/eviction.cc index bdcef6b..fd5bd2e 100644 --- a/net/disk_cache/eviction.cc +++ b/net/disk_cache/eviction.cc @@ -44,6 +44,7 @@ namespace { const int kCleanUpMargin = 1024 * 1024; const int kHighUse = 10; // Reuse count to be on the HIGH_USE list. const int kTargetTime = 24 * 7; // Time to be evicted (hours since last use). +const int kMaxDelayedTrims = 60; int LowWaterAdjust(int high_water) { if (high_water < kCleanUpMargin) @@ -67,18 +68,19 @@ void Eviction::Init(BackendImpl* backend) { first_trim_ = true; trimming_ = false; delay_trim_ = false; + trim_delays_ = 0; } void Eviction::TrimCache(bool empty) { - if (new_eviction_) - return TrimCacheV2(empty); - if (backend_->disabled_ || trimming_) return; - if (!empty && backend_->IsLoaded()) + if (!empty && !ShouldTrim()) return PostDelayedTrim(); + if (new_eviction_) + return TrimCacheV2(empty); + Trace("*** Trim Cache ***"); trimming_ = true; Time start = Time::Now(); @@ -111,7 +113,12 @@ void Eviction::TrimCache(bool empty) { } } - CACHE_UMA(AGE_MS, "TotalTrimTime", backend_->GetSizeGroup(), start); + if (empty) { + CACHE_UMA(AGE_MS, "TotalClearTimeV1", 0, start); + } else { + CACHE_UMA(AGE_MS, "TotalTrimTimeV1", backend_->GetSizeGroup(), start); + } + trimming_ = false; Trace("*** Trim Cache end ***"); return; @@ -153,15 +160,28 @@ void Eviction::PostDelayedTrim() { if (delay_trim_) return; delay_trim_ = true; + trim_delays_++; MessageLoop::current()->PostDelayedTask(FROM_HERE, factory_.NewRunnableMethod(&Eviction::DelayedTrim), 1000); } void Eviction::DelayedTrim() { delay_trim_ = false; + if (trim_delays_ < kMaxDelayedTrims && backend_->IsLoaded()) + return PostDelayedTrim(); + TrimCache(false); } +bool Eviction::ShouldTrim() { + if (trim_delays_ < kMaxDelayedTrims && backend_->IsLoaded()) + return false; + + UMA_HISTOGRAM_COUNTS("DiskCache.TrimDelays", trim_delays_); + trim_delays_ = 0; + return true; +} + void Eviction::ReportTrimTimes(EntryImpl* entry) { if (first_trim_) { first_trim_ = false; @@ -223,12 +243,6 @@ bool Eviction::EvictEntry(CacheRankingsBlock* node, bool empty) { // ----------------------------------------------------------------------- void Eviction::TrimCacheV2(bool empty) { - if (backend_->disabled_ || trimming_) - return; - - if (!empty && backend_->IsLoaded()) - return PostDelayedTrim(); - Trace("*** Trim Cache ***"); trimming_ = true; Time start = Time::Now(); @@ -300,7 +314,12 @@ void Eviction::TrimCacheV2(bool empty) { factory_.NewRunnableMethod(&Eviction::TrimDeleted, empty)); } - CACHE_UMA(AGE_MS, "TotalTrimTime", backend_->GetSizeGroup(), start); + if (empty) { + CACHE_UMA(AGE_MS, "TotalClearTimeV2", 0, start); + } else { + CACHE_UMA(AGE_MS, "TotalTrimTimeV2", backend_->GetSizeGroup(), start); + } + Trace("*** Trim Cache end ***"); trimming_ = false; return; diff --git a/net/disk_cache/eviction.h b/net/disk_cache/eviction.h index e3c0a72..c86e33a 100644 --- a/net/disk_cache/eviction.h +++ b/net/disk_cache/eviction.h @@ -42,6 +42,7 @@ class Eviction { private: void PostDelayedTrim(); void DelayedTrim(); + bool ShouldTrim(); void ReportTrimTimes(EntryImpl* entry); Rankings::List GetListForEntry(EntryImpl* entry); bool EvictEntry(CacheRankingsBlock* node, bool empty); @@ -67,6 +68,7 @@ class Eviction { Rankings* rankings_; IndexHeader* header_; int max_size_; + int trim_delays_; bool new_eviction_; bool first_trim_; bool trimming_; |