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

Side by Side Diff: net/disk_cache/eviction.cc

Issue 8540027: Disk Cache: Avoid discarding more deleted entries (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/disk_cache/eviction.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // The eviction policy is a very simple pure LRU, so the elements at the end of 5 // The eviction policy is a very simple pure LRU, so the elements at the end of
6 // the list are evicted until kCleanUpMargin free space is available. There is 6 // the list are evicted until kCleanUpMargin free space is available. There is
7 // only one list in use (Rankings::NO_USE), and elements are sent to the front 7 // only one list in use (Rankings::NO_USE), and elements are sent to the front
8 // of the list whenever they are accessed. 8 // of the list whenever they are accessed.
9 9
10 // The new (in-development) eviction policy adds re-use as a factor to evict 10 // The new (in-development) eviction policy adds re-use as a factor to evict
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 217
218 bool Eviction::ShouldTrim() { 218 bool Eviction::ShouldTrim() {
219 if (trim_delays_ < kMaxDelayedTrims && backend_->IsLoaded()) 219 if (trim_delays_ < kMaxDelayedTrims && backend_->IsLoaded())
220 return false; 220 return false;
221 221
222 UMA_HISTOGRAM_COUNTS("DiskCache.TrimDelays", trim_delays_); 222 UMA_HISTOGRAM_COUNTS("DiskCache.TrimDelays", trim_delays_);
223 trim_delays_ = 0; 223 trim_delays_ = 0;
224 return true; 224 return true;
225 } 225 }
226 226
227 bool Eviction::ShouldTrimDeleted() {
228 // Normally we use 25% for each list. The experiment doubles the number of
229 // deleted entries, so the total number of entries increases by 25%. Using
230 // 40% of that value for deleted entries leaves the size of the other three
231 // lists intact.
232 int max_length = in_experiment_ ? header_->num_entries * 2 / 5 :
233 header_->num_entries / 4;
234 return (!test_mode_ && header_->lru.sizes[Rankings::DELETED] > max_length);
235 }
236
227 void Eviction::ReportTrimTimes(EntryImpl* entry) { 237 void Eviction::ReportTrimTimes(EntryImpl* entry) {
228 if (first_trim_) { 238 if (first_trim_) {
229 first_trim_ = false; 239 first_trim_ = false;
230 if (backend_->ShouldReportAgain()) { 240 if (backend_->ShouldReportAgain()) {
231 CACHE_UMA(AGE, "TrimAge", 0, entry->GetLastUsed()); 241 CACHE_UMA(AGE, "TrimAge", 0, entry->GetLastUsed());
232 ReportListStats(); 242 ReportListStats();
233 } 243 }
234 244
235 if (header_->lru.filled) 245 if (header_->lru.filled)
236 return; 246 return;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 &Eviction::TrimCache, ptr_factory_.GetWeakPtr(), false)); 356 &Eviction::TrimCache, ptr_factory_.GetWeakPtr(), false));
347 break; 357 break;
348 } 358 }
349 } 359 }
350 if (!empty) 360 if (!empty)
351 list = kListsToSearch; 361 list = kListsToSearch;
352 } 362 }
353 363
354 if (empty) { 364 if (empty) {
355 TrimDeleted(true); 365 TrimDeleted(true);
356 } else if (header_->lru.sizes[Rankings::DELETED] > header_->num_entries / 4 && 366 } else if (ShouldTrimDeleted()) {
gavinp 2011/11/15 16:17:56 Good catch.
357 !test_mode_) {
358 MessageLoop::current()->PostTask(FROM_HERE, 367 MessageLoop::current()->PostTask(FROM_HERE,
359 base::Bind(&Eviction::TrimDeleted, ptr_factory_.GetWeakPtr(), empty)); 368 base::Bind(&Eviction::TrimDeleted, ptr_factory_.GetWeakPtr(), empty));
360 } 369 }
361 370
362 if (empty) { 371 if (empty) {
363 CACHE_UMA(AGE_MS, "TotalClearTimeV2", 0, start); 372 CACHE_UMA(AGE_MS, "TotalClearTimeV2", 0, start);
364 } else { 373 } else {
365 CACHE_UMA(AGE_MS, "TotalTrimTimeV2", 0, start); 374 CACHE_UMA(AGE_MS, "TotalTrimTimeV2", 0, start);
366 } 375 }
367 CACHE_UMA(COUNTS, "TrimItemsV2", 0, deleted_entries); 376 CACHE_UMA(COUNTS, "TrimItemsV2", 0, deleted_entries);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 (empty || (deleted_entries < 20 && 488 (empty || (deleted_entries < 20 &&
480 (TimeTicks::Now() - start).InMilliseconds() < 20))) { 489 (TimeTicks::Now() - start).InMilliseconds() < 20))) {
481 node.reset(next.release()); 490 node.reset(next.release());
482 next.reset(rankings_->GetPrev(node.get(), Rankings::DELETED)); 491 next.reset(rankings_->GetPrev(node.get(), Rankings::DELETED));
483 if (RemoveDeletedNode(node.get())) 492 if (RemoveDeletedNode(node.get()))
484 deleted_entries++; 493 deleted_entries++;
485 if (test_mode_) 494 if (test_mode_)
486 break; 495 break;
487 } 496 }
488 497
489 // Normally we use 25% for each list. The experiment doubles the number of 498 if (deleted_entries && !empty && ShouldTrimDeleted()) {
490 // deleted entries, so the total number of entries increases by 25%. Using
491 // 40% of that value for deleted entries leaves the size of the other three
492 // lists intact.
493 int max_length = in_experiment_ ? header_->num_entries * 2 / 5 :
494 header_->num_entries / 4;
495 if (deleted_entries && !empty && !test_mode_ &&
496 header_->lru.sizes[Rankings::DELETED] > max_length) {
497 MessageLoop::current()->PostTask(FROM_HERE, 499 MessageLoop::current()->PostTask(FROM_HERE,
498 base::Bind(&Eviction::TrimDeleted, ptr_factory_.GetWeakPtr(), false)); 500 base::Bind(&Eviction::TrimDeleted, ptr_factory_.GetWeakPtr(), false));
499 } 501 }
500 502
501 CACHE_UMA(AGE_MS, "TotalTrimDeletedTime", 0, start); 503 CACHE_UMA(AGE_MS, "TotalTrimDeletedTime", 0, start);
502 CACHE_UMA(COUNTS, "TrimDeletedItems", 0, deleted_entries); 504 CACHE_UMA(COUNTS, "TrimDeletedItems", 0, deleted_entries);
503 Trace("*** Trim Deleted end ***"); 505 Trace("*** Trim Deleted end ***");
504 return; 506 return;
505 } 507 }
506 508
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 Time::FromInternalValue(last2.get()->Data()->last_used)); 573 Time::FromInternalValue(last2.get()->Data()->last_used));
572 if (last3.get()) 574 if (last3.get())
573 CACHE_UMA(AGE, "HighUseAge", 0, 575 CACHE_UMA(AGE, "HighUseAge", 0,
574 Time::FromInternalValue(last3.get()->Data()->last_used)); 576 Time::FromInternalValue(last3.get()->Data()->last_used));
575 if (last4.get()) 577 if (last4.get())
576 CACHE_UMA(AGE, "DeletedAge", 0, 578 CACHE_UMA(AGE, "DeletedAge", 0,
577 Time::FromInternalValue(last4.get()->Data()->last_used)); 579 Time::FromInternalValue(last4.get()->Data()->last_used));
578 } 580 }
579 581
580 } // namespace disk_cache 582 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/eviction.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698