| 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 #include "net/disk_cache/blockfile/backend_impl.h" | 5 #include "net/disk_cache/blockfile/backend_impl.h" |
| 6 | 6 |
| 7 #include <limits> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 9 #include "base/files/file.h" | 11 #include "base/files/file.h" |
| 10 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 11 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 12 #include "base/hash.h" | 14 #include "base/hash.h" |
| 13 #include "base/location.h" | 15 #include "base/location.h" |
| 14 #include "base/metrics/field_trial.h" | 16 #include "base/metrics/field_trial.h" |
| 15 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
| 16 #include "base/rand_util.h" | 18 #include "base/rand_util.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 46 | 48 |
| 47 // Seems like ~240 MB correspond to less than 50k entries for 99% of the people. | 49 // Seems like ~240 MB correspond to less than 50k entries for 99% of the people. |
| 48 // Note that the actual target is to keep the index table load factor under 55% | 50 // Note that the actual target is to keep the index table load factor under 55% |
| 49 // for most users. | 51 // for most users. |
| 50 const int k64kEntriesStore = 240 * 1000 * 1000; | 52 const int k64kEntriesStore = 240 * 1000 * 1000; |
| 51 const int kBaseTableLen = 64 * 1024; | 53 const int kBaseTableLen = 64 * 1024; |
| 52 | 54 |
| 53 // Avoid trimming the cache for the first 5 minutes (10 timer ticks). | 55 // Avoid trimming the cache for the first 5 minutes (10 timer ticks). |
| 54 const int kTrimDelay = 10; | 56 const int kTrimDelay = 10; |
| 55 | 57 |
| 56 int DesiredIndexTableLen(int32 storage_size) { | 58 int DesiredIndexTableLen(int32_t storage_size) { |
| 57 if (storage_size <= k64kEntriesStore) | 59 if (storage_size <= k64kEntriesStore) |
| 58 return kBaseTableLen; | 60 return kBaseTableLen; |
| 59 if (storage_size <= k64kEntriesStore * 2) | 61 if (storage_size <= k64kEntriesStore * 2) |
| 60 return kBaseTableLen * 2; | 62 return kBaseTableLen * 2; |
| 61 if (storage_size <= k64kEntriesStore * 4) | 63 if (storage_size <= k64kEntriesStore * 4) |
| 62 return kBaseTableLen * 4; | 64 return kBaseTableLen * 4; |
| 63 if (storage_size <= k64kEntriesStore * 8) | 65 if (storage_size <= k64kEntriesStore * 8) |
| 64 return kBaseTableLen * 8; | 66 return kBaseTableLen * 8; |
| 65 | 67 |
| 66 // The biggest storage_size for int32 requires a 4 MB table. | 68 // The biggest storage_size for int32_t requires a 4 MB table. |
| 67 return kBaseTableLen * 16; | 69 return kBaseTableLen * 16; |
| 68 } | 70 } |
| 69 | 71 |
| 70 int MaxStorageSizeForTable(int table_len) { | 72 int MaxStorageSizeForTable(int table_len) { |
| 71 return table_len * (k64kEntriesStore / kBaseTableLen); | 73 return table_len * (k64kEntriesStore / kBaseTableLen); |
| 72 } | 74 } |
| 73 | 75 |
| 74 size_t GetIndexSize(int table_len) { | 76 size_t GetIndexSize(int table_len) { |
| 75 size_t table_size = sizeof(disk_cache::CacheAddr) * table_len; | 77 size_t table_size = sizeof(disk_cache::CacheAddr) * table_len; |
| 76 return sizeof(disk_cache::IndexHeader) + table_size; | 78 return sizeof(disk_cache::IndexHeader) + table_size; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 new_eviction_(false), | 134 new_eviction_(false), |
| 133 first_timer_(true), | 135 first_timer_(true), |
| 134 user_load_(false), | 136 user_load_(false), |
| 135 net_log_(net_log), | 137 net_log_(net_log), |
| 136 done_(true, false), | 138 done_(true, false), |
| 137 ptr_factory_(this) { | 139 ptr_factory_(this) { |
| 138 } | 140 } |
| 139 | 141 |
| 140 BackendImpl::BackendImpl( | 142 BackendImpl::BackendImpl( |
| 141 const base::FilePath& path, | 143 const base::FilePath& path, |
| 142 uint32 mask, | 144 uint32_t mask, |
| 143 const scoped_refptr<base::SingleThreadTaskRunner>& cache_thread, | 145 const scoped_refptr<base::SingleThreadTaskRunner>& cache_thread, |
| 144 net::NetLog* net_log) | 146 net::NetLog* net_log) |
| 145 : background_queue_(this, cache_thread), | 147 : background_queue_(this, cache_thread), |
| 146 path_(path), | 148 path_(path), |
| 147 block_files_(path), | 149 block_files_(path), |
| 148 mask_(mask), | 150 mask_(mask), |
| 149 max_size_(0), | 151 max_size_(0), |
| 150 up_ticks_(0), | 152 up_ticks_(0), |
| 151 cache_type_(net::DISK_CACHE), | 153 cache_type_(net::DISK_CACHE), |
| 152 uma_report_(0), | 154 uma_report_(0), |
| 153 user_flags_(kMask), | 155 user_flags_(kMask), |
| 154 init_(false), | 156 init_(false), |
| 155 restarted_(false), | 157 restarted_(false), |
| 156 unit_test_(false), | 158 unit_test_(false), |
| 157 read_only_(false), | 159 read_only_(false), |
| 158 disabled_(false), | 160 disabled_(false), |
| 159 new_eviction_(false), | 161 new_eviction_(false), |
| 160 first_timer_(true), | 162 first_timer_(true), |
| 161 user_load_(false), | 163 user_load_(false), |
| 162 net_log_(net_log), | 164 net_log_(net_log), |
| 163 done_(true, false), | 165 done_(true, false), |
| 164 ptr_factory_(this) { | 166 ptr_factory_(this) {} |
| 165 } | |
| 166 | 167 |
| 167 BackendImpl::~BackendImpl() { | 168 BackendImpl::~BackendImpl() { |
| 168 if (user_flags_ & kNoRandom) { | 169 if (user_flags_ & kNoRandom) { |
| 169 // This is a unit test, so we want to be strict about not leaking entries | 170 // This is a unit test, so we want to be strict about not leaking entries |
| 170 // and completing all the work. | 171 // and completing all the work. |
| 171 background_queue_.WaitForPendingIO(); | 172 background_queue_.WaitForPendingIO(); |
| 172 } else { | 173 } else { |
| 173 // This is most likely not a test, so we want to do as little work as | 174 // This is most likely not a test, so we want to do as little work as |
| 174 // possible at this time, at the price of leaving dirty entries behind. | 175 // possible at this time, at the price of leaving dirty entries behind. |
| 175 background_queue_.DropPendingIO(); | 176 background_queue_.DropPendingIO(); |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 } | 452 } |
| 452 | 453 |
| 453 void BackendImpl::SyncEndEnumeration(scoped_ptr<Rankings::Iterator> iterator) { | 454 void BackendImpl::SyncEndEnumeration(scoped_ptr<Rankings::Iterator> iterator) { |
| 454 iterator->Reset(); | 455 iterator->Reset(); |
| 455 } | 456 } |
| 456 | 457 |
| 457 void BackendImpl::SyncOnExternalCacheHit(const std::string& key) { | 458 void BackendImpl::SyncOnExternalCacheHit(const std::string& key) { |
| 458 if (disabled_) | 459 if (disabled_) |
| 459 return; | 460 return; |
| 460 | 461 |
| 461 uint32 hash = base::Hash(key); | 462 uint32_t hash = base::Hash(key); |
| 462 bool error; | 463 bool error; |
| 463 EntryImpl* cache_entry = MatchEntry(key, hash, false, Addr(), &error); | 464 EntryImpl* cache_entry = MatchEntry(key, hash, false, Addr(), &error); |
| 464 if (cache_entry) { | 465 if (cache_entry) { |
| 465 if (ENTRY_NORMAL == cache_entry->entry()->Data()->state) { | 466 if (ENTRY_NORMAL == cache_entry->entry()->Data()->state) { |
| 466 UpdateRank(cache_entry, cache_type() == net::SHADER_CACHE); | 467 UpdateRank(cache_entry, cache_type() == net::SHADER_CACHE); |
| 467 } | 468 } |
| 468 cache_entry->Release(); | 469 cache_entry->Release(); |
| 469 } | 470 } |
| 470 } | 471 } |
| 471 | 472 |
| 472 EntryImpl* BackendImpl::OpenEntryImpl(const std::string& key) { | 473 EntryImpl* BackendImpl::OpenEntryImpl(const std::string& key) { |
| 473 if (disabled_) | 474 if (disabled_) |
| 474 return NULL; | 475 return NULL; |
| 475 | 476 |
| 476 TimeTicks start = TimeTicks::Now(); | 477 TimeTicks start = TimeTicks::Now(); |
| 477 uint32 hash = base::Hash(key); | 478 uint32_t hash = base::Hash(key); |
| 478 Trace("Open hash 0x%x", hash); | 479 Trace("Open hash 0x%x", hash); |
| 479 | 480 |
| 480 bool error; | 481 bool error; |
| 481 EntryImpl* cache_entry = MatchEntry(key, hash, false, Addr(), &error); | 482 EntryImpl* cache_entry = MatchEntry(key, hash, false, Addr(), &error); |
| 482 if (cache_entry && ENTRY_NORMAL != cache_entry->entry()->Data()->state) { | 483 if (cache_entry && ENTRY_NORMAL != cache_entry->entry()->Data()->state) { |
| 483 // The entry was already evicted. | 484 // The entry was already evicted. |
| 484 cache_entry->Release(); | 485 cache_entry->Release(); |
| 485 cache_entry = NULL; | 486 cache_entry = NULL; |
| 486 web_fonts_histogram::RecordEvictedEntry(key); | 487 web_fonts_histogram::RecordEvictedEntry(key); |
| 487 } else if (!cache_entry) { | 488 } else if (!cache_entry) { |
| 488 web_fonts_histogram::RecordCacheMiss(key); | 489 web_fonts_histogram::RecordCacheMiss(key); |
| 489 } | 490 } |
| 490 | 491 |
| 491 int current_size = data_->header.num_bytes / (1024 * 1024); | 492 int current_size = data_->header.num_bytes / (1024 * 1024); |
| 492 int64 total_hours = stats_.GetCounter(Stats::TIMER) / 120; | 493 int64_t total_hours = stats_.GetCounter(Stats::TIMER) / 120; |
| 493 int64 no_use_hours = stats_.GetCounter(Stats::LAST_REPORT_TIMER) / 120; | 494 int64_t no_use_hours = stats_.GetCounter(Stats::LAST_REPORT_TIMER) / 120; |
| 494 int64 use_hours = total_hours - no_use_hours; | 495 int64_t use_hours = total_hours - no_use_hours; |
| 495 | 496 |
| 496 if (!cache_entry) { | 497 if (!cache_entry) { |
| 497 CACHE_UMA(AGE_MS, "OpenTime.Miss", 0, start); | 498 CACHE_UMA(AGE_MS, "OpenTime.Miss", 0, start); |
| 498 CACHE_UMA(COUNTS_10000, "AllOpenBySize.Miss", 0, current_size); | 499 CACHE_UMA(COUNTS_10000, "AllOpenBySize.Miss", 0, current_size); |
| 499 CACHE_UMA(HOURS, "AllOpenByTotalHours.Miss", 0, | 500 CACHE_UMA(HOURS, "AllOpenByTotalHours.Miss", 0, |
| 500 static_cast<base::HistogramBase::Sample>(total_hours)); | 501 static_cast<base::HistogramBase::Sample>(total_hours)); |
| 501 CACHE_UMA(HOURS, "AllOpenByUseHours.Miss", 0, | 502 CACHE_UMA(HOURS, "AllOpenByUseHours.Miss", 0, |
| 502 static_cast<base::HistogramBase::Sample>(use_hours)); | 503 static_cast<base::HistogramBase::Sample>(use_hours)); |
| 503 stats_.OnEvent(Stats::OPEN_MISS); | 504 stats_.OnEvent(Stats::OPEN_MISS); |
| 504 return NULL; | 505 return NULL; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 518 stats_.OnEvent(Stats::OPEN_HIT); | 519 stats_.OnEvent(Stats::OPEN_HIT); |
| 519 web_fonts_histogram::RecordCacheHit(cache_entry); | 520 web_fonts_histogram::RecordCacheHit(cache_entry); |
| 520 return cache_entry; | 521 return cache_entry; |
| 521 } | 522 } |
| 522 | 523 |
| 523 EntryImpl* BackendImpl::CreateEntryImpl(const std::string& key) { | 524 EntryImpl* BackendImpl::CreateEntryImpl(const std::string& key) { |
| 524 if (disabled_ || key.empty()) | 525 if (disabled_ || key.empty()) |
| 525 return NULL; | 526 return NULL; |
| 526 | 527 |
| 527 TimeTicks start = TimeTicks::Now(); | 528 TimeTicks start = TimeTicks::Now(); |
| 528 uint32 hash = base::Hash(key); | 529 uint32_t hash = base::Hash(key); |
| 529 Trace("Create hash 0x%x", hash); | 530 Trace("Create hash 0x%x", hash); |
| 530 | 531 |
| 531 scoped_refptr<EntryImpl> parent; | 532 scoped_refptr<EntryImpl> parent; |
| 532 Addr entry_address(data_->table[hash & mask_]); | 533 Addr entry_address(data_->table[hash & mask_]); |
| 533 if (entry_address.is_initialized()) { | 534 if (entry_address.is_initialized()) { |
| 534 // We have an entry already. It could be the one we are looking for, or just | 535 // We have an entry already. It could be the one we are looking for, or just |
| 535 // a hash conflict. | 536 // a hash conflict. |
| 536 bool error; | 537 bool error; |
| 537 EntryImpl* old_entry = MatchEntry(key, hash, false, Addr(), &error); | 538 EntryImpl* old_entry = MatchEntry(key, hash, false, Addr(), &error); |
| 538 if (old_entry) | 539 if (old_entry) |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 static_assert(sizeof(max_bytes) == sizeof(max_size_), | 691 static_assert(sizeof(max_bytes) == sizeof(max_size_), |
| 691 "unsupported int model"); | 692 "unsupported int model"); |
| 692 if (max_bytes < 0) | 693 if (max_bytes < 0) |
| 693 return false; | 694 return false; |
| 694 | 695 |
| 695 // Zero size means use the default. | 696 // Zero size means use the default. |
| 696 if (!max_bytes) | 697 if (!max_bytes) |
| 697 return true; | 698 return true; |
| 698 | 699 |
| 699 // Avoid a DCHECK later on. | 700 // Avoid a DCHECK later on. |
| 700 if (max_bytes >= kint32max - kint32max / 10) | 701 if (max_bytes >= std::numeric_limits<int32_t>::max() - |
| 701 max_bytes = kint32max - kint32max / 10 - 1; | 702 std::numeric_limits<int32_t>::max() / 10) { |
| 703 max_bytes = std::numeric_limits<int32_t>::max() - |
| 704 std::numeric_limits<int32_t>::max() / 10 - 1; |
| 705 } |
| 702 | 706 |
| 703 user_flags_ |= kMaxSize; | 707 user_flags_ |= kMaxSize; |
| 704 max_size_ = max_bytes; | 708 max_size_ = max_bytes; |
| 705 return true; | 709 return true; |
| 706 } | 710 } |
| 707 | 711 |
| 708 void BackendImpl::SetType(net::CacheType type) { | 712 void BackendImpl::SetType(net::CacheType type) { |
| 709 DCHECK_NE(net::MEMORY_CACHE, type); | 713 DCHECK_NE(net::MEMORY_CACHE, type); |
| 710 cache_type_ = type; | 714 cache_type_ = type; |
| 711 } | 715 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 } | 789 } |
| 786 | 790 |
| 787 void BackendImpl::RecoveredEntry(CacheRankingsBlock* rankings) { | 791 void BackendImpl::RecoveredEntry(CacheRankingsBlock* rankings) { |
| 788 Addr address(rankings->Data()->contents); | 792 Addr address(rankings->Data()->contents); |
| 789 EntryImpl* cache_entry = NULL; | 793 EntryImpl* cache_entry = NULL; |
| 790 if (NewEntry(address, &cache_entry)) { | 794 if (NewEntry(address, &cache_entry)) { |
| 791 STRESS_NOTREACHED(); | 795 STRESS_NOTREACHED(); |
| 792 return; | 796 return; |
| 793 } | 797 } |
| 794 | 798 |
| 795 uint32 hash = cache_entry->GetHash(); | 799 uint32_t hash = cache_entry->GetHash(); |
| 796 cache_entry->Release(); | 800 cache_entry->Release(); |
| 797 | 801 |
| 798 // Anything on the table means that this entry is there. | 802 // Anything on the table means that this entry is there. |
| 799 if (data_->table[hash & mask_]) | 803 if (data_->table[hash & mask_]) |
| 800 return; | 804 return; |
| 801 | 805 |
| 802 data_->table[hash & mask_] = address.value(); | 806 data_->table[hash & mask_] = address.value(); |
| 803 FlushIndex(); | 807 FlushIndex(); |
| 804 } | 808 } |
| 805 | 809 |
| 806 void BackendImpl::InternalDoomEntry(EntryImpl* entry) { | 810 void BackendImpl::InternalDoomEntry(EntryImpl* entry) { |
| 807 uint32 hash = entry->GetHash(); | 811 uint32_t hash = entry->GetHash(); |
| 808 std::string key = entry->GetKey(); | 812 std::string key = entry->GetKey(); |
| 809 Addr entry_addr = entry->entry()->address(); | 813 Addr entry_addr = entry->entry()->address(); |
| 810 bool error; | 814 bool error; |
| 811 EntryImpl* parent_entry = MatchEntry(key, hash, true, entry_addr, &error); | 815 EntryImpl* parent_entry = MatchEntry(key, hash, true, entry_addr, &error); |
| 812 CacheAddr child(entry->GetNextAddress()); | 816 CacheAddr child(entry->GetNextAddress()); |
| 813 | 817 |
| 814 Trace("Doom entry 0x%p", entry); | 818 Trace("Doom entry 0x%p", entry); |
| 815 | 819 |
| 816 if (!entry->doomed()) { | 820 if (!entry->doomed()) { |
| 817 // We may have doomed this entry from within MatchEntry. | 821 // We may have doomed this entry from within MatchEntry. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 844 DCHECK(block_files_.IsValid(address)); | 848 DCHECK(block_files_.IsValid(address)); |
| 845 DCHECK(!address.is_separate_file() && address.file_type() == BLOCK_256); | 849 DCHECK(!address.is_separate_file() && address.file_type() == BLOCK_256); |
| 846 | 850 |
| 847 CacheEntryBlock entry(File(address), address); | 851 CacheEntryBlock entry(File(address), address); |
| 848 CHECK(entry.Load()); | 852 CHECK(entry.Load()); |
| 849 return entry.Data()->next; | 853 return entry.Data()->next; |
| 850 } | 854 } |
| 851 | 855 |
| 852 void BackendImpl::NotLinked(EntryImpl* entry) { | 856 void BackendImpl::NotLinked(EntryImpl* entry) { |
| 853 Addr entry_addr = entry->entry()->address(); | 857 Addr entry_addr = entry->entry()->address(); |
| 854 uint32 i = entry->GetHash() & mask_; | 858 uint32_t i = entry->GetHash() & mask_; |
| 855 Addr address(data_->table[i]); | 859 Addr address(data_->table[i]); |
| 856 if (!address.is_initialized()) | 860 if (!address.is_initialized()) |
| 857 return; | 861 return; |
| 858 | 862 |
| 859 for (;;) { | 863 for (;;) { |
| 860 DCHECK(entry_addr.value() != address.value()); | 864 DCHECK(entry_addr.value() != address.value()); |
| 861 address.set_value(GetNextAddr(address)); | 865 address.set_value(GetNextAddr(address)); |
| 862 if (!address.is_initialized()) | 866 if (!address.is_initialized()) |
| 863 break; | 867 break; |
| 864 } | 868 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 EntriesMap::const_iterator it = | 903 EntriesMap::const_iterator it = |
| 900 open_entries_.find(rankings->Data()->contents); | 904 open_entries_.find(rankings->Data()->contents); |
| 901 if (it != open_entries_.end()) { | 905 if (it != open_entries_.end()) { |
| 902 // We have this entry in memory. | 906 // We have this entry in memory. |
| 903 return it->second; | 907 return it->second; |
| 904 } | 908 } |
| 905 | 909 |
| 906 return NULL; | 910 return NULL; |
| 907 } | 911 } |
| 908 | 912 |
| 909 int32 BackendImpl::GetCurrentEntryId() const { | 913 int32_t BackendImpl::GetCurrentEntryId() const { |
| 910 return data_->header.this_id; | 914 return data_->header.this_id; |
| 911 } | 915 } |
| 912 | 916 |
| 913 int BackendImpl::MaxFileSize() const { | 917 int BackendImpl::MaxFileSize() const { |
| 914 return cache_type() == net::PNACL_CACHE ? max_size_ : max_size_ / 8; | 918 return cache_type() == net::PNACL_CACHE ? max_size_ : max_size_ / 8; |
| 915 } | 919 } |
| 916 | 920 |
| 917 void BackendImpl::ModifyStorageSize(int32 old_size, int32 new_size) { | 921 void BackendImpl::ModifyStorageSize(int32_t old_size, int32_t new_size) { |
| 918 if (disabled_ || old_size == new_size) | 922 if (disabled_ || old_size == new_size) |
| 919 return; | 923 return; |
| 920 if (old_size > new_size) | 924 if (old_size > new_size) |
| 921 SubstractStorageSize(old_size - new_size); | 925 SubstractStorageSize(old_size - new_size); |
| 922 else | 926 else |
| 923 AddStorageSize(new_size - old_size); | 927 AddStorageSize(new_size - old_size); |
| 924 | 928 |
| 925 FlushIndex(); | 929 FlushIndex(); |
| 926 | 930 |
| 927 // Update the usage statistics. | 931 // Update the usage statistics. |
| 928 stats_.ModifyStorageStats(old_size, new_size); | 932 stats_.ModifyStorageStats(old_size, new_size); |
| 929 } | 933 } |
| 930 | 934 |
| 931 void BackendImpl::TooMuchStorageRequested(int32 size) { | 935 void BackendImpl::TooMuchStorageRequested(int32_t size) { |
| 932 stats_.ModifyStorageStats(0, size); | 936 stats_.ModifyStorageStats(0, size); |
| 933 } | 937 } |
| 934 | 938 |
| 935 bool BackendImpl::IsAllocAllowed(int current_size, int new_size) { | 939 bool BackendImpl::IsAllocAllowed(int current_size, int new_size) { |
| 936 DCHECK_GT(new_size, current_size); | 940 DCHECK_GT(new_size, current_size); |
| 937 if (user_flags_ & kNoBuffering) | 941 if (user_flags_ & kNoBuffering) |
| 938 return false; | 942 return false; |
| 939 | 943 |
| 940 int to_add = new_size - current_size; | 944 int to_add = new_size - current_size; |
| 941 if (buffer_bytes_ + to_add > MaxBuffersSize()) | 945 if (buffer_bytes_ + to_add > MaxBuffersSize()) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 970 return ptr_factory_.GetWeakPtr(); | 974 return ptr_factory_.GetWeakPtr(); |
| 971 } | 975 } |
| 972 | 976 |
| 973 // We want to remove biases from some histograms so we only send data once per | 977 // We want to remove biases from some histograms so we only send data once per |
| 974 // week. | 978 // week. |
| 975 bool BackendImpl::ShouldReportAgain() { | 979 bool BackendImpl::ShouldReportAgain() { |
| 976 if (uma_report_) | 980 if (uma_report_) |
| 977 return uma_report_ == 2; | 981 return uma_report_ == 2; |
| 978 | 982 |
| 979 uma_report_++; | 983 uma_report_++; |
| 980 int64 last_report = stats_.GetCounter(Stats::LAST_REPORT); | 984 int64_t last_report = stats_.GetCounter(Stats::LAST_REPORT); |
| 981 Time last_time = Time::FromInternalValue(last_report); | 985 Time last_time = Time::FromInternalValue(last_report); |
| 982 if (!last_report || (Time::Now() - last_time).InDays() >= 7) { | 986 if (!last_report || (Time::Now() - last_time).InDays() >= 7) { |
| 983 stats_.SetCounter(Stats::LAST_REPORT, Time::Now().ToInternalValue()); | 987 stats_.SetCounter(Stats::LAST_REPORT, Time::Now().ToInternalValue()); |
| 984 uma_report_++; | 988 uma_report_++; |
| 985 return true; | 989 return true; |
| 986 } | 990 } |
| 987 return false; | 991 return false; |
| 988 } | 992 } |
| 989 | 993 |
| 990 void BackendImpl::FirstEviction() { | 994 void BackendImpl::FirstEviction() { |
| 991 DCHECK(data_->header.create_time); | 995 DCHECK(data_->header.create_time); |
| 992 if (!GetEntryCount()) | 996 if (!GetEntryCount()) |
| 993 return; // This is just for unit tests. | 997 return; // This is just for unit tests. |
| 994 | 998 |
| 995 Time create_time = Time::FromInternalValue(data_->header.create_time); | 999 Time create_time = Time::FromInternalValue(data_->header.create_time); |
| 996 CACHE_UMA(AGE, "FillupAge", 0, create_time); | 1000 CACHE_UMA(AGE, "FillupAge", 0, create_time); |
| 997 | 1001 |
| 998 int64 use_time = stats_.GetCounter(Stats::TIMER); | 1002 int64_t use_time = stats_.GetCounter(Stats::TIMER); |
| 999 CACHE_UMA(HOURS, "FillupTime", 0, static_cast<int>(use_time / 120)); | 1003 CACHE_UMA(HOURS, "FillupTime", 0, static_cast<int>(use_time / 120)); |
| 1000 CACHE_UMA(PERCENTAGE, "FirstHitRatio", 0, stats_.GetHitRatio()); | 1004 CACHE_UMA(PERCENTAGE, "FirstHitRatio", 0, stats_.GetHitRatio()); |
| 1001 | 1005 |
| 1002 if (!use_time) | 1006 if (!use_time) |
| 1003 use_time = 1; | 1007 use_time = 1; |
| 1004 CACHE_UMA(COUNTS_10000, "FirstEntryAccessRate", 0, | 1008 CACHE_UMA(COUNTS_10000, "FirstEntryAccessRate", 0, |
| 1005 static_cast<int>(data_->header.num_entries / use_time)); | 1009 static_cast<int>(data_->header.num_entries / use_time)); |
| 1006 CACHE_UMA(COUNTS, "FirstByteIORate", 0, | 1010 CACHE_UMA(COUNTS, "FirstByteIORate", 0, |
| 1007 static_cast<int>((data_->header.num_bytes / 1024) / use_time)); | 1011 static_cast<int>((data_->header.num_bytes / 1024) / use_time)); |
| 1008 | 1012 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1052 | 1056 |
| 1053 // We transmit positive numbers, instead of direct error codes. | 1057 // We transmit positive numbers, instead of direct error codes. |
| 1054 DCHECK_LE(error, 0); | 1058 DCHECK_LE(error, 0); |
| 1055 CACHE_UMA(CACHE_ERROR, "Error", 0, error * -1); | 1059 CACHE_UMA(CACHE_ERROR, "Error", 0, error * -1); |
| 1056 } | 1060 } |
| 1057 | 1061 |
| 1058 void BackendImpl::OnEvent(Stats::Counters an_event) { | 1062 void BackendImpl::OnEvent(Stats::Counters an_event) { |
| 1059 stats_.OnEvent(an_event); | 1063 stats_.OnEvent(an_event); |
| 1060 } | 1064 } |
| 1061 | 1065 |
| 1062 void BackendImpl::OnRead(int32 bytes) { | 1066 void BackendImpl::OnRead(int32_t bytes) { |
| 1063 DCHECK_GE(bytes, 0); | 1067 DCHECK_GE(bytes, 0); |
| 1064 byte_count_ += bytes; | 1068 byte_count_ += bytes; |
| 1065 if (byte_count_ < 0) | 1069 if (byte_count_ < 0) |
| 1066 byte_count_ = kint32max; | 1070 byte_count_ = std::numeric_limits<int32_t>::max(); |
| 1067 } | 1071 } |
| 1068 | 1072 |
| 1069 void BackendImpl::OnWrite(int32 bytes) { | 1073 void BackendImpl::OnWrite(int32_t bytes) { |
| 1070 // We use the same implementation as OnRead... just log the number of bytes. | 1074 // We use the same implementation as OnRead... just log the number of bytes. |
| 1071 OnRead(bytes); | 1075 OnRead(bytes); |
| 1072 } | 1076 } |
| 1073 | 1077 |
| 1074 void BackendImpl::OnStatsTimer() { | 1078 void BackendImpl::OnStatsTimer() { |
| 1075 if (disabled_) | 1079 if (disabled_) |
| 1076 return; | 1080 return; |
| 1077 | 1081 |
| 1078 stats_.OnEvent(Stats::TIMER); | 1082 stats_.OnEvent(Stats::TIMER); |
| 1079 int64 time = stats_.GetCounter(Stats::TIMER); | 1083 int64_t time = stats_.GetCounter(Stats::TIMER); |
| 1080 int64 current = stats_.GetCounter(Stats::OPEN_ENTRIES); | 1084 int64_t current = stats_.GetCounter(Stats::OPEN_ENTRIES); |
| 1081 | 1085 |
| 1082 // OPEN_ENTRIES is a sampled average of the number of open entries, avoiding | 1086 // OPEN_ENTRIES is a sampled average of the number of open entries, avoiding |
| 1083 // the bias towards 0. | 1087 // the bias towards 0. |
| 1084 if (num_refs_ && (current != num_refs_)) { | 1088 if (num_refs_ && (current != num_refs_)) { |
| 1085 int64 diff = (num_refs_ - current) / 50; | 1089 int64_t diff = (num_refs_ - current) / 50; |
| 1086 if (!diff) | 1090 if (!diff) |
| 1087 diff = num_refs_ > current ? 1 : -1; | 1091 diff = num_refs_ > current ? 1 : -1; |
| 1088 current = current + diff; | 1092 current = current + diff; |
| 1089 stats_.SetCounter(Stats::OPEN_ENTRIES, current); | 1093 stats_.SetCounter(Stats::OPEN_ENTRIES, current); |
| 1090 stats_.SetCounter(Stats::MAX_ENTRIES, max_refs_); | 1094 stats_.SetCounter(Stats::MAX_ENTRIES, max_refs_); |
| 1091 } | 1095 } |
| 1092 | 1096 |
| 1093 CACHE_UMA(COUNTS, "NumberOfReferences", 0, num_refs_); | 1097 CACHE_UMA(COUNTS, "NumberOfReferences", 0, num_refs_); |
| 1094 | 1098 |
| 1095 CACHE_UMA(COUNTS_10000, "EntryAccessRate", 0, entry_count_); | 1099 CACHE_UMA(COUNTS_10000, "EntryAccessRate", 0, entry_count_); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1130 void BackendImpl::SetUpgradeMode() { | 1134 void BackendImpl::SetUpgradeMode() { |
| 1131 user_flags_ |= kUpgradeMode; | 1135 user_flags_ |= kUpgradeMode; |
| 1132 read_only_ = true; | 1136 read_only_ = true; |
| 1133 } | 1137 } |
| 1134 | 1138 |
| 1135 void BackendImpl::SetNewEviction() { | 1139 void BackendImpl::SetNewEviction() { |
| 1136 user_flags_ |= kNewEviction; | 1140 user_flags_ |= kNewEviction; |
| 1137 new_eviction_ = true; | 1141 new_eviction_ = true; |
| 1138 } | 1142 } |
| 1139 | 1143 |
| 1140 void BackendImpl::SetFlags(uint32 flags) { | 1144 void BackendImpl::SetFlags(uint32_t flags) { |
| 1141 user_flags_ |= flags; | 1145 user_flags_ |= flags; |
| 1142 } | 1146 } |
| 1143 | 1147 |
| 1144 void BackendImpl::ClearRefCountForTest() { | 1148 void BackendImpl::ClearRefCountForTest() { |
| 1145 num_refs_ = 0; | 1149 num_refs_ = 0; |
| 1146 } | 1150 } |
| 1147 | 1151 |
| 1148 int BackendImpl::FlushQueueForTest(const CompletionCallback& callback) { | 1152 int BackendImpl::FlushQueueForTest(const CompletionCallback& callback) { |
| 1149 background_queue_.FlushQueue(callback); | 1153 background_queue_.FlushQueue(callback); |
| 1150 return net::ERR_IO_PENDING; | 1154 return net::ERR_IO_PENDING; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1198 if (index_.get() && !disabled_) | 1202 if (index_.get() && !disabled_) |
| 1199 index_->Flush(); | 1203 index_->Flush(); |
| 1200 } | 1204 } |
| 1201 | 1205 |
| 1202 // ------------------------------------------------------------------------ | 1206 // ------------------------------------------------------------------------ |
| 1203 | 1207 |
| 1204 net::CacheType BackendImpl::GetCacheType() const { | 1208 net::CacheType BackendImpl::GetCacheType() const { |
| 1205 return cache_type_; | 1209 return cache_type_; |
| 1206 } | 1210 } |
| 1207 | 1211 |
| 1208 int32 BackendImpl::GetEntryCount() const { | 1212 int32_t BackendImpl::GetEntryCount() const { |
| 1209 if (!index_.get() || disabled_) | 1213 if (!index_.get() || disabled_) |
| 1210 return 0; | 1214 return 0; |
| 1211 // num_entries includes entries already evicted. | 1215 // num_entries includes entries already evicted. |
| 1212 int32 not_deleted = data_->header.num_entries - | 1216 int32_t not_deleted = |
| 1213 data_->header.lru.sizes[Rankings::DELETED]; | 1217 data_->header.num_entries - data_->header.lru.sizes[Rankings::DELETED]; |
| 1214 | 1218 |
| 1215 if (not_deleted < 0) { | 1219 if (not_deleted < 0) { |
| 1216 NOTREACHED(); | 1220 NOTREACHED(); |
| 1217 not_deleted = 0; | 1221 not_deleted = 0; |
| 1218 } | 1222 } |
| 1219 | 1223 |
| 1220 return not_deleted; | 1224 return not_deleted; |
| 1221 } | 1225 } |
| 1222 | 1226 |
| 1223 int BackendImpl::OpenEntry(const std::string& key, Entry** entry, | 1227 int BackendImpl::OpenEntry(const std::string& key, Entry** entry, |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1395 // The maximum cache size will be either set explicitly by the caller, or | 1399 // The maximum cache size will be either set explicitly by the caller, or |
| 1396 // calculated by this code. | 1400 // calculated by this code. |
| 1397 void BackendImpl::AdjustMaxCacheSize(int table_len) { | 1401 void BackendImpl::AdjustMaxCacheSize(int table_len) { |
| 1398 if (max_size_) | 1402 if (max_size_) |
| 1399 return; | 1403 return; |
| 1400 | 1404 |
| 1401 // If table_len is provided, the index file exists. | 1405 // If table_len is provided, the index file exists. |
| 1402 DCHECK(!table_len || data_->header.magic); | 1406 DCHECK(!table_len || data_->header.magic); |
| 1403 | 1407 |
| 1404 // The user is not setting the size, let's figure it out. | 1408 // The user is not setting the size, let's figure it out. |
| 1405 int64 available = base::SysInfo::AmountOfFreeDiskSpace(path_); | 1409 int64_t available = base::SysInfo::AmountOfFreeDiskSpace(path_); |
| 1406 if (available < 0) { | 1410 if (available < 0) { |
| 1407 max_size_ = kDefaultCacheSize; | 1411 max_size_ = kDefaultCacheSize; |
| 1408 return; | 1412 return; |
| 1409 } | 1413 } |
| 1410 | 1414 |
| 1411 if (table_len) | 1415 if (table_len) |
| 1412 available += data_->header.num_bytes; | 1416 available += data_->header.num_bytes; |
| 1413 | 1417 |
| 1414 max_size_ = PreferredCacheSize(available); | 1418 max_size_ = PreferredCacheSize(available); |
| 1415 | 1419 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1474 MappedFile* file = File(address); | 1478 MappedFile* file = File(address); |
| 1475 if (!file) | 1479 if (!file) |
| 1476 return; | 1480 return; |
| 1477 | 1481 |
| 1478 size_t offset = address.start_block() * address.BlockSize() + | 1482 size_t offset = address.start_block() * address.BlockSize() + |
| 1479 kBlockHeaderSize; | 1483 kBlockHeaderSize; |
| 1480 file->Write(data.get(), size, offset); // ignore result. | 1484 file->Write(data.get(), size, offset); // ignore result. |
| 1481 } | 1485 } |
| 1482 | 1486 |
| 1483 void BackendImpl::RestartCache(bool failure) { | 1487 void BackendImpl::RestartCache(bool failure) { |
| 1484 int64 errors = stats_.GetCounter(Stats::FATAL_ERROR); | 1488 int64_t errors = stats_.GetCounter(Stats::FATAL_ERROR); |
| 1485 int64 full_dooms = stats_.GetCounter(Stats::DOOM_CACHE); | 1489 int64_t full_dooms = stats_.GetCounter(Stats::DOOM_CACHE); |
| 1486 int64 partial_dooms = stats_.GetCounter(Stats::DOOM_RECENT); | 1490 int64_t partial_dooms = stats_.GetCounter(Stats::DOOM_RECENT); |
| 1487 int64 last_report = stats_.GetCounter(Stats::LAST_REPORT); | 1491 int64_t last_report = stats_.GetCounter(Stats::LAST_REPORT); |
| 1488 | 1492 |
| 1489 PrepareForRestart(); | 1493 PrepareForRestart(); |
| 1490 if (failure) { | 1494 if (failure) { |
| 1491 DCHECK(!num_refs_); | 1495 DCHECK(!num_refs_); |
| 1492 DCHECK(!open_entries_.size()); | 1496 DCHECK(!open_entries_.size()); |
| 1493 DelayedCacheCleanup(path_); | 1497 DelayedCacheCleanup(path_); |
| 1494 } else { | 1498 } else { |
| 1495 DeleteCache(path_, false); | 1499 DeleteCache(path_, false); |
| 1496 } | 1500 } |
| 1497 | 1501 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1596 address.value()); | 1600 address.value()); |
| 1597 } | 1601 } |
| 1598 | 1602 |
| 1599 open_entries_[address.value()] = cache_entry.get(); | 1603 open_entries_[address.value()] = cache_entry.get(); |
| 1600 | 1604 |
| 1601 cache_entry->BeginLogging(net_log_, false); | 1605 cache_entry->BeginLogging(net_log_, false); |
| 1602 cache_entry.swap(entry); | 1606 cache_entry.swap(entry); |
| 1603 return 0; | 1607 return 0; |
| 1604 } | 1608 } |
| 1605 | 1609 |
| 1606 EntryImpl* BackendImpl::MatchEntry(const std::string& key, uint32 hash, | 1610 EntryImpl* BackendImpl::MatchEntry(const std::string& key, |
| 1607 bool find_parent, Addr entry_addr, | 1611 uint32_t hash, |
| 1612 bool find_parent, |
| 1613 Addr entry_addr, |
| 1608 bool* match_error) { | 1614 bool* match_error) { |
| 1609 Addr address(data_->table[hash & mask_]); | 1615 Addr address(data_->table[hash & mask_]); |
| 1610 scoped_refptr<EntryImpl> cache_entry, parent_entry; | 1616 scoped_refptr<EntryImpl> cache_entry, parent_entry; |
| 1611 EntryImpl* tmp = NULL; | 1617 EntryImpl* tmp = NULL; |
| 1612 bool found = false; | 1618 bool found = false; |
| 1613 std::set<CacheAddr> visited; | 1619 std::set<CacheAddr> visited; |
| 1614 *match_error = false; | 1620 *match_error = false; |
| 1615 | 1621 |
| 1616 for (;;) { | 1622 for (;;) { |
| 1617 if (disabled_) | 1623 if (disabled_) |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1801 entry->SetPointerForInvalidEntry(GetCurrentEntryId()); | 1807 entry->SetPointerForInvalidEntry(GetCurrentEntryId()); |
| 1802 | 1808 |
| 1803 eviction_.OnDoomEntry(entry); | 1809 eviction_.OnDoomEntry(entry); |
| 1804 entry->InternalDoom(); | 1810 entry->InternalDoom(); |
| 1805 | 1811 |
| 1806 if (!new_eviction_) | 1812 if (!new_eviction_) |
| 1807 DecreaseNumEntries(); | 1813 DecreaseNumEntries(); |
| 1808 stats_.OnEvent(Stats::INVALID_ENTRY); | 1814 stats_.OnEvent(Stats::INVALID_ENTRY); |
| 1809 } | 1815 } |
| 1810 | 1816 |
| 1811 void BackendImpl::AddStorageSize(int32 bytes) { | 1817 void BackendImpl::AddStorageSize(int32_t bytes) { |
| 1812 data_->header.num_bytes += bytes; | 1818 data_->header.num_bytes += bytes; |
| 1813 DCHECK_GE(data_->header.num_bytes, 0); | 1819 DCHECK_GE(data_->header.num_bytes, 0); |
| 1814 } | 1820 } |
| 1815 | 1821 |
| 1816 void BackendImpl::SubstractStorageSize(int32 bytes) { | 1822 void BackendImpl::SubstractStorageSize(int32_t bytes) { |
| 1817 data_->header.num_bytes -= bytes; | 1823 data_->header.num_bytes -= bytes; |
| 1818 DCHECK_GE(data_->header.num_bytes, 0); | 1824 DCHECK_GE(data_->header.num_bytes, 0); |
| 1819 } | 1825 } |
| 1820 | 1826 |
| 1821 void BackendImpl::IncreaseNumRefs() { | 1827 void BackendImpl::IncreaseNumRefs() { |
| 1822 num_refs_++; | 1828 num_refs_++; |
| 1823 if (max_refs_ < num_refs_) | 1829 if (max_refs_ < num_refs_) |
| 1824 max_refs_ = num_refs_; | 1830 max_refs_ = num_refs_; |
| 1825 } | 1831 } |
| 1826 | 1832 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1886 static_cast<int>(stats_.GetCounter(Stats::DOOM_RECENT))); | 1892 static_cast<int>(stats_.GetCounter(Stats::DOOM_RECENT))); |
| 1887 stats_.SetCounter(Stats::FATAL_ERROR, 0); | 1893 stats_.SetCounter(Stats::FATAL_ERROR, 0); |
| 1888 stats_.SetCounter(Stats::DOOM_CACHE, 0); | 1894 stats_.SetCounter(Stats::DOOM_CACHE, 0); |
| 1889 stats_.SetCounter(Stats::DOOM_RECENT, 0); | 1895 stats_.SetCounter(Stats::DOOM_RECENT, 0); |
| 1890 | 1896 |
| 1891 int age = (Time::Now() - | 1897 int age = (Time::Now() - |
| 1892 Time::FromInternalValue(data_->header.create_time)).InHours(); | 1898 Time::FromInternalValue(data_->header.create_time)).InHours(); |
| 1893 if (age) | 1899 if (age) |
| 1894 CACHE_UMA(HOURS, "FilesAge", 0, age); | 1900 CACHE_UMA(HOURS, "FilesAge", 0, age); |
| 1895 | 1901 |
| 1896 int64 total_hours = stats_.GetCounter(Stats::TIMER) / 120; | 1902 int64_t total_hours = stats_.GetCounter(Stats::TIMER) / 120; |
| 1897 if (!data_->header.create_time || !data_->header.lru.filled) { | 1903 if (!data_->header.create_time || !data_->header.lru.filled) { |
| 1898 int cause = data_->header.create_time ? 0 : 1; | 1904 int cause = data_->header.create_time ? 0 : 1; |
| 1899 if (!data_->header.lru.filled) | 1905 if (!data_->header.lru.filled) |
| 1900 cause |= 2; | 1906 cause |= 2; |
| 1901 CACHE_UMA(CACHE_ERROR, "ShortReport", 0, cause); | 1907 CACHE_UMA(CACHE_ERROR, "ShortReport", 0, cause); |
| 1902 CACHE_UMA(HOURS, "TotalTimeNotFull", 0, static_cast<int>(total_hours)); | 1908 CACHE_UMA(HOURS, "TotalTimeNotFull", 0, static_cast<int>(total_hours)); |
| 1903 return; | 1909 return; |
| 1904 } | 1910 } |
| 1905 | 1911 |
| 1906 // This is an up to date client that will report FirstEviction() data. After | 1912 // This is an up to date client that will report FirstEviction() data. After |
| 1907 // that event, start reporting this: | 1913 // that event, start reporting this: |
| 1908 | 1914 |
| 1909 CACHE_UMA(HOURS, "TotalTime", 0, static_cast<int>(total_hours)); | 1915 CACHE_UMA(HOURS, "TotalTime", 0, static_cast<int>(total_hours)); |
| 1910 // For any bin in HitRatioByTotalTime, the hit ratio of caches of that total | 1916 // For any bin in HitRatioByTotalTime, the hit ratio of caches of that total |
| 1911 // time is the ratio of that bin's total count to the count in the same bin in | 1917 // time is the ratio of that bin's total count to the count in the same bin in |
| 1912 // the TotalTime histogram. | 1918 // the TotalTime histogram. |
| 1913 if (base::RandInt(0, 99) < hit_ratio_as_percentage) | 1919 if (base::RandInt(0, 99) < hit_ratio_as_percentage) |
| 1914 CACHE_UMA(HOURS, "HitRatioByTotalTime", 0, static_cast<int>(total_hours)); | 1920 CACHE_UMA(HOURS, "HitRatioByTotalTime", 0, static_cast<int>(total_hours)); |
| 1915 | 1921 |
| 1916 int64 use_hours = stats_.GetCounter(Stats::LAST_REPORT_TIMER) / 120; | 1922 int64_t use_hours = stats_.GetCounter(Stats::LAST_REPORT_TIMER) / 120; |
| 1917 stats_.SetCounter(Stats::LAST_REPORT_TIMER, stats_.GetCounter(Stats::TIMER)); | 1923 stats_.SetCounter(Stats::LAST_REPORT_TIMER, stats_.GetCounter(Stats::TIMER)); |
| 1918 | 1924 |
| 1919 // We may see users with no use_hours at this point if this is the first time | 1925 // We may see users with no use_hours at this point if this is the first time |
| 1920 // we are running this code. | 1926 // we are running this code. |
| 1921 if (use_hours) | 1927 if (use_hours) |
| 1922 use_hours = total_hours - use_hours; | 1928 use_hours = total_hours - use_hours; |
| 1923 | 1929 |
| 1924 if (!use_hours || !GetEntryCount() || !data_->header.num_bytes) | 1930 if (!use_hours || !GetEntryCount() || !data_->header.num_bytes) |
| 1925 return; | 1931 return; |
| 1926 | 1932 |
| 1927 CACHE_UMA(HOURS, "UseTime", 0, static_cast<int>(use_hours)); | 1933 CACHE_UMA(HOURS, "UseTime", 0, static_cast<int>(use_hours)); |
| 1928 // For any bin in HitRatioByUseTime, the hit ratio of caches of that use time | 1934 // For any bin in HitRatioByUseTime, the hit ratio of caches of that use time |
| 1929 // is the ratio of that bin's total count to the count in the same bin in the | 1935 // is the ratio of that bin's total count to the count in the same bin in the |
| 1930 // UseTime histogram. | 1936 // UseTime histogram. |
| 1931 if (base::RandInt(0, 99) < hit_ratio_as_percentage) | 1937 if (base::RandInt(0, 99) < hit_ratio_as_percentage) |
| 1932 CACHE_UMA(HOURS, "HitRatioByUseTime", 0, static_cast<int>(use_hours)); | 1938 CACHE_UMA(HOURS, "HitRatioByUseTime", 0, static_cast<int>(use_hours)); |
| 1933 CACHE_UMA(PERCENTAGE, "HitRatio", 0, hit_ratio_as_percentage); | 1939 CACHE_UMA(PERCENTAGE, "HitRatio", 0, hit_ratio_as_percentage); |
| 1934 | 1940 |
| 1935 int64 trim_rate = stats_.GetCounter(Stats::TRIM_ENTRY) / use_hours; | 1941 int64_t trim_rate = stats_.GetCounter(Stats::TRIM_ENTRY) / use_hours; |
| 1936 CACHE_UMA(COUNTS, "TrimRate", 0, static_cast<int>(trim_rate)); | 1942 CACHE_UMA(COUNTS, "TrimRate", 0, static_cast<int>(trim_rate)); |
| 1937 | 1943 |
| 1938 int avg_size = data_->header.num_bytes / GetEntryCount(); | 1944 int avg_size = data_->header.num_bytes / GetEntryCount(); |
| 1939 CACHE_UMA(COUNTS, "EntrySize", 0, avg_size); | 1945 CACHE_UMA(COUNTS, "EntrySize", 0, avg_size); |
| 1940 CACHE_UMA(COUNTS, "EntriesFull", 0, data_->header.num_entries); | 1946 CACHE_UMA(COUNTS, "EntriesFull", 0, data_->header.num_entries); |
| 1941 | 1947 |
| 1942 CACHE_UMA(PERCENTAGE, "IndexLoad", 0, | 1948 CACHE_UMA(PERCENTAGE, "IndexLoad", 0, |
| 1943 data_->header.num_entries * 100 / (mask_ + 1)); | 1949 data_->header.num_entries * 100 / (mask_ + 1)); |
| 1944 | 1950 |
| 1945 int large_entries_bytes = stats_.GetLargeEntriesSize(); | 1951 int large_entries_bytes = stats_.GetLargeEntriesSize(); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2009 if (current_size < GetIndexSize(data_->header.table_len) || | 2015 if (current_size < GetIndexSize(data_->header.table_len) || |
| 2010 data_->header.table_len & (kBaseTableLen - 1)) { | 2016 data_->header.table_len & (kBaseTableLen - 1)) { |
| 2011 LOG(ERROR) << "Corrupt Index file"; | 2017 LOG(ERROR) << "Corrupt Index file"; |
| 2012 return false; | 2018 return false; |
| 2013 } | 2019 } |
| 2014 | 2020 |
| 2015 AdjustMaxCacheSize(data_->header.table_len); | 2021 AdjustMaxCacheSize(data_->header.table_len); |
| 2016 | 2022 |
| 2017 #if !defined(NET_BUILD_STRESS_CACHE) | 2023 #if !defined(NET_BUILD_STRESS_CACHE) |
| 2018 if (data_->header.num_bytes < 0 || | 2024 if (data_->header.num_bytes < 0 || |
| 2019 (max_size_ < kint32max - kDefaultCacheSize && | 2025 (max_size_ < std::numeric_limits<int32_t>::max() - kDefaultCacheSize && |
| 2020 data_->header.num_bytes > max_size_ + kDefaultCacheSize)) { | 2026 data_->header.num_bytes > max_size_ + kDefaultCacheSize)) { |
| 2021 LOG(ERROR) << "Invalid cache (current) size"; | 2027 LOG(ERROR) << "Invalid cache (current) size"; |
| 2022 return false; | 2028 return false; |
| 2023 } | 2029 } |
| 2024 #endif | 2030 #endif |
| 2025 | 2031 |
| 2026 if (data_->header.num_entries < 0) { | 2032 if (data_->header.num_entries < 0) { |
| 2027 LOG(ERROR) << "Invalid number of entries"; | 2033 LOG(ERROR) << "Invalid number of entries"; |
| 2028 return false; | 2034 return false; |
| 2029 } | 2035 } |
| 2030 | 2036 |
| 2031 if (!mask_) | 2037 if (!mask_) |
| 2032 mask_ = data_->header.table_len - 1; | 2038 mask_ = data_->header.table_len - 1; |
| 2033 | 2039 |
| 2034 // Load the table into memory. | 2040 // Load the table into memory. |
| 2035 return index_->Preload(); | 2041 return index_->Preload(); |
| 2036 } | 2042 } |
| 2037 | 2043 |
| 2038 int BackendImpl::CheckAllEntries() { | 2044 int BackendImpl::CheckAllEntries() { |
| 2039 int num_dirty = 0; | 2045 int num_dirty = 0; |
| 2040 int num_entries = 0; | 2046 int num_entries = 0; |
| 2041 DCHECK(mask_ < kuint32max); | 2047 DCHECK(mask_ < std::numeric_limits<uint32_t>::max()); |
| 2042 for (unsigned int i = 0; i <= mask_; i++) { | 2048 for (unsigned int i = 0; i <= mask_; i++) { |
| 2043 Addr address(data_->table[i]); | 2049 Addr address(data_->table[i]); |
| 2044 if (!address.is_initialized()) | 2050 if (!address.is_initialized()) |
| 2045 continue; | 2051 continue; |
| 2046 for (;;) { | 2052 for (;;) { |
| 2047 EntryImpl* tmp; | 2053 EntryImpl* tmp; |
| 2048 int ret = NewEntry(address, &tmp); | 2054 int ret = NewEntry(address, &tmp); |
| 2049 if (ret) { | 2055 if (ret) { |
| 2050 STRESS_NOTREACHED(); | 2056 STRESS_NOTREACHED(); |
| 2051 return ret; | 2057 return ret; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2087 Addr address(data->data_addr[i]); | 2093 Addr address(data->data_addr[i]); |
| 2088 if (address.is_block_file()) | 2094 if (address.is_block_file()) |
| 2089 ok = ok && block_files_.IsValid(address); | 2095 ok = ok && block_files_.IsValid(address); |
| 2090 } | 2096 } |
| 2091 } | 2097 } |
| 2092 | 2098 |
| 2093 return ok && cache_entry->rankings()->VerifyHash(); | 2099 return ok && cache_entry->rankings()->VerifyHash(); |
| 2094 } | 2100 } |
| 2095 | 2101 |
| 2096 int BackendImpl::MaxBuffersSize() { | 2102 int BackendImpl::MaxBuffersSize() { |
| 2097 static int64 total_memory = base::SysInfo::AmountOfPhysicalMemory(); | 2103 static int64_t total_memory = base::SysInfo::AmountOfPhysicalMemory(); |
| 2098 static bool done = false; | 2104 static bool done = false; |
| 2099 | 2105 |
| 2100 if (!done) { | 2106 if (!done) { |
| 2101 const int kMaxBuffersSize = 30 * 1024 * 1024; | 2107 const int kMaxBuffersSize = 30 * 1024 * 1024; |
| 2102 | 2108 |
| 2103 // We want to use up to 2% of the computer's memory. | 2109 // We want to use up to 2% of the computer's memory. |
| 2104 total_memory = total_memory * 2 / 100; | 2110 total_memory = total_memory * 2 / 100; |
| 2105 if (total_memory > kMaxBuffersSize || total_memory <= 0) | 2111 if (total_memory > kMaxBuffersSize || total_memory <= 0) |
| 2106 total_memory = kMaxBuffersSize; | 2112 total_memory = kMaxBuffersSize; |
| 2107 | 2113 |
| 2108 done = true; | 2114 done = true; |
| 2109 } | 2115 } |
| 2110 | 2116 |
| 2111 return static_cast<int>(total_memory); | 2117 return static_cast<int>(total_memory); |
| 2112 } | 2118 } |
| 2113 | 2119 |
| 2114 } // namespace disk_cache | 2120 } // namespace disk_cache |
| OLD | NEW |