OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 17 matching lines...) Expand all Loading... |
28 | 28 |
29 #include "net/disk_cache/eviction.h" | 29 #include "net/disk_cache/eviction.h" |
30 | 30 |
31 #include "base/bind.h" | 31 #include "base/bind.h" |
32 #include "base/compiler_specific.h" | 32 #include "base/compiler_specific.h" |
33 #include "base/logging.h" | 33 #include "base/logging.h" |
34 #include "base/message_loop.h" | 34 #include "base/message_loop.h" |
35 #include "base/string_util.h" | 35 #include "base/string_util.h" |
36 #include "base/time.h" | 36 #include "base/time.h" |
37 #include "net/disk_cache/backend_impl.h" | 37 #include "net/disk_cache/backend_impl.h" |
| 38 #include "net/disk_cache/disk_format.h" |
38 #include "net/disk_cache/entry_impl.h" | 39 #include "net/disk_cache/entry_impl.h" |
39 #include "net/disk_cache/experiments.h" | 40 #include "net/disk_cache/experiments.h" |
40 #include "net/disk_cache/histogram_macros.h" | 41 #include "net/disk_cache/histogram_macros.h" |
41 #include "net/disk_cache/trace.h" | 42 #include "net/disk_cache/trace.h" |
42 | 43 |
43 using base::Time; | 44 using base::Time; |
44 using base::TimeTicks; | 45 using base::TimeTicks; |
45 | 46 |
46 namespace { | 47 namespace { |
47 | 48 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 // Do NOT use node as an iterator after this point. | 136 // Do NOT use node as an iterator after this point. |
136 rankings_->TrackRankingsBlock(node.get(), false); | 137 rankings_->TrackRankingsBlock(node.get(), false); |
137 if (EvictEntry(node.get(), empty, Rankings::NO_USE) && !test_mode_) | 138 if (EvictEntry(node.get(), empty, Rankings::NO_USE) && !test_mode_) |
138 deleted_entries++; | 139 deleted_entries++; |
139 | 140 |
140 if (!empty && test_mode_) | 141 if (!empty && test_mode_) |
141 break; | 142 break; |
142 } | 143 } |
143 if (!empty && (deleted_entries > 20 || | 144 if (!empty && (deleted_entries > 20 || |
144 (TimeTicks::Now() - start).InMilliseconds() > 20)) { | 145 (TimeTicks::Now() - start).InMilliseconds() > 20)) { |
145 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | 146 base::MessageLoop::current()->PostTask( |
146 &Eviction::TrimCache, ptr_factory_.GetWeakPtr(), false)); | 147 FROM_HERE, |
| 148 base::Bind(&Eviction::TrimCache, ptr_factory_.GetWeakPtr(), false)); |
147 break; | 149 break; |
148 } | 150 } |
149 } | 151 } |
150 | 152 |
151 if (empty) { | 153 if (empty) { |
152 CACHE_UMA(AGE_MS, "TotalClearTimeV1", 0, start); | 154 CACHE_UMA(AGE_MS, "TotalClearTimeV1", 0, start); |
153 } else { | 155 } else { |
154 CACHE_UMA(AGE_MS, "TotalTrimTimeV1", 0, start); | 156 CACHE_UMA(AGE_MS, "TotalTrimTimeV1", 0, start); |
155 } | 157 } |
156 CACHE_UMA(COUNTS, "TrimItemsV1", 0, deleted_entries); | 158 CACHE_UMA(COUNTS, "TrimItemsV1", 0, deleted_entries); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 DCHECK(test_mode_ && new_eviction_); | 204 DCHECK(test_mode_ && new_eviction_); |
203 TrimDeleted(empty); | 205 TrimDeleted(empty); |
204 } | 206 } |
205 | 207 |
206 void Eviction::PostDelayedTrim() { | 208 void Eviction::PostDelayedTrim() { |
207 // Prevent posting multiple tasks. | 209 // Prevent posting multiple tasks. |
208 if (delay_trim_) | 210 if (delay_trim_) |
209 return; | 211 return; |
210 delay_trim_ = true; | 212 delay_trim_ = true; |
211 trim_delays_++; | 213 trim_delays_++; |
212 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 214 base::MessageLoop::current()->PostDelayedTask( |
| 215 FROM_HERE, |
213 base::Bind(&Eviction::DelayedTrim, ptr_factory_.GetWeakPtr()), | 216 base::Bind(&Eviction::DelayedTrim, ptr_factory_.GetWeakPtr()), |
214 base::TimeDelta::FromMilliseconds(1000)); | 217 base::TimeDelta::FromMilliseconds(1000)); |
215 } | 218 } |
216 | 219 |
217 void Eviction::DelayedTrim() { | 220 void Eviction::DelayedTrim() { |
218 delay_trim_ = false; | 221 delay_trim_ = false; |
219 if (trim_delays_ < kMaxDelayedTrims && backend_->IsLoaded()) | 222 if (trim_delays_ < kMaxDelayedTrims && backend_->IsLoaded()) |
220 return PostDelayedTrim(); | 223 return PostDelayedTrim(); |
221 | 224 |
222 TrimCache(false); | 225 TrimCache(false); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 } else { | 293 } else { |
291 entry->DeleteEntryData(false); | 294 entry->DeleteEntryData(false); |
292 EntryStore* info = entry->entry()->Data(); | 295 EntryStore* info = entry->entry()->Data(); |
293 DCHECK_EQ(ENTRY_NORMAL, info->state); | 296 DCHECK_EQ(ENTRY_NORMAL, info->state); |
294 | 297 |
295 rankings_->Remove(entry->rankings(), GetListForEntryV2(entry), true); | 298 rankings_->Remove(entry->rankings(), GetListForEntryV2(entry), true); |
296 info->state = ENTRY_EVICTED; | 299 info->state = ENTRY_EVICTED; |
297 entry->entry()->Store(); | 300 entry->entry()->Store(); |
298 rankings_->Insert(entry->rankings(), true, Rankings::DELETED); | 301 rankings_->Insert(entry->rankings(), true, Rankings::DELETED); |
299 } | 302 } |
300 if (!empty) { | 303 if (!empty) |
301 backend_->OnEvent(Stats::TRIM_ENTRY); | 304 backend_->OnEvent(Stats::TRIM_ENTRY); |
302 | 305 |
303 static const char gajs[] = "http://www.google-analytics.com/ga.js"; | |
304 if (!entry->GetKey().compare(gajs)) | |
305 backend_->OnEvent(Stats::GAJS_EVICTED); | |
306 } | |
307 entry->Release(); | 306 entry->Release(); |
308 | 307 |
309 return true; | 308 return true; |
310 } | 309 } |
311 | 310 |
312 // ----------------------------------------------------------------------- | 311 // ----------------------------------------------------------------------- |
313 | 312 |
314 void Eviction::TrimCacheV2(bool empty) { | 313 void Eviction::TrimCacheV2(bool empty) { |
315 Trace("*** Trim Cache ***"); | 314 Trace("*** Trim Cache ***"); |
316 trimming_ = true; | 315 trimming_ = true; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 // Do NOT use node as an iterator after this point. | 357 // Do NOT use node as an iterator after this point. |
359 rankings_->TrackRankingsBlock(node.get(), false); | 358 rankings_->TrackRankingsBlock(node.get(), false); |
360 if (EvictEntry(node.get(), empty, static_cast<Rankings::List>(list))) | 359 if (EvictEntry(node.get(), empty, static_cast<Rankings::List>(list))) |
361 deleted_entries++; | 360 deleted_entries++; |
362 | 361 |
363 if (!empty && test_mode_) | 362 if (!empty && test_mode_) |
364 break; | 363 break; |
365 } | 364 } |
366 if (!empty && (deleted_entries > 20 || | 365 if (!empty && (deleted_entries > 20 || |
367 (TimeTicks::Now() - start).InMilliseconds() > 20)) { | 366 (TimeTicks::Now() - start).InMilliseconds() > 20)) { |
368 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | 367 base::MessageLoop::current()->PostTask( |
369 &Eviction::TrimCache, ptr_factory_.GetWeakPtr(), false)); | 368 FROM_HERE, |
| 369 base::Bind(&Eviction::TrimCache, ptr_factory_.GetWeakPtr(), false)); |
370 break; | 370 break; |
371 } | 371 } |
372 } | 372 } |
373 if (!empty) | 373 if (!empty) |
374 list = kListsToSearch; | 374 list = kListsToSearch; |
375 } | 375 } |
376 | 376 |
377 if (empty) { | 377 if (empty) { |
378 TrimDeleted(true); | 378 TrimDeleted(true); |
379 } else if (ShouldTrimDeleted()) { | 379 } else if (ShouldTrimDeleted()) { |
380 MessageLoop::current()->PostTask(FROM_HERE, | 380 base::MessageLoop::current()->PostTask( |
| 381 FROM_HERE, |
381 base::Bind(&Eviction::TrimDeleted, ptr_factory_.GetWeakPtr(), empty)); | 382 base::Bind(&Eviction::TrimDeleted, ptr_factory_.GetWeakPtr(), empty)); |
382 } | 383 } |
383 | 384 |
384 if (empty) { | 385 if (empty) { |
385 CACHE_UMA(AGE_MS, "TotalClearTimeV2", 0, start); | 386 CACHE_UMA(AGE_MS, "TotalClearTimeV2", 0, start); |
386 } else { | 387 } else { |
387 CACHE_UMA(AGE_MS, "TotalTrimTimeV2", 0, start); | 388 CACHE_UMA(AGE_MS, "TotalTrimTimeV2", 0, start); |
388 } | 389 } |
389 CACHE_UMA(COUNTS, "TrimItemsV2", 0, deleted_entries); | 390 CACHE_UMA(COUNTS, "TrimItemsV2", 0, deleted_entries); |
390 | 391 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 (TimeTicks::Now() - start).InMilliseconds() < 20))) { | 503 (TimeTicks::Now() - start).InMilliseconds() < 20))) { |
503 node.reset(next.release()); | 504 node.reset(next.release()); |
504 next.reset(rankings_->GetPrev(node.get(), Rankings::DELETED)); | 505 next.reset(rankings_->GetPrev(node.get(), Rankings::DELETED)); |
505 if (RemoveDeletedNode(node.get())) | 506 if (RemoveDeletedNode(node.get())) |
506 deleted_entries++; | 507 deleted_entries++; |
507 if (test_mode_) | 508 if (test_mode_) |
508 break; | 509 break; |
509 } | 510 } |
510 | 511 |
511 if (deleted_entries && !empty && ShouldTrimDeleted()) { | 512 if (deleted_entries && !empty && ShouldTrimDeleted()) { |
512 MessageLoop::current()->PostTask(FROM_HERE, | 513 base::MessageLoop::current()->PostTask( |
| 514 FROM_HERE, |
513 base::Bind(&Eviction::TrimDeleted, ptr_factory_.GetWeakPtr(), false)); | 515 base::Bind(&Eviction::TrimDeleted, ptr_factory_.GetWeakPtr(), false)); |
514 } | 516 } |
515 | 517 |
516 CACHE_UMA(AGE_MS, "TotalTrimDeletedTime", 0, start); | 518 CACHE_UMA(AGE_MS, "TotalTrimDeletedTime", 0, start); |
517 CACHE_UMA(COUNTS, "TrimDeletedItems", 0, deleted_entries); | 519 CACHE_UMA(COUNTS, "TrimDeletedItems", 0, deleted_entries); |
518 Trace("*** Trim Deleted end ***"); | 520 Trace("*** Trim Deleted end ***"); |
519 return; | 521 return; |
520 } | 522 } |
521 | 523 |
522 bool Eviction::RemoveDeletedNode(CacheRankingsBlock* node) { | 524 bool Eviction::RemoveDeletedNode(CacheRankingsBlock* node) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 Time::FromInternalValue(last2.get()->Data()->last_used)); | 588 Time::FromInternalValue(last2.get()->Data()->last_used)); |
587 if (last3.get()) | 589 if (last3.get()) |
588 CACHE_UMA(AGE, "HighUseAge", 0, | 590 CACHE_UMA(AGE, "HighUseAge", 0, |
589 Time::FromInternalValue(last3.get()->Data()->last_used)); | 591 Time::FromInternalValue(last3.get()->Data()->last_used)); |
590 if (last4.get()) | 592 if (last4.get()) |
591 CACHE_UMA(AGE, "DeletedAge", 0, | 593 CACHE_UMA(AGE, "DeletedAge", 0, |
592 Time::FromInternalValue(last4.get()->Data()->last_used)); | 594 Time::FromInternalValue(last4.get()->Data()->last_used)); |
593 } | 595 } |
594 | 596 |
595 } // namespace disk_cache | 597 } // namespace disk_cache |
OLD | NEW |