summaryrefslogtreecommitdiffstats
path: root/net/disk_cache
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-09 22:43:35 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-09 22:43:35 +0000
commit8f82f9d9ae8dfd23ab63fb9e63c6246da71d29fd (patch)
tree3c4308efb534a5585d947882666b86073ae89463 /net/disk_cache
parentd756326c7c3c4a53ca94bc8d709d13e65c0d6464 (diff)
downloadchromium_src-8f82f9d9ae8dfd23ab63fb9e63c6246da71d29fd.zip
chromium_src-8f82f9d9ae8dfd23ab63fb9e63c6246da71d29fd.tar.gz
chromium_src-8f82f9d9ae8dfd23ab63fb9e63c6246da71d29fd.tar.bz2
Disk cache: Don't evict entries if we are busy doing other stuff.
BUG=10727 TEST=none Review URL: http://codereview.chromium.org/155314 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20330 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache')
-rw-r--r--net/disk_cache/backend_impl.cc27
-rw-r--r--net/disk_cache/backend_impl.h9
-rw-r--r--net/disk_cache/eviction.cc39
-rw-r--r--net/disk_cache/eviction.h3
4 files changed, 58 insertions, 20 deletions
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc
index 0a59030..e089660 100644
--- a/net/disk_cache/backend_impl.cc
+++ b/net/disk_cache/backend_impl.cc
@@ -766,13 +766,18 @@ void BackendImpl::TooMuchStorageRequested(int32 size) {
stats_.ModifyStorageStats(0, size);
}
-std::string BackendImpl::HistogramName(const char* name, int experiment) {
+bool BackendImpl::IsLoaded() const {
+ CACHE_UMA(COUNTS, "PendingIO", GetSizeGroup(), num_pending_io_);
+ return num_pending_io_ > 10;
+}
+
+std::string BackendImpl::HistogramName(const char* name, int experiment) const {
if (!experiment)
return StringPrintf("DiskCache.%d.%s", cache_type_, name);
return StringPrintf("DiskCache.%d.%s_%d", cache_type_, name, experiment);
}
-int BackendImpl::GetSizeGroup() {
+int BackendImpl::GetSizeGroup() const {
if (disabled_)
return 0;
@@ -859,13 +864,21 @@ void BackendImpl::OnEvent(Stats::Counters an_event) {
void BackendImpl::OnStatsTimer() {
stats_.OnEvent(Stats::TIMER);
- int64 current = stats_.GetCounter(Stats::OPEN_ENTRIES);
int64 time = stats_.GetCounter(Stats::TIMER);
+ int64 current = stats_.GetCounter(Stats::OPEN_ENTRIES);
+
+ // OPEN_ENTRIES is a sampled average of the number of open entries, avoiding
+ // the bias towards 0.
+ if (num_refs_ && (current != num_refs_)) {
+ int64 diff = (num_refs_ - current) / 50;
+ if (!diff)
+ diff = num_refs_ > current ? 1 : -1;
+ current = current + diff;
+ stats_.SetCounter(Stats::OPEN_ENTRIES, current);
+ stats_.SetCounter(Stats::MAX_ENTRIES, max_refs_);
+ }
- current = current * (time - 1) + num_refs_;
- current /= time;
- stats_.SetCounter(Stats::OPEN_ENTRIES, current);
- stats_.SetCounter(Stats::MAX_ENTRIES, max_refs_);
+ CACHE_UMA(COUNTS, "NumberOfReferences", 0, num_refs_);
if (!data_)
first_timer_ = false;
diff --git a/net/disk_cache/backend_impl.h b/net/disk_cache/backend_impl.h
index 84a10c1..e53150e 100644
--- a/net/disk_cache/backend_impl.h
+++ b/net/disk_cache/backend_impl.h
@@ -119,17 +119,20 @@ class BackendImpl : public Backend {
// Logs requests that are denied due to being too big.
void TooMuchStorageRequested(int32 size);
+ // Returns true if this instance seems to be under heavy load.
+ bool IsLoaded() const;
+
// Returns the full histogram name, for the given base |name| and experiment,
// and the current cache type. The name will be "DiskCache.t.name_e" where n
// is the cache type and e the provided |experiment|.
- std::string HistogramName(const char* name, int experiment);
+ std::string HistogramName(const char* name, int experiment) const;
- net::CacheType cache_type() {
+ net::CacheType cache_type() const {
return cache_type_;
}
// Returns the group for this client, based on the current cache size.
- int GetSizeGroup();
+ int GetSizeGroup() const;
// Returns true if we should send histograms for this user again. The caller
// must call this function only once per run (because it returns always the
diff --git a/net/disk_cache/eviction.cc b/net/disk_cache/eviction.cc
index 14ffce9..8fb1e1c 100644
--- a/net/disk_cache/eviction.cc
+++ b/net/disk_cache/eviction.cc
@@ -66,6 +66,7 @@ void Eviction::Init(BackendImpl* backend) {
new_eviction_ = backend->new_eviction_;
first_trim_ = true;
trimming_ = false;
+ delay_trim_ = false;
}
void Eviction::TrimCache(bool empty) {
@@ -76,6 +77,9 @@ void Eviction::TrimCache(bool empty) {
if (backend_->disabled_ || trimming_)
return;
+ if (!empty && backend_->IsLoaded())
+ return PostDelayedTrim();
+
trimming_ = true;
Time start = Time::Now();
Rankings::ScopedRankingsBlock node(rankings_);
@@ -83,7 +87,6 @@ void Eviction::TrimCache(bool empty) {
rankings_->GetPrev(node.get(), Rankings::NO_USE));
DCHECK(next.get());
int target_size = empty ? 0 : max_size_;
- int deleted = 0;
while (header_->num_bytes > target_size && next.get()) {
node.reset(next.release());
next.reset(rankings_->GetPrev(node.get(), Rankings::NO_USE));
@@ -92,14 +95,14 @@ void Eviction::TrimCache(bool empty) {
if (!EvictEntry(node.get(), empty))
continue;
- if (!empty)
+ if (!empty) {
backend_->OnEvent(Stats::TRIM_ENTRY);
- if (++deleted == 4 && !empty) {
-#if defined(OS_WIN)
- MessageLoop::current()->PostTask(FROM_HERE,
- factory_.NewRunnableMethod(&Eviction::TrimCache, false));
- break;
-#endif
+
+ if ((Time::Now() - start).InMilliseconds() > 20) {
+ MessageLoop::current()->PostTask(FROM_HERE,
+ factory_.NewRunnableMethod(&Eviction::TrimCache, false));
+ break;
+ }
}
}
}
@@ -141,6 +144,20 @@ void Eviction::OnDestroyEntry(EntryImpl* entry) {
return OnDestroyEntryV2(entry);
}
+void Eviction::PostDelayedTrim() {
+ // Prevent posting multiple tasks.
+ if (delay_trim_)
+ return;
+ delay_trim_ = true;
+ MessageLoop::current()->PostDelayedTask(FROM_HERE,
+ factory_.NewRunnableMethod(&Eviction::DelayedTrim), 1000);
+}
+
+void Eviction::DelayedTrim() {
+ delay_trim_ = false;
+ TrimCache(false);
+}
+
void Eviction::ReportTrimTimes(EntryImpl* entry) {
if (first_trim_) {
first_trim_ = false;
@@ -211,6 +228,9 @@ void Eviction::TrimCacheV2(bool empty) {
if (backend_->disabled_ || trimming_)
return;
+ if (!empty && backend_->IsLoaded())
+ return PostDelayedTrim();
+
trimming_ = true;
Time start = Time::Now();
@@ -248,7 +268,6 @@ void Eviction::TrimCacheV2(bool empty) {
Rankings::ScopedRankingsBlock node(rankings_);
int target_size = empty ? 0 : max_size_;
- int deleted = 0;
for (; list < kListsToSearch; list++) {
while (header_->num_bytes > target_size && next[list].get()) {
node.reset(next[list].release());
@@ -259,7 +278,7 @@ void Eviction::TrimCacheV2(bool empty) {
if (!EvictEntry(node.get(), empty))
continue;
- if (++deleted == 4 && !empty) {
+ if (!empty && (Time::Now() - start).InMilliseconds() > 20) {
MessageLoop::current()->PostTask(FROM_HERE,
factory_.NewRunnableMethod(&Eviction::TrimCache, false));
break;
diff --git a/net/disk_cache/eviction.h b/net/disk_cache/eviction.h
index 3392680..e3c0a72 100644
--- a/net/disk_cache/eviction.h
+++ b/net/disk_cache/eviction.h
@@ -40,6 +40,8 @@ class Eviction {
void OnDestroyEntry(EntryImpl* entry);
private:
+ void PostDelayedTrim();
+ void DelayedTrim();
void ReportTrimTimes(EntryImpl* entry);
Rankings::List GetListForEntry(EntryImpl* entry);
bool EvictEntry(CacheRankingsBlock* node, bool empty);
@@ -68,6 +70,7 @@ class Eviction {
bool new_eviction_;
bool first_trim_;
bool trimming_;
+ bool delay_trim_;
ScopedRunnableMethodFactory<Eviction> factory_;
DISALLOW_COPY_AND_ASSIGN(Eviction);