| 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 10 matching lines...) Expand all Loading... |
| 21 // When we have to evict an element, first we try to use the last element from | 21 // When we have to evict an element, first we try to use the last element from |
| 22 // the NO_USE list, then we move to the LOW_USE and only then we evict an entry | 22 // the NO_USE list, then we move to the LOW_USE and only then we evict an entry |
| 23 // from the HIGH_USE. We attempt to keep entries on the cache for at least | 23 // from the HIGH_USE. We attempt to keep entries on the cache for at least |
| 24 // kTargetTime hours (with frequently accessed items stored for longer periods), | 24 // kTargetTime hours (with frequently accessed items stored for longer periods), |
| 25 // but if we cannot do that, we fall-back to keep each list roughly the same | 25 // but if we cannot do that, we fall-back to keep each list roughly the same |
| 26 // size so that we have a chance to see an element again and move it to another | 26 // size so that we have a chance to see an element again and move it to another |
| 27 // list. | 27 // list. |
| 28 | 28 |
| 29 #include "net/disk_cache/blockfile/eviction.h" | 29 #include "net/disk_cache/blockfile/eviction.h" |
| 30 | 30 |
| 31 #include <stdint.h> |
| 32 |
| 33 #include <limits> |
| 34 |
| 31 #include "base/bind.h" | 35 #include "base/bind.h" |
| 32 #include "base/compiler_specific.h" | 36 #include "base/compiler_specific.h" |
| 33 #include "base/location.h" | 37 #include "base/location.h" |
| 34 #include "base/logging.h" | 38 #include "base/logging.h" |
| 35 #include "base/single_thread_task_runner.h" | 39 #include "base/single_thread_task_runner.h" |
| 36 #include "base/strings/string_util.h" | 40 #include "base/strings/string_util.h" |
| 37 #include "base/thread_task_runner_handle.h" | 41 #include "base/thread_task_runner_handle.h" |
| 38 #include "base/time/time.h" | 42 #include "base/time/time.h" |
| 39 #include "net/disk_cache/blockfile/backend_impl.h" | 43 #include "net/disk_cache/blockfile/backend_impl.h" |
| 40 #include "net/disk_cache/blockfile/disk_format.h" | 44 #include "net/disk_cache/blockfile/disk_format.h" |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 } | 405 } |
| 402 | 406 |
| 403 void Eviction::UpdateRankV2(EntryImpl* entry, bool modified) { | 407 void Eviction::UpdateRankV2(EntryImpl* entry, bool modified) { |
| 404 rankings_->UpdateRank(entry->rankings(), modified, GetListForEntryV2(entry)); | 408 rankings_->UpdateRank(entry->rankings(), modified, GetListForEntryV2(entry)); |
| 405 } | 409 } |
| 406 | 410 |
| 407 void Eviction::OnOpenEntryV2(EntryImpl* entry) { | 411 void Eviction::OnOpenEntryV2(EntryImpl* entry) { |
| 408 EntryStore* info = entry->entry()->Data(); | 412 EntryStore* info = entry->entry()->Data(); |
| 409 DCHECK_EQ(ENTRY_NORMAL, info->state); | 413 DCHECK_EQ(ENTRY_NORMAL, info->state); |
| 410 | 414 |
| 411 if (info->reuse_count < kint32max) { | 415 if (info->reuse_count < std::numeric_limits<int32_t>::max()) { |
| 412 info->reuse_count++; | 416 info->reuse_count++; |
| 413 entry->entry()->set_modified(); | 417 entry->entry()->set_modified(); |
| 414 | 418 |
| 415 // We may need to move this to a new list. | 419 // We may need to move this to a new list. |
| 416 if (1 == info->reuse_count) { | 420 if (1 == info->reuse_count) { |
| 417 rankings_->Remove(entry->rankings(), Rankings::NO_USE, true); | 421 rankings_->Remove(entry->rankings(), Rankings::NO_USE, true); |
| 418 rankings_->Insert(entry->rankings(), false, Rankings::LOW_USE); | 422 rankings_->Insert(entry->rankings(), false, Rankings::LOW_USE); |
| 419 entry->entry()->Store(); | 423 entry->entry()->Store(); |
| 420 } else if (kHighUse == info->reuse_count) { | 424 } else if (kHighUse == info->reuse_count) { |
| 421 rankings_->Remove(entry->rankings(), Rankings::LOW_USE, true); | 425 rankings_->Remove(entry->rankings(), Rankings::LOW_USE, true); |
| 422 rankings_->Insert(entry->rankings(), false, Rankings::HIGH_USE); | 426 rankings_->Insert(entry->rankings(), false, Rankings::HIGH_USE); |
| 423 entry->entry()->Store(); | 427 entry->entry()->Store(); |
| 424 } | 428 } |
| 425 } | 429 } |
| 426 } | 430 } |
| 427 | 431 |
| 428 void Eviction::OnCreateEntryV2(EntryImpl* entry) { | 432 void Eviction::OnCreateEntryV2(EntryImpl* entry) { |
| 429 EntryStore* info = entry->entry()->Data(); | 433 EntryStore* info = entry->entry()->Data(); |
| 430 switch (info->state) { | 434 switch (info->state) { |
| 431 case ENTRY_NORMAL: { | 435 case ENTRY_NORMAL: { |
| 432 DCHECK(!info->reuse_count); | 436 DCHECK(!info->reuse_count); |
| 433 DCHECK(!info->refetch_count); | 437 DCHECK(!info->refetch_count); |
| 434 break; | 438 break; |
| 435 }; | 439 }; |
| 436 case ENTRY_EVICTED: { | 440 case ENTRY_EVICTED: { |
| 437 if (info->refetch_count < kint32max) | 441 if (info->refetch_count < std::numeric_limits<int32_t>::max()) |
| 438 info->refetch_count++; | 442 info->refetch_count++; |
| 439 | 443 |
| 440 if (info->refetch_count > kHighUse && info->reuse_count < kHighUse) { | 444 if (info->refetch_count > kHighUse && info->reuse_count < kHighUse) { |
| 441 info->reuse_count = kHighUse; | 445 info->reuse_count = kHighUse; |
| 442 } else { | 446 } else { |
| 443 info->reuse_count++; | 447 info->reuse_count++; |
| 444 } | 448 } |
| 445 info->state = ENTRY_NORMAL; | 449 info->state = ENTRY_NORMAL; |
| 446 entry->entry()->Store(); | 450 entry->entry()->Store(); |
| 447 rankings_->Remove(entry->rankings(), Rankings::DELETED, true); | 451 rankings_->Remove(entry->rankings(), Rankings::DELETED, true); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 Time::FromInternalValue(last2.get()->Data()->last_used)); | 598 Time::FromInternalValue(last2.get()->Data()->last_used)); |
| 595 if (last3.get()) | 599 if (last3.get()) |
| 596 CACHE_UMA(AGE, "HighUseAge", 0, | 600 CACHE_UMA(AGE, "HighUseAge", 0, |
| 597 Time::FromInternalValue(last3.get()->Data()->last_used)); | 601 Time::FromInternalValue(last3.get()->Data()->last_used)); |
| 598 if (last4.get()) | 602 if (last4.get()) |
| 599 CACHE_UMA(AGE, "DeletedAge", 0, | 603 CACHE_UMA(AGE, "DeletedAge", 0, |
| 600 Time::FromInternalValue(last4.get()->Data()->last_used)); | 604 Time::FromInternalValue(last4.get()->Data()->last_used)); |
| 601 } | 605 } |
| 602 | 606 |
| 603 } // namespace disk_cache | 607 } // namespace disk_cache |
| OLD | NEW |