| Index: net/disk_cache/v3/eviction_v3.cc
|
| ===================================================================
|
| --- net/disk_cache/v3/eviction_v3.cc (revision 0)
|
| +++ net/disk_cache/v3/eviction_v3.cc (working copy)
|
| @@ -161,40 +161,56 @@
|
| return;
|
| }
|
|
|
| -void Eviction::UpdateRank(EntryImpl* entry, bool modified) {
|
| - if (new_eviction_)
|
| - return UpdateRankV2(entry, modified);
|
| +void Eviction::OnOpenEntryV2(EntryImpl* entry) {
|
| + EntryStore* info = entry->entry()->Data();
|
| + DCHECK_EQ(ENTRY_NORMAL, info->state);
|
|
|
| - rankings_->UpdateRank(entry->rankings(), modified, GetListForEntry(entry));
|
| -}
|
| + if (info->reuse_count < kint32max) {
|
| + info->reuse_count++;
|
| + entry->entry()->set_modified();
|
|
|
| -void Eviction::OnOpenEntry(EntryImpl* entry) {
|
| - if (new_eviction_)
|
| - return OnOpenEntryV2(entry);
|
| + // We may need to move this to a new list.
|
| + if (1 == info->reuse_count) {
|
| + rankings_->Remove(entry->rankings(), Rankings::NO_USE, true);
|
| + rankings_->Insert(entry->rankings(), false, Rankings::LOW_USE);
|
| + entry->entry()->Store();
|
| + } else if (kHighUse == info->reuse_count) {
|
| + rankings_->Remove(entry->rankings(), Rankings::LOW_USE, true);
|
| + rankings_->Insert(entry->rankings(), false, Rankings::HIGH_USE);
|
| + entry->entry()->Store();
|
| + }
|
| + }
|
| }
|
|
|
| -void Eviction::OnCreateEntry(EntryImpl* entry) {
|
| - if (new_eviction_)
|
| - return OnCreateEntryV2(entry);
|
| +void Eviction::OnCreateEntryV2(EntryImpl* entry) {
|
| + EntryStore* info = entry->entry()->Data();
|
| + switch (info->state) {
|
| + case ENTRY_NORMAL: {
|
| + DCHECK(!info->reuse_count);
|
| + DCHECK(!info->refetch_count);
|
| + break;
|
| + };
|
| + case ENTRY_EVICTED: {
|
| + if (info->refetch_count < kint32max)
|
| + info->refetch_count++;
|
|
|
| - rankings_->Insert(entry->rankings(), true, GetListForEntry(entry));
|
| -}
|
| + if (info->refetch_count > kHighUse && info->reuse_count < kHighUse) {
|
| + info->reuse_count = kHighUse;
|
| + } else {
|
| + info->reuse_count++;
|
| + }
|
| + info->state = ENTRY_NORMAL;
|
| + entry->entry()->Store();
|
| + rankings_->Remove(entry->rankings(), Rankings::DELETED, true);
|
| + break;
|
| + };
|
| + default:
|
| + NOTREACHED();
|
| + }
|
|
|
| -void Eviction::OnDoomEntry(EntryImpl* entry) {
|
| - if (new_eviction_)
|
| - return OnDoomEntryV2(entry);
|
| -
|
| - if (entry->LeaveRankingsBehind())
|
| - return;
|
| -
|
| - rankings_->Remove(entry->rankings(), GetListForEntry(entry), true);
|
| + rankings_->Insert(entry->rankings(), true, GetListForEntryV2(entry));
|
| }
|
|
|
| -void Eviction::OnDestroyEntry(EntryImpl* entry) {
|
| - if (new_eviction_)
|
| - return OnDestroyEntryV2(entry);
|
| -}
|
| -
|
| void Eviction::SetTestMode() {
|
| test_mode_ = true;
|
| }
|
| @@ -204,6 +220,8 @@
|
| TrimDeleted(empty);
|
| }
|
|
|
| +// -----------------------------------------------------------------------
|
| +
|
| void Eviction::PostDelayedTrim() {
|
| // Prevent posting multiple tasks.
|
| if (delay_trim_)
|
| @@ -246,38 +264,6 @@
|
| return (!test_mode_ && header_->lru.sizes[Rankings::DELETED] > max_length);
|
| }
|
|
|
| -void Eviction::ReportTrimTimes(EntryImpl* entry) {
|
| - if (first_trim_) {
|
| - first_trim_ = false;
|
| - if (backend_->ShouldReportAgain()) {
|
| - CACHE_UMA(AGE, "TrimAge", 0, entry->GetLastUsed());
|
| - ReportListStats();
|
| - }
|
| -
|
| - if (header_->lru.filled)
|
| - return;
|
| -
|
| - header_->lru.filled = 1;
|
| -
|
| - if (header_->create_time) {
|
| - // This is the first entry that we have to evict, generate some noise.
|
| - backend_->FirstEviction();
|
| - } else {
|
| - // This is an old file, but we may want more reports from this user so
|
| - // lets save some create_time.
|
| - Time::Exploded old = {0};
|
| - old.year = 2009;
|
| - old.month = 3;
|
| - old.day_of_month = 1;
|
| - header_->create_time = Time::FromLocalExploded(old).ToInternalValue();
|
| - }
|
| - }
|
| -}
|
| -
|
| -Rankings::List Eviction::GetListForEntry(EntryImpl* entry) {
|
| - return Rankings::NO_USE;
|
| -}
|
| -
|
| bool Eviction::EvictEntry(CacheRankingsBlock* node, bool empty,
|
| Rankings::List list) {
|
| EntryImpl* entry = backend_->GetEnumeratedEntry(node, list);
|
| @@ -307,8 +293,6 @@
|
| return true;
|
| }
|
|
|
| -// -----------------------------------------------------------------------
|
| -
|
| void Eviction::TrimCacheV2(bool empty) {
|
| Trace("*** Trim Cache ***");
|
| trimming_ = true;
|
| @@ -393,98 +377,6 @@
|
| return;
|
| }
|
|
|
| -void Eviction::UpdateRankV2(EntryImpl* entry, bool modified) {
|
| - rankings_->UpdateRank(entry->rankings(), modified, GetListForEntryV2(entry));
|
| -}
|
| -
|
| -void Eviction::OnOpenEntryV2(EntryImpl* entry) {
|
| - EntryStore* info = entry->entry()->Data();
|
| - DCHECK_EQ(ENTRY_NORMAL, info->state);
|
| -
|
| - if (info->reuse_count < kint32max) {
|
| - info->reuse_count++;
|
| - entry->entry()->set_modified();
|
| -
|
| - // We may need to move this to a new list.
|
| - if (1 == info->reuse_count) {
|
| - rankings_->Remove(entry->rankings(), Rankings::NO_USE, true);
|
| - rankings_->Insert(entry->rankings(), false, Rankings::LOW_USE);
|
| - entry->entry()->Store();
|
| - } else if (kHighUse == info->reuse_count) {
|
| - rankings_->Remove(entry->rankings(), Rankings::LOW_USE, true);
|
| - rankings_->Insert(entry->rankings(), false, Rankings::HIGH_USE);
|
| - entry->entry()->Store();
|
| - }
|
| - }
|
| -}
|
| -
|
| -void Eviction::OnCreateEntryV2(EntryImpl* entry) {
|
| - EntryStore* info = entry->entry()->Data();
|
| - switch (info->state) {
|
| - case ENTRY_NORMAL: {
|
| - DCHECK(!info->reuse_count);
|
| - DCHECK(!info->refetch_count);
|
| - break;
|
| - };
|
| - case ENTRY_EVICTED: {
|
| - if (info->refetch_count < kint32max)
|
| - info->refetch_count++;
|
| -
|
| - if (info->refetch_count > kHighUse && info->reuse_count < kHighUse) {
|
| - info->reuse_count = kHighUse;
|
| - } else {
|
| - info->reuse_count++;
|
| - }
|
| - info->state = ENTRY_NORMAL;
|
| - entry->entry()->Store();
|
| - rankings_->Remove(entry->rankings(), Rankings::DELETED, true);
|
| - break;
|
| - };
|
| - default:
|
| - NOTREACHED();
|
| - }
|
| -
|
| - rankings_->Insert(entry->rankings(), true, GetListForEntryV2(entry));
|
| -}
|
| -
|
| -void Eviction::OnDoomEntryV2(EntryImpl* entry) {
|
| - EntryStore* info = entry->entry()->Data();
|
| - if (ENTRY_NORMAL != info->state)
|
| - return;
|
| -
|
| - if (entry->LeaveRankingsBehind()) {
|
| - info->state = ENTRY_DOOMED;
|
| - entry->entry()->Store();
|
| - return;
|
| - }
|
| -
|
| - rankings_->Remove(entry->rankings(), GetListForEntryV2(entry), true);
|
| -
|
| - info->state = ENTRY_DOOMED;
|
| - entry->entry()->Store();
|
| - rankings_->Insert(entry->rankings(), true, Rankings::DELETED);
|
| -}
|
| -
|
| -void Eviction::OnDestroyEntryV2(EntryImpl* entry) {
|
| - if (entry->LeaveRankingsBehind())
|
| - return;
|
| -
|
| - rankings_->Remove(entry->rankings(), Rankings::DELETED, true);
|
| -}
|
| -
|
| -Rankings::List Eviction::GetListForEntryV2(EntryImpl* entry) {
|
| - EntryStore* info = entry->entry()->Data();
|
| - DCHECK_EQ(ENTRY_NORMAL, info->state);
|
| -
|
| - if (!info->reuse_count)
|
| - return Rankings::NO_USE;
|
| -
|
| - if (info->reuse_count < kHighUse)
|
| - return Rankings::LOW_USE;
|
| -
|
| - return Rankings::HIGH_USE;
|
| -}
|
| -
|
| // This is a minimal implementation that just discards the oldest nodes.
|
| // TODO(rvargas): Do something better here.
|
| void Eviction::TrimDeleted(bool empty) {
|
| @@ -520,18 +412,32 @@
|
| return;
|
| }
|
|
|
| -bool Eviction::RemoveDeletedNode(CacheRankingsBlock* node) {
|
| - EntryImpl* entry = backend_->GetEnumeratedEntry(node, Rankings::DELETED);
|
| - if (!entry) {
|
| - Trace("NewEntry failed on Trim 0x%x", node->address().value());
|
| - return false;
|
| - }
|
| +void Eviction::ReportTrimTimes(EntryImpl* entry) {
|
| + if (first_trim_) {
|
| + first_trim_ = false;
|
| + if (backend_->ShouldReportAgain()) {
|
| + CACHE_UMA(AGE, "TrimAge", 0, entry->GetLastUsed());
|
| + ReportListStats();
|
| + }
|
|
|
| - bool doomed = (entry->entry()->Data()->state == ENTRY_DOOMED);
|
| - entry->entry()->Data()->state = ENTRY_DOOMED;
|
| - entry->DoomImpl();
|
| - entry->Release();
|
| - return !doomed;
|
| + if (header_->lru.filled)
|
| + return;
|
| +
|
| + header_->lru.filled = 1;
|
| +
|
| + if (header_->create_time) {
|
| + // This is the first entry that we have to evict, generate some noise.
|
| + backend_->FirstEviction();
|
| + } else {
|
| + // This is an old file, but we may want more reports from this user so
|
| + // lets save some create_time.
|
| + Time::Exploded old = {0};
|
| + old.year = 2009;
|
| + old.month = 3;
|
| + old.day_of_month = 1;
|
| + header_->create_time = Time::FromLocalExploded(old).ToInternalValue();
|
| + }
|
| + }
|
| }
|
|
|
| bool Eviction::NodeIsOldEnough(CacheRankingsBlock* node, int list) {
|
|
|