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

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

Issue 7765006: Disk cache: Don't evict anything for the first five (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/disk_cache/backend_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/backend_impl.h" 5 #include "net/disk_cache/backend_impl.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
(...skipping 29 matching lines...) Expand all
40 const char* kIndexName = "index"; 40 const char* kIndexName = "index";
41 const int kMaxOldFolders = 100; 41 const int kMaxOldFolders = 100;
42 42
43 // Seems like ~240 MB correspond to less than 50k entries for 99% of the people. 43 // Seems like ~240 MB correspond to less than 50k entries for 99% of the people.
44 // Note that the actual target is to keep the index table load factor under 55% 44 // Note that the actual target is to keep the index table load factor under 55%
45 // for most users. 45 // for most users.
46 const int k64kEntriesStore = 240 * 1000 * 1000; 46 const int k64kEntriesStore = 240 * 1000 * 1000;
47 const int kBaseTableLen = 64 * 1024; 47 const int kBaseTableLen = 64 * 1024;
48 const int kDefaultCacheSize = 80 * 1024 * 1024; 48 const int kDefaultCacheSize = 80 * 1024 * 1024;
49 49
50 // Avoid trimming the cache for the first 5 minutes (10 timer ticks).
51 const int kTrimDelay = 10;
52
50 int DesiredIndexTableLen(int32 storage_size) { 53 int DesiredIndexTableLen(int32 storage_size) {
51 if (storage_size <= k64kEntriesStore) 54 if (storage_size <= k64kEntriesStore)
52 return kBaseTableLen; 55 return kBaseTableLen;
53 if (storage_size <= k64kEntriesStore * 2) 56 if (storage_size <= k64kEntriesStore * 2)
54 return kBaseTableLen * 2; 57 return kBaseTableLen * 2;
55 if (storage_size <= k64kEntriesStore * 4) 58 if (storage_size <= k64kEntriesStore * 4)
56 return kBaseTableLen * 4; 59 return kBaseTableLen * 4;
57 if (storage_size <= k64kEntriesStore * 8) 60 if (storage_size <= k64kEntriesStore * 8)
58 return kBaseTableLen * 8; 61 return kBaseTableLen * 8;
59 62
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 // ------------------------------------------------------------------------ 362 // ------------------------------------------------------------------------
360 363
361 BackendImpl::BackendImpl(const FilePath& path, 364 BackendImpl::BackendImpl(const FilePath& path,
362 base::MessageLoopProxy* cache_thread, 365 base::MessageLoopProxy* cache_thread,
363 net::NetLog* net_log) 366 net::NetLog* net_log)
364 : ALLOW_THIS_IN_INITIALIZER_LIST(background_queue_(this, cache_thread)), 367 : ALLOW_THIS_IN_INITIALIZER_LIST(background_queue_(this, cache_thread)),
365 path_(path), 368 path_(path),
366 block_files_(path), 369 block_files_(path),
367 mask_(0), 370 mask_(0),
368 max_size_(0), 371 max_size_(0),
369 io_delay_(0), 372 up_ticks_(0),
370 cache_type_(net::DISK_CACHE), 373 cache_type_(net::DISK_CACHE),
371 uma_report_(0), 374 uma_report_(0),
372 user_flags_(0), 375 user_flags_(0),
373 init_(false), 376 init_(false),
374 restarted_(false), 377 restarted_(false),
375 unit_test_(false), 378 unit_test_(false),
376 read_only_(false), 379 read_only_(false),
377 disabled_(false), 380 disabled_(false),
378 new_eviction_(false), 381 new_eviction_(false),
379 first_timer_(true), 382 first_timer_(true),
380 net_log_(net_log), 383 net_log_(net_log),
381 done_(true, false), 384 done_(true, false),
382 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)), 385 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)),
383 ALLOW_THIS_IN_INITIALIZER_LIST(ptr_factory_(this)) { 386 ALLOW_THIS_IN_INITIALIZER_LIST(ptr_factory_(this)) {
384 } 387 }
385 388
386 BackendImpl::BackendImpl(const FilePath& path, 389 BackendImpl::BackendImpl(const FilePath& path,
387 uint32 mask, 390 uint32 mask,
388 base::MessageLoopProxy* cache_thread, 391 base::MessageLoopProxy* cache_thread,
389 net::NetLog* net_log) 392 net::NetLog* net_log)
390 : ALLOW_THIS_IN_INITIALIZER_LIST(background_queue_(this, cache_thread)), 393 : ALLOW_THIS_IN_INITIALIZER_LIST(background_queue_(this, cache_thread)),
391 path_(path), 394 path_(path),
392 block_files_(path), 395 block_files_(path),
393 mask_(mask), 396 mask_(mask),
394 max_size_(0), 397 max_size_(0),
395 io_delay_(0), 398 up_ticks_(0),
396 cache_type_(net::DISK_CACHE), 399 cache_type_(net::DISK_CACHE),
397 uma_report_(0), 400 uma_report_(0),
398 user_flags_(kMask), 401 user_flags_(kMask),
399 init_(false), 402 init_(false),
400 restarted_(false), 403 restarted_(false),
401 unit_test_(false), 404 unit_test_(false),
402 read_only_(false), 405 read_only_(false),
403 disabled_(false), 406 disabled_(false),
404 new_eviction_(false), 407 new_eviction_(false),
405 first_timer_(true), 408 first_timer_(true),
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 } 971 }
969 972
970 void BackendImpl::OnEntryDestroyBegin(Addr address) { 973 void BackendImpl::OnEntryDestroyBegin(Addr address) {
971 EntriesMap::iterator it = open_entries_.find(address.value()); 974 EntriesMap::iterator it = open_entries_.find(address.value());
972 if (it != open_entries_.end()) 975 if (it != open_entries_.end())
973 open_entries_.erase(it); 976 open_entries_.erase(it);
974 } 977 }
975 978
976 void BackendImpl::OnEntryDestroyEnd() { 979 void BackendImpl::OnEntryDestroyEnd() {
977 DecreaseNumRefs(); 980 DecreaseNumRefs();
978 if (data_->header.num_bytes > max_size_ && !read_only_) 981 if (data_->header.num_bytes > max_size_ && !read_only_ &&
982 (up_ticks_ > kTrimDelay || user_flags_ & disk_cache::kNoRandom))
979 eviction_.TrimCache(false); 983 eviction_.TrimCache(false);
980 } 984 }
981 985
982 EntryImpl* BackendImpl::GetOpenEntry(CacheRankingsBlock* rankings) const { 986 EntryImpl* BackendImpl::GetOpenEntry(CacheRankingsBlock* rankings) const {
983 DCHECK(rankings->HasData()); 987 DCHECK(rankings->HasData());
984 EntriesMap::const_iterator it = 988 EntriesMap::const_iterator it =
985 open_entries_.find(rankings->Data()->contents); 989 open_entries_.find(rankings->Data()->contents);
986 if (it != open_entries_.end()) { 990 if (it != open_entries_.end()) {
987 // We have this entry in memory. 991 // We have this entry in memory.
988 return it->second; 992 return it->second;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 stats_.SetCounter(Stats::OPEN_ENTRIES, current); 1187 stats_.SetCounter(Stats::OPEN_ENTRIES, current);
1184 stats_.SetCounter(Stats::MAX_ENTRIES, max_refs_); 1188 stats_.SetCounter(Stats::MAX_ENTRIES, max_refs_);
1185 } 1189 }
1186 1190
1187 CACHE_UMA(COUNTS, "NumberOfReferences", 0, num_refs_); 1191 CACHE_UMA(COUNTS, "NumberOfReferences", 0, num_refs_);
1188 1192
1189 CACHE_UMA(COUNTS_10000, "EntryAccessRate", 0, entry_count_); 1193 CACHE_UMA(COUNTS_10000, "EntryAccessRate", 0, entry_count_);
1190 CACHE_UMA(COUNTS, "ByteIORate", 0, byte_count_ / 1024); 1194 CACHE_UMA(COUNTS, "ByteIORate", 0, byte_count_ / 1024);
1191 entry_count_ = 0; 1195 entry_count_ = 0;
1192 byte_count_ = 0; 1196 byte_count_ = 0;
1197 up_ticks_++;
1193 1198
1194 if (!data_) 1199 if (!data_)
1195 first_timer_ = false; 1200 first_timer_ = false;
1196 if (first_timer_) { 1201 if (first_timer_) {
1197 first_timer_ = false; 1202 first_timer_ = false;
1198 if (ShouldReportAgain()) 1203 if (ShouldReportAgain())
1199 ReportStats(); 1204 ReportStats();
1200 } 1205 }
1201 1206
1202 // Save stats to disk at 5 min intervals. 1207 // Save stats to disk at 5 min intervals.
(...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after
2115 if (total_memory > kMaxBuffersSize || total_memory <= 0) 2120 if (total_memory > kMaxBuffersSize || total_memory <= 0)
2116 total_memory = kMaxBuffersSize; 2121 total_memory = kMaxBuffersSize;
2117 2122
2118 done = true; 2123 done = true;
2119 } 2124 }
2120 2125
2121 return static_cast<int>(total_memory); 2126 return static_cast<int>(total_memory);
2122 } 2127 }
2123 2128
2124 } // namespace disk_cache 2129 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/backend_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698