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

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

Issue 42682: Disk Cache: Second pass (and final) to allow multiple instances... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 months 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/entry_impl.cc ('k') | net/disk_cache/histogram_macros.h » ('j') | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 ads re-use as a factor to evict 10 // The new (in-development) eviction policy ads re-use as a factor to evict
(...skipping 16 matching lines...) Expand all
27 // list. 27 // list.
28 28
29 #include "net/disk_cache/eviction.h" 29 #include "net/disk_cache/eviction.h"
30 30
31 #include "base/logging.h" 31 #include "base/logging.h"
32 #include "base/message_loop.h" 32 #include "base/message_loop.h"
33 #include "base/string_util.h" 33 #include "base/string_util.h"
34 #include "base/time.h" 34 #include "base/time.h"
35 #include "net/disk_cache/backend_impl.h" 35 #include "net/disk_cache/backend_impl.h"
36 #include "net/disk_cache/entry_impl.h" 36 #include "net/disk_cache/entry_impl.h"
37 #include "net/disk_cache/histogram_macros.h"
37 #include "net/disk_cache/trace.h" 38 #include "net/disk_cache/trace.h"
38 39
39 using base::Time; 40 using base::Time;
40 41
41 // HISTOGRAM_HOURS will collect time related data with a granularity of hours
42 // and normal values of a few months.
43 #define UMA_HISTOGRAM_HOURS UMA_HISTOGRAM_COUNTS_10000
44
45 namespace { 42 namespace {
46 43
47 const int kCleanUpMargin = 1024 * 1024; 44 const int kCleanUpMargin = 1024 * 1024;
48 const int kHighUse = 10; // Reuse count to be on the HIGH_USE list. 45 const int kHighUse = 10; // Reuse count to be on the HIGH_USE list.
49 const int kTargetTime = 24 * 7; // Time to be evicted (hours since last use). 46 const int kTargetTime = 24 * 7; // Time to be evicted (hours since last use).
50 47
51 int LowWaterAdjust(int high_water) { 48 int LowWaterAdjust(int high_water) {
52 if (high_water < kCleanUpMargin) 49 if (high_water < kCleanUpMargin)
53 return 0; 50 return 0;
54 51
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 if (++deleted == 4 && !empty) { 95 if (++deleted == 4 && !empty) {
99 #if defined(OS_WIN) 96 #if defined(OS_WIN)
100 MessageLoop::current()->PostTask(FROM_HERE, 97 MessageLoop::current()->PostTask(FROM_HERE,
101 factory_.NewRunnableMethod(&Eviction::TrimCache, false)); 98 factory_.NewRunnableMethod(&Eviction::TrimCache, false));
102 break; 99 break;
103 #endif 100 #endif
104 } 101 }
105 } 102 }
106 } 103 }
107 104
108 UMA_HISTOGRAM_TIMES("DiskCache.TotalTrimTime", Time::Now() - start); 105 CACHE_UMA(AGE_MS, "TotalTrimTime", 0, start);
109 Trace("*** Trim Cache end ***"); 106 Trace("*** Trim Cache end ***");
110 return; 107 return;
111 } 108 }
112 109
113 void Eviction::UpdateRank(EntryImpl* entry, bool modified) { 110 void Eviction::UpdateRank(EntryImpl* entry, bool modified) {
114 if (new_eviction_) 111 if (new_eviction_)
115 return UpdateRankV2(entry, modified); 112 return UpdateRankV2(entry, modified);
116 113
117 rankings_->UpdateRank(entry->rankings(), modified, GetListForEntry(entry)); 114 rankings_->UpdateRank(entry->rankings(), modified, GetListForEntry(entry));
118 } 115 }
(...skipping 19 matching lines...) Expand all
138 135
139 void Eviction::OnDestroyEntry(EntryImpl* entry) { 136 void Eviction::OnDestroyEntry(EntryImpl* entry) {
140 if (new_eviction_) 137 if (new_eviction_)
141 return OnDestroyEntryV2(entry); 138 return OnDestroyEntryV2(entry);
142 } 139 }
143 140
144 void Eviction::ReportTrimTimes(EntryImpl* entry) { 141 void Eviction::ReportTrimTimes(EntryImpl* entry) {
145 if (first_trim_) { 142 if (first_trim_) {
146 first_trim_ = false; 143 first_trim_ = false;
147 if (backend_->ShouldReportAgain()) { 144 if (backend_->ShouldReportAgain()) {
148 std::string name(StringPrintf("DiskCache.TrimAge_%d", 145 CACHE_UMA(AGE, "TrimAge", header_->experiment, entry->GetLastUsed());
149 header_->experiment));
150 UMA_HISTOGRAM_HOURS(name.c_str(),
151 (Time::Now() - entry->GetLastUsed()).InHours());
152 } 146 }
153 147
154 if (header_->create_time && !header_->lru.filled) { 148 if (header_->create_time && !header_->lru.filled) {
155 // This is the first entry that we have to evict, generate some noise. 149 // This is the first entry that we have to evict, generate some noise.
156 header_->lru.filled = 1; 150 header_->lru.filled = 1;
157 backend_->FirstEviction(); 151 backend_->FirstEviction();
158 } 152 }
159 } 153 }
160 } 154 }
161 155
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 list = kListsToSearch; 252 list = kListsToSearch;
259 } 253 }
260 254
261 if (empty) { 255 if (empty) {
262 TrimDeleted(true); 256 TrimDeleted(true);
263 } else if (header_->lru.sizes[Rankings::DELETED] > header_->num_entries / 4) { 257 } else if (header_->lru.sizes[Rankings::DELETED] > header_->num_entries / 4) {
264 MessageLoop::current()->PostTask(FROM_HERE, 258 MessageLoop::current()->PostTask(FROM_HERE,
265 factory_.NewRunnableMethod(&Eviction::TrimDeleted, empty)); 259 factory_.NewRunnableMethod(&Eviction::TrimDeleted, empty));
266 } 260 }
267 261
268 UMA_HISTOGRAM_TIMES("DiskCache.TotalTrimTime", Time::Now() - start); 262 CACHE_UMA(AGE_MS, "TotalTrimTime", 0, start);
269 Trace("*** Trim Cache end ***"); 263 Trace("*** Trim Cache end ***");
270 return; 264 return;
271 } 265 }
272 266
273 void Eviction::UpdateRankV2(EntryImpl* entry, bool modified) { 267 void Eviction::UpdateRankV2(EntryImpl* entry, bool modified) {
274 rankings_->UpdateRank(entry->rankings(), modified, GetListForEntryV2(entry)); 268 rankings_->UpdateRank(entry->rankings(), modified, GetListForEntryV2(entry));
275 } 269 }
276 270
277 void Eviction::OnOpenEntryV2(EntryImpl* entry) { 271 void Eviction::OnOpenEntryV2(EntryImpl* entry) {
278 EntryStore* info = entry->entry()->Data(); 272 EntryStore* info = entry->entry()->Data();
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 for (int i = 0; (i < 4 || empty) && next.get(); i++) { 362 for (int i = 0; (i < 4 || empty) && next.get(); i++) {
369 node.reset(next.release()); 363 node.reset(next.release());
370 next.reset(rankings_->GetPrev(node.get(), Rankings::DELETED)); 364 next.reset(rankings_->GetPrev(node.get(), Rankings::DELETED));
371 RemoveDeletedNode(node.get()); 365 RemoveDeletedNode(node.get());
372 } 366 }
373 367
374 if (header_->lru.sizes[Rankings::DELETED] > header_->num_entries / 4) 368 if (header_->lru.sizes[Rankings::DELETED] > header_->num_entries / 4)
375 MessageLoop::current()->PostTask(FROM_HERE, 369 MessageLoop::current()->PostTask(FROM_HERE,
376 factory_.NewRunnableMethod(&Eviction::TrimDeleted, false)); 370 factory_.NewRunnableMethod(&Eviction::TrimDeleted, false));
377 371
378 UMA_HISTOGRAM_TIMES("DiskCache.TotalTrimDeletedTime", Time::Now() - start); 372 CACHE_UMA(AGE_MS, "TotalTrimDeletedTime", 0, start);
379 Trace("*** Trim Deleted end ***"); 373 Trace("*** Trim Deleted end ***");
380 return; 374 return;
381 } 375 }
382 376
383 bool Eviction::RemoveDeletedNode(CacheRankingsBlock* node) { 377 bool Eviction::RemoveDeletedNode(CacheRankingsBlock* node) {
384 EntryImpl* entry; 378 EntryImpl* entry;
385 bool dirty; 379 bool dirty;
386 if (backend_->NewEntry(Addr(node->Data()->contents), &entry, &dirty)) { 380 if (backend_->NewEntry(Addr(node->Data()->contents), &entry, &dirty)) {
387 Trace("NewEntry failed on Trim 0x%x", node->address().value()); 381 Trace("NewEntry failed on Trim 0x%x", node->address().value());
388 return false; 382 return false;
(...skipping 25 matching lines...) Expand all
414 header_->lru.sizes[Rankings::DELETED]; 408 header_->lru.sizes[Rankings::DELETED];
415 // Start by having each list to be roughly the same size. 409 // Start by having each list to be roughly the same size.
416 if (header_->lru.sizes[0] > data_entries / 3) 410 if (header_->lru.sizes[0] > data_entries / 3)
417 return 0; 411 return 0;
418 if (header_->lru.sizes[1] > data_entries / 3) 412 if (header_->lru.sizes[1] > data_entries / 3)
419 return 1; 413 return 1;
420 return 2; 414 return 2;
421 } 415 }
422 416
423 } // namespace disk_cache 417 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/entry_impl.cc ('k') | net/disk_cache/histogram_macros.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698