| 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_v3.h" | 5 #include "net/disk_cache/blockfile/backend_impl_v3.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_path.h" | 11 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 11 #include "base/hash.h" | 13 #include "base/hash.h" |
| 12 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 13 #include "base/metrics/field_trial.h" | 15 #include "base/metrics/field_trial.h" |
| 14 #include "base/rand_util.h" | 16 #include "base/rand_util.h" |
| 15 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 static_assert(sizeof(max_bytes) == sizeof(max_size_), | 95 static_assert(sizeof(max_bytes) == sizeof(max_size_), |
| 94 "unsupported int model"); | 96 "unsupported int model"); |
| 95 if (max_bytes < 0) | 97 if (max_bytes < 0) |
| 96 return false; | 98 return false; |
| 97 | 99 |
| 98 // Zero size means use the default. | 100 // Zero size means use the default. |
| 99 if (!max_bytes) | 101 if (!max_bytes) |
| 100 return true; | 102 return true; |
| 101 | 103 |
| 102 // Avoid a DCHECK later on. | 104 // Avoid a DCHECK later on. |
| 103 if (max_bytes >= kint32max - kint32max / 10) | 105 if (max_bytes >= std::numeric_limits<int32_t>::max() - |
| 104 max_bytes = kint32max - kint32max / 10 - 1; | 106 std::numeric_limits<int32_t>::max() / 10) { |
| 107 max_bytes = std::numeric_limits<int32_t>::max() - |
| 108 std::numeric_limits<int32_t>::max() / 10 - 1; |
| 109 } |
| 105 | 110 |
| 106 user_flags_ |= MAX_SIZE; | 111 user_flags_ |= MAX_SIZE; |
| 107 max_size_ = max_bytes; | 112 max_size_ = max_bytes; |
| 108 return true; | 113 return true; |
| 109 } | 114 } |
| 110 | 115 |
| 111 void BackendImplV3::SetType(net::CacheType type) { | 116 void BackendImplV3::SetType(net::CacheType type) { |
| 112 DCHECK_NE(net::MEMORY_CACHE, type); | 117 DCHECK_NE(net::MEMORY_CACHE, type); |
| 113 cache_type_ = type; | 118 cache_type_ = type; |
| 114 } | 119 } |
| 115 | 120 |
| 116 bool BackendImplV3::CreateBlock(FileType block_type, int block_count, | 121 bool BackendImplV3::CreateBlock(FileType block_type, int block_count, |
| 117 Addr* block_address) { | 122 Addr* block_address) { |
| 118 return block_files_.CreateBlock(block_type, block_count, block_address); | 123 return block_files_.CreateBlock(block_type, block_count, block_address); |
| 119 } | 124 } |
| 120 | 125 |
| 121 #if defined(V3_NOT_JUST_YET_READY) | 126 #if defined(V3_NOT_JUST_YET_READY) |
| 122 void BackendImplV3::UpdateRank(EntryImplV3* entry, bool modified) { | 127 void BackendImplV3::UpdateRank(EntryImplV3* entry, bool modified) { |
| 123 if (read_only_ || (!modified && cache_type() == net::SHADER_CACHE)) | 128 if (read_only_ || (!modified && cache_type() == net::SHADER_CACHE)) |
| 124 return; | 129 return; |
| 125 eviction_.UpdateRank(entry, modified); | 130 eviction_.UpdateRank(entry, modified); |
| 126 } | 131 } |
| 127 | 132 |
| 128 void BackendImplV3::InternalDoomEntry(EntryImplV3* entry) { | 133 void BackendImplV3::InternalDoomEntry(EntryImplV3* entry) { |
| 129 uint32 hash = entry->GetHash(); | 134 uint32_t hash = entry->GetHash(); |
| 130 std::string key = entry->GetKey(); | 135 std::string key = entry->GetKey(); |
| 131 Addr entry_addr = entry->entry()->address(); | 136 Addr entry_addr = entry->entry()->address(); |
| 132 bool error; | 137 bool error; |
| 133 EntryImpl* parent_entry = MatchEntry(key, hash, true, entry_addr, &error); | 138 EntryImpl* parent_entry = MatchEntry(key, hash, true, entry_addr, &error); |
| 134 CacheAddr child(entry->GetNextAddress()); | 139 CacheAddr child(entry->GetNextAddress()); |
| 135 | 140 |
| 136 Trace("Doom entry 0x%p", entry); | 141 Trace("Doom entry 0x%p", entry); |
| 137 | 142 |
| 138 if (!entry->doomed()) { | 143 if (!entry->doomed()) { |
| 139 // We may have doomed this entry from within MatchEntry. | 144 // We may have doomed this entry from within MatchEntry. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 return it->second; | 182 return it->second; |
| 178 } | 183 } |
| 179 | 184 |
| 180 return NULL; | 185 return NULL; |
| 181 } | 186 } |
| 182 | 187 |
| 183 int BackendImplV3::MaxFileSize() const { | 188 int BackendImplV3::MaxFileSize() const { |
| 184 return max_size_ / 8; | 189 return max_size_ / 8; |
| 185 } | 190 } |
| 186 | 191 |
| 187 void BackendImplV3::ModifyStorageSize(int32 old_size, int32 new_size) { | 192 void BackendImplV3::ModifyStorageSize(int32_t old_size, int32_t new_size) { |
| 188 if (disabled_ || old_size == new_size) | 193 if (disabled_ || old_size == new_size) |
| 189 return; | 194 return; |
| 190 if (old_size > new_size) | 195 if (old_size > new_size) |
| 191 SubstractStorageSize(old_size - new_size); | 196 SubstractStorageSize(old_size - new_size); |
| 192 else | 197 else |
| 193 AddStorageSize(new_size - old_size); | 198 AddStorageSize(new_size - old_size); |
| 194 | 199 |
| 195 // Update the usage statistics. | 200 // Update the usage statistics. |
| 196 stats_.ModifyStorageStats(old_size, new_size); | 201 stats_.ModifyStorageStats(old_size, new_size); |
| 197 } | 202 } |
| 198 | 203 |
| 199 void BackendImplV3::TooMuchStorageRequested(int32 size) { | 204 void BackendImplV3::TooMuchStorageRequested(int32_t size) { |
| 200 stats_.ModifyStorageStats(0, size); | 205 stats_.ModifyStorageStats(0, size); |
| 201 } | 206 } |
| 202 | 207 |
| 203 bool BackendImplV3::IsAllocAllowed(int current_size, int new_size) { | 208 bool BackendImplV3::IsAllocAllowed(int current_size, int new_size) { |
| 204 DCHECK_GT(new_size, current_size); | 209 DCHECK_GT(new_size, current_size); |
| 205 if (user_flags_ & NO_BUFFERING) | 210 if (user_flags_ & NO_BUFFERING) |
| 206 return false; | 211 return false; |
| 207 | 212 |
| 208 int to_add = new_size - current_size; | 213 int to_add = new_size - current_size; |
| 209 if (buffer_bytes_ + to_add > MaxBuffersSize()) | 214 if (buffer_bytes_ + to_add > MaxBuffersSize()) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 240 } | 245 } |
| 241 | 246 |
| 242 #if defined(V3_NOT_JUST_YET_READY) | 247 #if defined(V3_NOT_JUST_YET_READY) |
| 243 // We want to remove biases from some histograms so we only send data once per | 248 // We want to remove biases from some histograms so we only send data once per |
| 244 // week. | 249 // week. |
| 245 bool BackendImplV3::ShouldReportAgain() { | 250 bool BackendImplV3::ShouldReportAgain() { |
| 246 if (uma_report_) | 251 if (uma_report_) |
| 247 return uma_report_ == 2; | 252 return uma_report_ == 2; |
| 248 | 253 |
| 249 uma_report_++; | 254 uma_report_++; |
| 250 int64 last_report = stats_.GetCounter(Stats::LAST_REPORT); | 255 int64_t last_report = stats_.GetCounter(Stats::LAST_REPORT); |
| 251 Time last_time = Time::FromInternalValue(last_report); | 256 Time last_time = Time::FromInternalValue(last_report); |
| 252 if (!last_report || (Time::Now() - last_time).InDays() >= 7) { | 257 if (!last_report || (Time::Now() - last_time).InDays() >= 7) { |
| 253 stats_.SetCounter(Stats::LAST_REPORT, Time::Now().ToInternalValue()); | 258 stats_.SetCounter(Stats::LAST_REPORT, Time::Now().ToInternalValue()); |
| 254 uma_report_++; | 259 uma_report_++; |
| 255 return true; | 260 return true; |
| 256 } | 261 } |
| 257 return false; | 262 return false; |
| 258 } | 263 } |
| 259 | 264 |
| 260 void BackendImplV3::FirstEviction() { | 265 void BackendImplV3::FirstEviction() { |
| 261 IndexHeaderV3* header = index_.header(); | 266 IndexHeaderV3* header = index_.header(); |
| 262 header->flags |= CACHE_EVICTED; | 267 header->flags |= CACHE_EVICTED; |
| 263 DCHECK(header->create_time); | 268 DCHECK(header->create_time); |
| 264 if (!GetEntryCount()) | 269 if (!GetEntryCount()) |
| 265 return; // This is just for unit tests. | 270 return; // This is just for unit tests. |
| 266 | 271 |
| 267 Time create_time = Time::FromInternalValue(header->create_time); | 272 Time create_time = Time::FromInternalValue(header->create_time); |
| 268 CACHE_UMA(AGE, "FillupAge", create_time); | 273 CACHE_UMA(AGE, "FillupAge", create_time); |
| 269 | 274 |
| 270 int64 use_time = stats_.GetCounter(Stats::TIMER); | 275 int64_t use_time = stats_.GetCounter(Stats::TIMER); |
| 271 CACHE_UMA(HOURS, "FillupTime", static_cast<int>(use_time / 120)); | 276 CACHE_UMA(HOURS, "FillupTime", static_cast<int>(use_time / 120)); |
| 272 CACHE_UMA(PERCENTAGE, "FirstHitRatio", stats_.GetHitRatio()); | 277 CACHE_UMA(PERCENTAGE, "FirstHitRatio", stats_.GetHitRatio()); |
| 273 | 278 |
| 274 if (!use_time) | 279 if (!use_time) |
| 275 use_time = 1; | 280 use_time = 1; |
| 276 CACHE_UMA(COUNTS_10000, "FirstEntryAccessRate", | 281 CACHE_UMA(COUNTS_10000, "FirstEntryAccessRate", |
| 277 static_cast<int>(header->num_entries / use_time)); | 282 static_cast<int>(header->num_entries / use_time)); |
| 278 CACHE_UMA(COUNTS, "FirstByteIORate", | 283 CACHE_UMA(COUNTS, "FirstByteIORate", |
| 279 static_cast<int>((header->num_bytes / 1024) / use_time)); | 284 static_cast<int>((header->num_bytes / 1024) / use_time)); |
| 280 | 285 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 295 header->num_high_use_entries * 100 / header->num_entries); | 300 header->num_high_use_entries * 100 / header->num_entries); |
| 296 } | 301 } |
| 297 | 302 |
| 298 stats_.ResetRatios(); | 303 stats_.ResetRatios(); |
| 299 } | 304 } |
| 300 | 305 |
| 301 void BackendImplV3::OnEvent(Stats::Counters an_event) { | 306 void BackendImplV3::OnEvent(Stats::Counters an_event) { |
| 302 stats_.OnEvent(an_event); | 307 stats_.OnEvent(an_event); |
| 303 } | 308 } |
| 304 | 309 |
| 305 void BackendImplV3::OnRead(int32 bytes) { | 310 void BackendImplV3::OnRead(int32_t bytes) { |
| 306 DCHECK_GE(bytes, 0); | 311 DCHECK_GE(bytes, 0); |
| 307 byte_count_ += bytes; | 312 byte_count_ += bytes; |
| 308 if (byte_count_ < 0) | 313 if (byte_count_ < 0) |
| 309 byte_count_ = kint32max; | 314 byte_count_ = std::numeric_limits<int32_t>::max(); |
| 310 } | 315 } |
| 311 | 316 |
| 312 void BackendImplV3::OnWrite(int32 bytes) { | 317 void BackendImplV3::OnWrite(int32_t bytes) { |
| 313 // We use the same implementation as OnRead... just log the number of bytes. | 318 // We use the same implementation as OnRead... just log the number of bytes. |
| 314 OnRead(bytes); | 319 OnRead(bytes); |
| 315 } | 320 } |
| 316 | 321 |
| 317 void BackendImplV3::OnTimerTick() { | 322 void BackendImplV3::OnTimerTick() { |
| 318 stats_.OnEvent(Stats::TIMER); | 323 stats_.OnEvent(Stats::TIMER); |
| 319 int64 time = stats_.GetCounter(Stats::TIMER); | 324 int64_t time = stats_.GetCounter(Stats::TIMER); |
| 320 int64 current = stats_.GetCounter(Stats::OPEN_ENTRIES); | 325 int64_t current = stats_.GetCounter(Stats::OPEN_ENTRIES); |
| 321 | 326 |
| 322 // OPEN_ENTRIES is a sampled average of the number of open entries, avoiding | 327 // OPEN_ENTRIES is a sampled average of the number of open entries, avoiding |
| 323 // the bias towards 0. | 328 // the bias towards 0. |
| 324 if (num_refs_ && (current != num_refs_)) { | 329 if (num_refs_ && (current != num_refs_)) { |
| 325 int64 diff = (num_refs_ - current) / 50; | 330 int64_t diff = (num_refs_ - current) / 50; |
| 326 if (!diff) | 331 if (!diff) |
| 327 diff = num_refs_ > current ? 1 : -1; | 332 diff = num_refs_ > current ? 1 : -1; |
| 328 current = current + diff; | 333 current = current + diff; |
| 329 stats_.SetCounter(Stats::OPEN_ENTRIES, current); | 334 stats_.SetCounter(Stats::OPEN_ENTRIES, current); |
| 330 stats_.SetCounter(Stats::MAX_ENTRIES, max_refs_); | 335 stats_.SetCounter(Stats::MAX_ENTRIES, max_refs_); |
| 331 } | 336 } |
| 332 | 337 |
| 333 CACHE_UMA(COUNTS, "NumberOfReferences", num_refs_); | 338 CACHE_UMA(COUNTS, "NumberOfReferences", num_refs_); |
| 334 | 339 |
| 335 CACHE_UMA(COUNTS_10000, "EntryAccessRate", entry_count_); | 340 CACHE_UMA(COUNTS_10000, "EntryAccessRate", entry_count_); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 361 void BackendImplV3::SetUpgradeMode() { | 366 void BackendImplV3::SetUpgradeMode() { |
| 362 user_flags_ |= UPGRADE_MODE; | 367 user_flags_ |= UPGRADE_MODE; |
| 363 read_only_ = true; | 368 read_only_ = true; |
| 364 } | 369 } |
| 365 | 370 |
| 366 void BackendImplV3::SetNewEviction() { | 371 void BackendImplV3::SetNewEviction() { |
| 367 user_flags_ |= EVICTION_V2; | 372 user_flags_ |= EVICTION_V2; |
| 368 lru_eviction_ = false; | 373 lru_eviction_ = false; |
| 369 } | 374 } |
| 370 | 375 |
| 371 void BackendImplV3::SetFlags(uint32 flags) { | 376 void BackendImplV3::SetFlags(uint32_t flags) { |
| 372 user_flags_ |= flags; | 377 user_flags_ |= flags; |
| 373 } | 378 } |
| 374 | 379 |
| 375 int BackendImplV3::FlushQueueForTest(const CompletionCallback& callback) { | 380 int BackendImplV3::FlushQueueForTest(const CompletionCallback& callback) { |
| 376 background_queue_.FlushQueue(callback); | 381 background_queue_.FlushQueue(callback); |
| 377 return net::ERR_IO_PENDING; | 382 return net::ERR_IO_PENDING; |
| 378 } | 383 } |
| 379 | 384 |
| 380 void BackendImplV3::TrimForTest(bool empty) { | 385 void BackendImplV3::TrimForTest(bool empty) { |
| 381 eviction_.SetTestMode(); | 386 eviction_.SetTestMode(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 410 | 415 |
| 411 return CheckAllEntries(); | 416 return CheckAllEntries(); |
| 412 } | 417 } |
| 413 | 418 |
| 414 // ------------------------------------------------------------------------ | 419 // ------------------------------------------------------------------------ |
| 415 | 420 |
| 416 net::CacheType BackendImplV3::GetCacheType() const { | 421 net::CacheType BackendImplV3::GetCacheType() const { |
| 417 return cache_type_; | 422 return cache_type_; |
| 418 } | 423 } |
| 419 | 424 |
| 420 int32 BackendImplV3::GetEntryCount() const { | 425 int32_t BackendImplV3::GetEntryCount() const { |
| 421 if (disabled_) | 426 if (disabled_) |
| 422 return 0; | 427 return 0; |
| 423 DCHECK(init_); | 428 DCHECK(init_); |
| 424 return index_.header()->num_entries; | 429 return index_.header()->num_entries; |
| 425 } | 430 } |
| 426 | 431 |
| 427 int BackendImplV3::OpenEntry(const std::string& key, Entry** entry, | 432 int BackendImplV3::OpenEntry(const std::string& key, Entry** entry, |
| 428 const CompletionCallback& callback) { | 433 const CompletionCallback& callback) { |
| 429 if (disabled_) | 434 if (disabled_) |
| 430 return NULL; | 435 return NULL; |
| 431 | 436 |
| 432 TimeTicks start = TimeTicks::Now(); | 437 TimeTicks start = TimeTicks::Now(); |
| 433 uint32 hash = base::Hash(key); | 438 uint32_t hash = base::Hash(key); |
| 434 Trace("Open hash 0x%x", hash); | 439 Trace("Open hash 0x%x", hash); |
| 435 | 440 |
| 436 bool error; | 441 bool error; |
| 437 EntryImpl* cache_entry = MatchEntry(key, hash, false, Addr(), &error); | 442 EntryImpl* cache_entry = MatchEntry(key, hash, false, Addr(), &error); |
| 438 if (cache_entry && ENTRY_NORMAL != cache_entry->entry()->Data()->state) { | 443 if (cache_entry && ENTRY_NORMAL != cache_entry->entry()->Data()->state) { |
| 439 // The entry was already evicted. | 444 // The entry was already evicted. |
| 440 cache_entry->Release(); | 445 cache_entry->Release(); |
| 441 cache_entry = NULL; | 446 cache_entry = NULL; |
| 442 } | 447 } |
| 443 | 448 |
| 444 int current_size = data_->header.num_bytes / (1024 * 1024); | 449 int current_size = data_->header.num_bytes / (1024 * 1024); |
| 445 int64 total_hours = stats_.GetCounter(Stats::TIMER) / 120; | 450 int64_t total_hours = stats_.GetCounter(Stats::TIMER) / 120; |
| 446 int64 no_use_hours = stats_.GetCounter(Stats::LAST_REPORT_TIMER) / 120; | 451 int64_t no_use_hours = stats_.GetCounter(Stats::LAST_REPORT_TIMER) / 120; |
| 447 int64 use_hours = total_hours - no_use_hours; | 452 int64_t use_hours = total_hours - no_use_hours; |
| 448 | 453 |
| 449 if (!cache_entry) { | 454 if (!cache_entry) { |
| 450 CACHE_UMA(AGE_MS, "OpenTime.Miss", 0, start); | 455 CACHE_UMA(AGE_MS, "OpenTime.Miss", 0, start); |
| 451 CACHE_UMA(COUNTS_10000, "AllOpenBySize.Miss", 0, current_size); | 456 CACHE_UMA(COUNTS_10000, "AllOpenBySize.Miss", 0, current_size); |
| 452 CACHE_UMA(HOURS, "AllOpenByTotalHours.Miss", 0, total_hours); | 457 CACHE_UMA(HOURS, "AllOpenByTotalHours.Miss", 0, total_hours); |
| 453 CACHE_UMA(HOURS, "AllOpenByUseHours.Miss", 0, use_hours); | 458 CACHE_UMA(HOURS, "AllOpenByUseHours.Miss", 0, use_hours); |
| 454 stats_.OnEvent(Stats::OPEN_MISS); | 459 stats_.OnEvent(Stats::OPEN_MISS); |
| 455 return NULL; | 460 return NULL; |
| 456 } | 461 } |
| 457 | 462 |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 item.second = "Blockfile Cache"; | 715 item.second = "Blockfile Cache"; |
| 711 stats->push_back(item); | 716 stats->push_back(item); |
| 712 | 717 |
| 713 stats_.GetItems(stats); | 718 stats_.GetItems(stats); |
| 714 } | 719 } |
| 715 | 720 |
| 716 void BackendImplV3::OnExternalCacheHit(const std::string& key) { | 721 void BackendImplV3::OnExternalCacheHit(const std::string& key) { |
| 717 if (disabled_) | 722 if (disabled_) |
| 718 return; | 723 return; |
| 719 | 724 |
| 720 uint32 hash = base::Hash(key); | 725 uint32_t hash = base::Hash(key); |
| 721 bool error; | 726 bool error; |
| 722 EntryImpl* cache_entry = MatchEntry(key, hash, false, Addr(), &error); | 727 EntryImpl* cache_entry = MatchEntry(key, hash, false, Addr(), &error); |
| 723 if (cache_entry) { | 728 if (cache_entry) { |
| 724 if (ENTRY_NORMAL == cache_entry->entry()->Data()->state) { | 729 if (ENTRY_NORMAL == cache_entry->entry()->Data()->state) { |
| 725 UpdateRank(cache_entry, cache_type() == net::SHADER_CACHE); | 730 UpdateRank(cache_entry, cache_type() == net::SHADER_CACHE); |
| 726 } | 731 } |
| 727 cache_entry->Release(); | 732 cache_entry->Release(); |
| 728 } | 733 } |
| 729 } | 734 } |
| 730 | 735 |
| 731 // ------------------------------------------------------------------------ | 736 // ------------------------------------------------------------------------ |
| 732 | 737 |
| 733 // The maximum cache size will be either set explicitly by the caller, or | 738 // The maximum cache size will be either set explicitly by the caller, or |
| 734 // calculated by this code. | 739 // calculated by this code. |
| 735 void BackendImplV3::AdjustMaxCacheSize(int table_len) { | 740 void BackendImplV3::AdjustMaxCacheSize(int table_len) { |
| 736 if (max_size_) | 741 if (max_size_) |
| 737 return; | 742 return; |
| 738 | 743 |
| 739 // If table_len is provided, the index file exists. | 744 // If table_len is provided, the index file exists. |
| 740 DCHECK(!table_len || data_->header.magic); | 745 DCHECK(!table_len || data_->header.magic); |
| 741 | 746 |
| 742 // The user is not setting the size, let's figure it out. | 747 // The user is not setting the size, let's figure it out. |
| 743 int64 available = base::SysInfo::AmountOfFreeDiskSpace(path_); | 748 int64_t available = base::SysInfo::AmountOfFreeDiskSpace(path_); |
| 744 if (available < 0) { | 749 if (available < 0) { |
| 745 max_size_ = kDefaultCacheSize; | 750 max_size_ = kDefaultCacheSize; |
| 746 return; | 751 return; |
| 747 } | 752 } |
| 748 | 753 |
| 749 if (table_len) | 754 if (table_len) |
| 750 available += data_->header.num_bytes; | 755 available += data_->header.num_bytes; |
| 751 | 756 |
| 752 max_size_ = PreferedCacheSize(available); | 757 max_size_ = PreferedCacheSize(available); |
| 753 | 758 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 MappedFile* file = File(address); | 820 MappedFile* file = File(address); |
| 816 if (!file) | 821 if (!file) |
| 817 return; | 822 return; |
| 818 | 823 |
| 819 size_t offset = address.start_block() * address.BlockSize() + | 824 size_t offset = address.start_block() * address.BlockSize() + |
| 820 kBlockHeaderSize; | 825 kBlockHeaderSize; |
| 821 file->Write(data.get(), size, offset); // ignore result. | 826 file->Write(data.get(), size, offset); // ignore result. |
| 822 } | 827 } |
| 823 | 828 |
| 824 void BackendImplV3::RestartCache(bool failure) { | 829 void BackendImplV3::RestartCache(bool failure) { |
| 825 int64 errors = stats_.GetCounter(Stats::FATAL_ERROR); | 830 int64_t errors = stats_.GetCounter(Stats::FATAL_ERROR); |
| 826 int64 full_dooms = stats_.GetCounter(Stats::DOOM_CACHE); | 831 int64_t full_dooms = stats_.GetCounter(Stats::DOOM_CACHE); |
| 827 int64 partial_dooms = stats_.GetCounter(Stats::DOOM_RECENT); | 832 int64_t partial_dooms = stats_.GetCounter(Stats::DOOM_RECENT); |
| 828 int64 last_report = stats_.GetCounter(Stats::LAST_REPORT); | 833 int64_t last_report = stats_.GetCounter(Stats::LAST_REPORT); |
| 829 | 834 |
| 830 PrepareForRestart(); | 835 PrepareForRestart(); |
| 831 if (failure) { | 836 if (failure) { |
| 832 DCHECK(!num_refs_); | 837 DCHECK(!num_refs_); |
| 833 DCHECK(!open_entries_.size()); | 838 DCHECK(!open_entries_.size()); |
| 834 DelayedCacheCleanup(path_); | 839 DelayedCacheCleanup(path_); |
| 835 } else { | 840 } else { |
| 836 DeleteCache(path_, false); | 841 DeleteCache(path_, false); |
| 837 } | 842 } |
| 838 | 843 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 address.value()); | 963 address.value()); |
| 959 } | 964 } |
| 960 | 965 |
| 961 open_entries_[address.value()] = cache_entry.get(); | 966 open_entries_[address.value()] = cache_entry.get(); |
| 962 | 967 |
| 963 cache_entry->BeginLogging(net_log_, false); | 968 cache_entry->BeginLogging(net_log_, false); |
| 964 cache_entry.swap(entry); | 969 cache_entry.swap(entry); |
| 965 return 0; | 970 return 0; |
| 966 } | 971 } |
| 967 | 972 |
| 968 void BackendImplV3::AddStorageSize(int32 bytes) { | 973 void BackendImplV3::AddStorageSize(int32_t bytes) { |
| 969 data_->header.num_bytes += bytes; | 974 data_->header.num_bytes += bytes; |
| 970 DCHECK_GE(data_->header.num_bytes, 0); | 975 DCHECK_GE(data_->header.num_bytes, 0); |
| 971 } | 976 } |
| 972 | 977 |
| 973 void BackendImplV3::SubstractStorageSize(int32 bytes) { | 978 void BackendImplV3::SubstractStorageSize(int32_t bytes) { |
| 974 data_->header.num_bytes -= bytes; | 979 data_->header.num_bytes -= bytes; |
| 975 DCHECK_GE(data_->header.num_bytes, 0); | 980 DCHECK_GE(data_->header.num_bytes, 0); |
| 976 } | 981 } |
| 977 | 982 |
| 978 void BackendImplV3::IncreaseNumRefs() { | 983 void BackendImplV3::IncreaseNumRefs() { |
| 979 num_refs_++; | 984 num_refs_++; |
| 980 if (max_refs_ < num_refs_) | 985 if (max_refs_ < num_refs_) |
| 981 max_refs_ = num_refs_; | 986 max_refs_ = num_refs_; |
| 982 } | 987 } |
| 983 | 988 |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1255 CACHE_UMA(COUNTS_10000, "TotalFatalErrors", | 1260 CACHE_UMA(COUNTS_10000, "TotalFatalErrors", |
| 1256 static_cast<int>(stats_.GetCounter(Stats::FATAL_ERROR))); | 1261 static_cast<int>(stats_.GetCounter(Stats::FATAL_ERROR))); |
| 1257 CACHE_UMA(COUNTS_10000, "TotalDoomCache", | 1262 CACHE_UMA(COUNTS_10000, "TotalDoomCache", |
| 1258 static_cast<int>(stats_.GetCounter(Stats::DOOM_CACHE))); | 1263 static_cast<int>(stats_.GetCounter(Stats::DOOM_CACHE))); |
| 1259 CACHE_UMA(COUNTS_10000, "TotalDoomRecentEntries", | 1264 CACHE_UMA(COUNTS_10000, "TotalDoomRecentEntries", |
| 1260 static_cast<int>(stats_.GetCounter(Stats::DOOM_RECENT))); | 1265 static_cast<int>(stats_.GetCounter(Stats::DOOM_RECENT))); |
| 1261 stats_.SetCounter(Stats::FATAL_ERROR, 0); | 1266 stats_.SetCounter(Stats::FATAL_ERROR, 0); |
| 1262 stats_.SetCounter(Stats::DOOM_CACHE, 0); | 1267 stats_.SetCounter(Stats::DOOM_CACHE, 0); |
| 1263 stats_.SetCounter(Stats::DOOM_RECENT, 0); | 1268 stats_.SetCounter(Stats::DOOM_RECENT, 0); |
| 1264 | 1269 |
| 1265 int64 total_hours = stats_.GetCounter(Stats::TIMER) / 120; | 1270 int64_t total_hours = stats_.GetCounter(Stats::TIMER) / 120; |
| 1266 if (!(header->flags & CACHE_EVICTED)) { | 1271 if (!(header->flags & CACHE_EVICTED)) { |
| 1267 CACHE_UMA(HOURS, "TotalTimeNotFull", static_cast<int>(total_hours)); | 1272 CACHE_UMA(HOURS, "TotalTimeNotFull", static_cast<int>(total_hours)); |
| 1268 return; | 1273 return; |
| 1269 } | 1274 } |
| 1270 | 1275 |
| 1271 // This is an up to date client that will report FirstEviction() data. After | 1276 // This is an up to date client that will report FirstEviction() data. After |
| 1272 // that event, start reporting this: | 1277 // that event, start reporting this: |
| 1273 | 1278 |
| 1274 CACHE_UMA(HOURS, "TotalTime", static_cast<int>(total_hours)); | 1279 CACHE_UMA(HOURS, "TotalTime", static_cast<int>(total_hours)); |
| 1275 | 1280 |
| 1276 int64 use_hours = stats_.GetCounter(Stats::LAST_REPORT_TIMER) / 120; | 1281 int64_t use_hours = stats_.GetCounter(Stats::LAST_REPORT_TIMER) / 120; |
| 1277 stats_.SetCounter(Stats::LAST_REPORT_TIMER, stats_.GetCounter(Stats::TIMER)); | 1282 stats_.SetCounter(Stats::LAST_REPORT_TIMER, stats_.GetCounter(Stats::TIMER)); |
| 1278 | 1283 |
| 1279 // We may see users with no use_hours at this point if this is the first time | 1284 // We may see users with no use_hours at this point if this is the first time |
| 1280 // we are running this code. | 1285 // we are running this code. |
| 1281 if (use_hours) | 1286 if (use_hours) |
| 1282 use_hours = total_hours - use_hours; | 1287 use_hours = total_hours - use_hours; |
| 1283 | 1288 |
| 1284 if (!use_hours || !GetEntryCount() || !header->num_bytes) | 1289 if (!use_hours || !GetEntryCount() || !header->num_bytes) |
| 1285 return; | 1290 return; |
| 1286 | 1291 |
| 1287 CACHE_UMA(HOURS, "UseTime", static_cast<int>(use_hours)); | 1292 CACHE_UMA(HOURS, "UseTime", static_cast<int>(use_hours)); |
| 1288 | 1293 |
| 1289 int64 trim_rate = stats_.GetCounter(Stats::TRIM_ENTRY) / use_hours; | 1294 int64_t trim_rate = stats_.GetCounter(Stats::TRIM_ENTRY) / use_hours; |
| 1290 CACHE_UMA(COUNTS, "TrimRate", static_cast<int>(trim_rate)); | 1295 CACHE_UMA(COUNTS, "TrimRate", static_cast<int>(trim_rate)); |
| 1291 | 1296 |
| 1292 int avg_size = header->num_bytes / GetEntryCount(); | 1297 int avg_size = header->num_bytes / GetEntryCount(); |
| 1293 CACHE_UMA(COUNTS, "EntrySize", avg_size); | 1298 CACHE_UMA(COUNTS, "EntrySize", avg_size); |
| 1294 CACHE_UMA(COUNTS, "EntriesFull", header->num_entries); | 1299 CACHE_UMA(COUNTS, "EntriesFull", header->num_entries); |
| 1295 | 1300 |
| 1296 int large_entries_bytes = stats_.GetLargeEntriesSize(); | 1301 int large_entries_bytes = stats_.GetLargeEntriesSize(); |
| 1297 int large_ratio = large_entries_bytes * 100 / header->num_bytes; | 1302 int large_ratio = large_entries_bytes * 100 / header->num_bytes; |
| 1298 CACHE_UMA(PERCENTAGE, "LargeEntriesRatio", large_ratio); | 1303 CACHE_UMA(PERCENTAGE, "LargeEntriesRatio", large_ratio); |
| 1299 | 1304 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1361 if (current_size < GetIndexSize(data_->header.table_len) || | 1366 if (current_size < GetIndexSize(data_->header.table_len) || |
| 1362 data_->header.table_len & (kBaseTableLen - 1)) { | 1367 data_->header.table_len & (kBaseTableLen - 1)) { |
| 1363 LOG(ERROR) << "Corrupt Index file"; | 1368 LOG(ERROR) << "Corrupt Index file"; |
| 1364 return false; | 1369 return false; |
| 1365 } | 1370 } |
| 1366 | 1371 |
| 1367 AdjustMaxCacheSize(data_->header.table_len); | 1372 AdjustMaxCacheSize(data_->header.table_len); |
| 1368 | 1373 |
| 1369 #if !defined(NET_BUILD_STRESS_CACHE) | 1374 #if !defined(NET_BUILD_STRESS_CACHE) |
| 1370 if (data_->header.num_bytes < 0 || | 1375 if (data_->header.num_bytes < 0 || |
| 1371 (max_size_ < kint32max - kDefaultCacheSize && | 1376 (max_size_ < std::numeric_limits<int32_t>::max() - kDefaultCacheSize && |
| 1372 data_->header.num_bytes > max_size_ + kDefaultCacheSize)) { | 1377 data_->header.num_bytes > max_size_ + kDefaultCacheSize)) { |
| 1373 LOG(ERROR) << "Invalid cache (current) size"; | 1378 LOG(ERROR) << "Invalid cache (current) size"; |
| 1374 return false; | 1379 return false; |
| 1375 } | 1380 } |
| 1376 #endif | 1381 #endif |
| 1377 | 1382 |
| 1378 if (data_->header.num_entries < 0) { | 1383 if (data_->header.num_entries < 0) { |
| 1379 LOG(ERROR) << "Invalid number of entries"; | 1384 LOG(ERROR) << "Invalid number of entries"; |
| 1380 return false; | 1385 return false; |
| 1381 } | 1386 } |
| 1382 | 1387 |
| 1383 if (!mask_) | 1388 if (!mask_) |
| 1384 mask_ = data_->header.table_len - 1; | 1389 mask_ = data_->header.table_len - 1; |
| 1385 | 1390 |
| 1386 // Load the table into memory with a single read. | 1391 // Load the table into memory with a single read. |
| 1387 scoped_ptr<char[]> buf(new char[current_size]); | 1392 scoped_ptr<char[]> buf(new char[current_size]); |
| 1388 return index_->Read(buf.get(), current_size, 0); | 1393 return index_->Read(buf.get(), current_size, 0); |
| 1389 } | 1394 } |
| 1390 | 1395 |
| 1391 int BackendImplV3::CheckAllEntries() { | 1396 int BackendImplV3::CheckAllEntries() { |
| 1392 int num_dirty = 0; | 1397 int num_dirty = 0; |
| 1393 int num_entries = 0; | 1398 int num_entries = 0; |
| 1394 DCHECK(mask_ < kuint32max); | 1399 DCHECK(mask_ < std::numeric_limits<uint32_t>::max()); |
| 1395 for (unsigned int i = 0; i <= mask_; i++) { | 1400 for (unsigned int i = 0; i <= mask_; i++) { |
| 1396 Addr address(data_->table[i]); | 1401 Addr address(data_->table[i]); |
| 1397 if (!address.is_initialized()) | 1402 if (!address.is_initialized()) |
| 1398 continue; | 1403 continue; |
| 1399 for (;;) { | 1404 for (;;) { |
| 1400 EntryImpl* tmp; | 1405 EntryImpl* tmp; |
| 1401 int ret = NewEntry(address, &tmp); | 1406 int ret = NewEntry(address, &tmp); |
| 1402 if (ret) { | 1407 if (ret) { |
| 1403 STRESS_NOTREACHED(); | 1408 STRESS_NOTREACHED(); |
| 1404 return ret; | 1409 return ret; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1440 Addr address(data->data_addr[i]); | 1445 Addr address(data->data_addr[i]); |
| 1441 if (address.is_block_file()) | 1446 if (address.is_block_file()) |
| 1442 ok = ok && block_files_.IsValid(address); | 1447 ok = ok && block_files_.IsValid(address); |
| 1443 } | 1448 } |
| 1444 } | 1449 } |
| 1445 | 1450 |
| 1446 return ok && cache_entry->rankings()->VerifyHash(); | 1451 return ok && cache_entry->rankings()->VerifyHash(); |
| 1447 } | 1452 } |
| 1448 | 1453 |
| 1449 int BackendImplV3::MaxBuffersSize() { | 1454 int BackendImplV3::MaxBuffersSize() { |
| 1450 static int64 total_memory = base::SysInfo::AmountOfPhysicalMemory(); | 1455 static int64_t total_memory = base::SysInfo::AmountOfPhysicalMemory(); |
| 1451 static bool done = false; | 1456 static bool done = false; |
| 1452 | 1457 |
| 1453 if (!done) { | 1458 if (!done) { |
| 1454 const int kMaxBuffersSize = 30 * 1024 * 1024; | 1459 const int kMaxBuffersSize = 30 * 1024 * 1024; |
| 1455 | 1460 |
| 1456 // We want to use up to 2% of the computer's memory. | 1461 // We want to use up to 2% of the computer's memory. |
| 1457 total_memory = total_memory * 2 / 100; | 1462 total_memory = total_memory * 2 / 100; |
| 1458 if (total_memory > kMaxBuffersSize || total_memory <= 0) | 1463 if (total_memory > kMaxBuffersSize || total_memory <= 0) |
| 1459 total_memory = kMaxBuffersSize; | 1464 total_memory = kMaxBuffersSize; |
| 1460 | 1465 |
| 1461 done = true; | 1466 done = true; |
| 1462 } | 1467 } |
| 1463 | 1468 |
| 1464 return static_cast<int>(total_memory); | 1469 return static_cast<int>(total_memory); |
| 1465 } | 1470 } |
| 1466 | 1471 |
| 1467 #endif // defined(V3_NOT_JUST_YET_READY). | 1472 #endif // defined(V3_NOT_JUST_YET_READY). |
| 1468 | 1473 |
| 1469 bool BackendImplV3::IsAllocAllowed(int current_size, int new_size) { | 1474 bool BackendImplV3::IsAllocAllowed(int current_size, int new_size) { |
| 1470 return false; | 1475 return false; |
| 1471 } | 1476 } |
| 1472 | 1477 |
| 1473 net::CacheType BackendImplV3::GetCacheType() const { | 1478 net::CacheType BackendImplV3::GetCacheType() const { |
| 1474 return cache_type_; | 1479 return cache_type_; |
| 1475 } | 1480 } |
| 1476 | 1481 |
| 1477 int32 BackendImplV3::GetEntryCount() const { | 1482 int32_t BackendImplV3::GetEntryCount() const { |
| 1478 return 0; | 1483 return 0; |
| 1479 } | 1484 } |
| 1480 | 1485 |
| 1481 int BackendImplV3::OpenEntry(const std::string& key, Entry** entry, | 1486 int BackendImplV3::OpenEntry(const std::string& key, Entry** entry, |
| 1482 const CompletionCallback& callback) { | 1487 const CompletionCallback& callback) { |
| 1483 return net::ERR_FAILED; | 1488 return net::ERR_FAILED; |
| 1484 } | 1489 } |
| 1485 | 1490 |
| 1486 int BackendImplV3::CreateEntry(const std::string& key, Entry** entry, | 1491 int BackendImplV3::CreateEntry(const std::string& key, Entry** entry, |
| 1487 const CompletionCallback& callback) { | 1492 const CompletionCallback& callback) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1530 } | 1535 } |
| 1531 | 1536 |
| 1532 void BackendImplV3::OnExternalCacheHit(const std::string& key) { | 1537 void BackendImplV3::OnExternalCacheHit(const std::string& key) { |
| 1533 NOTIMPLEMENTED(); | 1538 NOTIMPLEMENTED(); |
| 1534 } | 1539 } |
| 1535 | 1540 |
| 1536 void BackendImplV3::CleanupCache() { | 1541 void BackendImplV3::CleanupCache() { |
| 1537 } | 1542 } |
| 1538 | 1543 |
| 1539 } // namespace disk_cache | 1544 } // namespace disk_cache |
| OLD | NEW |