diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-29 18:21:34 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-29 18:21:34 +0000 |
commit | 813149f8eae2381d0e788c611035574fbb1fd4c1 (patch) | |
tree | 6e281c1176ad1246b56d73de76e283b9fb009bce | |
parent | ecf100830533911b799a5806d69f1cc0bd5d91e3 (diff) | |
download | chromium_src-813149f8eae2381d0e788c611035574fbb1fd4c1.zip chromium_src-813149f8eae2381d0e788c611035574fbb1fd4c1.tar.gz chromium_src-813149f8eae2381d0e788c611035574fbb1fd4c1.tar.bz2 |
Disk cache: End the experiment and use the new eviction
algorithm by default.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/248022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27514 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | net/disk_cache/backend_impl.cc | 143 | ||||
-rw-r--r-- | net/disk_cache/backend_impl.h | 7 | ||||
-rw-r--r-- | net/disk_cache/disk_cache_test_base.cc | 15 | ||||
-rw-r--r-- | net/disk_cache/disk_cache_test_util.cc | 1 | ||||
-rw-r--r-- | net/disk_cache/eviction.cc | 8 |
5 files changed, 78 insertions, 96 deletions
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc index f61fab8..36ab4c2 100644 --- a/net/disk_cache/backend_impl.cc +++ b/net/disk_cache/backend_impl.cc @@ -20,9 +20,6 @@ #include "net/disk_cache/hash.h" #include "net/disk_cache/file.h" -// Uncomment this to use the new eviction algorithm. -// #define USE_NEW_EVICTION - // This has to be defined before including histogram_macros.h from this file. #define NET_DISK_CACHE_BACKEND_IMPL_CC_ #include "net/disk_cache/histogram_macros.h" @@ -146,27 +143,14 @@ bool InitExperiment(int* current_group) { return false; } - if (*current_group <= 5) { - // The experiment is currently closed. - *current_group = 10; - } - - // The current groups should be: - // 6 control. - // 7 new eviction, upgraded data. - // 8 new eviction, from new files. - // 9 out. (sort of control for group 8). - // 10 out. - - UMA_HISTOGRAM_CACHE_ERROR("DiskCache.Experiment", *current_group); - - // Current experiment already set. + // There is no experiment. + *current_group = 0; return true; } // Initializes the field trial structures to allow performance measurements // for the current cache configuration. -void SetFieldTrialInfo(int experiment_group, int size_group) { +void SetFieldTrialInfo(int size_group) { static bool first = true; if (!first) return; @@ -176,13 +160,6 @@ void SetFieldTrialInfo(int experiment_group, int size_group) { scoped_refptr<FieldTrial> trial1 = new FieldTrial("CacheSize", 10); std::string group1 = StringPrintf("CacheSizeGroup_%d", size_group); trial1->AppendGroup(group1, FieldTrial::kAllRemainingProbability); - - if (experiment_group < 6 || experiment_group > 9) - return; - - scoped_refptr<FieldTrial> trial2 = new FieldTrial("NewEviction", 10); - std::string group2 = StringPrintf("NewEvictionGroup_%d", experiment_group); - trial2->AppendGroup(group2, FieldTrial::kAllRemainingProbability); } } // namespace @@ -191,6 +168,40 @@ void SetFieldTrialInfo(int experiment_group, int size_group) { namespace disk_cache { +Backend* CreateCacheBackend(const std::wstring& full_path, bool force, + int max_bytes, net::CacheType type) { + // Create a backend without extra flags. + return BackendImpl::CreateBackend(full_path, force, max_bytes, type, kNone); +} + +int PreferedCacheSize(int64 available) { + // If there is not enough space to use kDefaultCacheSize, use 80% of the + // available space. + if (available < kDefaultCacheSize) + return static_cast<int32>(available * 8 / 10); + + // Don't use more than 10% of the available space. + if (available < 10 * kDefaultCacheSize) + return kDefaultCacheSize; + + // Use 10% of the free space until we reach 2.5 * kDefaultCacheSize. + if (available < static_cast<int64>(kDefaultCacheSize) * 25) + return static_cast<int32>(available / 10); + + // After reaching our target size (2.5 * kDefaultCacheSize), attempt to use + // 1% of the availabe space. + if (available < static_cast<int64>(kDefaultCacheSize) * 100) + return kDefaultCacheSize * 5 / 2; + + int64 one_percent = available / 100; + if (one_percent > kint32max) + return kint32max; + + return static_cast<int32>(one_percent); +} + +// ------------------------------------------------------------------------ + // If the initialization of the cache fails, and force is true, we will discard // the whole cache and create a new one. In order to process a potentially large // number of files, we'll rename the cache folder to old_ + original_name + @@ -199,11 +210,15 @@ namespace disk_cache { // still fail if we are not able to rename the cache folder (for instance due to // a sharing violation), and in that case a cache for this profile (on the // desired path) cannot be created. -Backend* CreateCacheBackend(const std::wstring& full_path, bool force, - int max_bytes, net::CacheType type) { +// +// Static. +Backend* BackendImpl::CreateBackend(const std::wstring& full_path, bool force, + int max_bytes, net::CacheType type, + BackendFlags flags) { BackendImpl* cache = new BackendImpl(full_path); cache->SetMaxSize(max_bytes); cache->SetType(type); + cache->SetFlags(flags); if (cache->Init()) return cache; @@ -219,6 +234,7 @@ Backend* CreateCacheBackend(const std::wstring& full_path, bool force, cache = new BackendImpl(full_path); cache->SetMaxSize(max_bytes); cache->SetType(type); + cache->SetFlags(flags); if (cache->Init()) return cache; @@ -227,44 +243,11 @@ Backend* CreateCacheBackend(const std::wstring& full_path, bool force, return NULL; } -int PreferedCacheSize(int64 available) { - // If there is not enough space to use kDefaultCacheSize, use 80% of the - // available space. - if (available < kDefaultCacheSize) - return static_cast<int32>(available * 8 / 10); - - // Don't use more than 10% of the available space. - if (available < 10 * kDefaultCacheSize) - return kDefaultCacheSize; - - // Use 10% of the free space until we reach 2.5 * kDefaultCacheSize. - if (available < static_cast<int64>(kDefaultCacheSize) * 25) - return static_cast<int32>(available / 10); - - // After reaching our target size (2.5 * kDefaultCacheSize), attempt to use - // 1% of the availabe space. - if (available < static_cast<int64>(kDefaultCacheSize) * 100) - return kDefaultCacheSize * 5 / 2; - - int64 one_percent = available / 100; - if (one_percent > kint32max) - return kint32max; - - return static_cast<int32>(one_percent); -} - -// ------------------------------------------------------------------------ - bool BackendImpl::Init() { DCHECK(!init_); if (init_) return false; -#ifdef USE_NEW_EVICTION - new_eviction_ = true; - user_flags_ |= kNewEviction; -#endif - bool create_files = false; if (!InitBackingStore(&create_files)) { ReportError(ERR_STORAGE_ERROR); @@ -288,15 +271,13 @@ bool BackendImpl::Init() { return false; } - if (!(user_flags_ & disk_cache::kNoRandom) && - cache_type_ == net::DISK_CACHE) { + if (!(user_flags_ & disk_cache::kNoRandom)) { // The unit test controls directly what to test. if (!InitExperiment(&data_->header.experiment)) return false; - } - if (data_->header.experiment > 6 && data_->header.experiment < 9) - new_eviction_ = true; + new_eviction_ = (cache_type_ == net::DISK_CACHE); + } if (!CheckIndex()) { ReportError(ERR_INIT_FAILED); @@ -329,9 +310,9 @@ bool BackendImpl::Init() { disabled_ = !rankings_.Init(this, new_eviction_); eviction_.Init(this); - // Setup experiment data only for the main cache. + // Setup load-time data only for the main cache. if (cache_type() == net::DISK_CACHE) - SetFieldTrialInfo(data_->header.experiment, GetSizeGroup()); + SetFieldTrialInfo(GetSizeGroup()); return !disabled_; } @@ -855,13 +836,13 @@ void BackendImpl::FirstEviction() { int large_ratio = large_entries_bytes * 100 / data_->header.num_bytes; CACHE_UMA(PERCENTAGE, "FirstLargeEntriesRatio", 0, large_ratio); - if (data_->header.experiment == 8) { - CACHE_UMA(PERCENTAGE, "FirstResurrectRatio", 8, stats_.GetResurrectRatio()); - CACHE_UMA(PERCENTAGE, "FirstNoUseRatio", 8, + if (new_eviction_) { + CACHE_UMA(PERCENTAGE, "FirstResurrectRatio", 0, stats_.GetResurrectRatio()); + CACHE_UMA(PERCENTAGE, "FirstNoUseRatio", 0, data_->header.lru.sizes[0] * 100 / data_->header.num_entries); - CACHE_UMA(PERCENTAGE, "FirstLowUseRatio", 8, + CACHE_UMA(PERCENTAGE, "FirstLowUseRatio", 0, data_->header.lru.sizes[1] * 100 / data_->header.num_entries); - CACHE_UMA(PERCENTAGE, "FirstHighUseRatio", 8, + CACHE_UMA(PERCENTAGE, "FirstHighUseRatio", 0, data_->header.lru.sizes[2] * 100 / data_->header.num_entries); } @@ -1508,29 +1489,27 @@ void BackendImpl::ReportStats() { return; CACHE_UMA(HOURS, "UseTime", 0, static_cast<int>(use_hours)); - CACHE_UMA(PERCENTAGE, "HitRatio", data_->header.experiment, - stats_.GetHitRatio()); + CACHE_UMA(PERCENTAGE, "HitRatio", 0, stats_.GetHitRatio()); int64 trim_rate = stats_.GetCounter(Stats::TRIM_ENTRY) / use_hours; CACHE_UMA(COUNTS, "TrimRate", 0, static_cast<int>(trim_rate)); int avg_size = data_->header.num_bytes / GetEntryCount(); - CACHE_UMA(COUNTS, "EntrySize", data_->header.experiment, avg_size); + CACHE_UMA(COUNTS, "EntrySize", 0, avg_size); int large_entries_bytes = stats_.GetLargeEntriesSize(); int large_ratio = large_entries_bytes * 100 / data_->header.num_bytes; CACHE_UMA(PERCENTAGE, "LargeEntriesRatio", 0, large_ratio); if (new_eviction_) { - CACHE_UMA(PERCENTAGE, "ResurrectRatio", data_->header.experiment, - stats_.GetResurrectRatio()); - CACHE_UMA(PERCENTAGE, "NoUseRatio", data_->header.experiment, + CACHE_UMA(PERCENTAGE, "ResurrectRatio", 0, stats_.GetResurrectRatio()); + CACHE_UMA(PERCENTAGE, "NoUseRatio", 0, data_->header.lru.sizes[0] * 100 / data_->header.num_entries); - CACHE_UMA(PERCENTAGE, "LowUseRatio", data_->header.experiment, + CACHE_UMA(PERCENTAGE, "LowUseRatio", 0, data_->header.lru.sizes[1] * 100 / data_->header.num_entries); - CACHE_UMA(PERCENTAGE, "HighUseRatio", data_->header.experiment, + CACHE_UMA(PERCENTAGE, "HighUseRatio", 0, data_->header.lru.sizes[2] * 100 / data_->header.num_entries); - CACHE_UMA(PERCENTAGE, "DeletedRatio", data_->header.experiment, + CACHE_UMA(PERCENTAGE, "DeletedRatio", 0, data_->header.lru.sizes[4] * 100 / data_->header.num_entries); } diff --git a/net/disk_cache/backend_impl.h b/net/disk_cache/backend_impl.h index a2dd0c6..40bae4b 100644 --- a/net/disk_cache/backend_impl.h +++ b/net/disk_cache/backend_impl.h @@ -19,6 +19,7 @@ namespace disk_cache { enum BackendFlags { + kNone = 0, kMask = 1, // A mask (for the index table) was specified. kMaxSize = 1 << 1, // A maximum size was provided. kUnitTestMode = 1 << 2, // We are modifying the behavior for testing. @@ -48,6 +49,12 @@ class BackendImpl : public Backend { ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {} ~BackendImpl(); + // Returns a new backend with the desired flags. See the declaration of + // CreateCacheBackend(). + static Backend* CreateBackend(const std::wstring& full_path, bool force, + int max_bytes, net::CacheType type, + BackendFlags flags); + // Performs general initialization for this current instance of the cache. bool Init(); diff --git a/net/disk_cache/disk_cache_test_base.cc b/net/disk_cache/disk_cache_test_base.cc index db6af64..a148f4c 100644 --- a/net/disk_cache/disk_cache_test_base.cc +++ b/net/disk_cache/disk_cache_test_base.cc @@ -56,17 +56,12 @@ void DiskCacheTestWithCache::InitDiskCache() { if (first_cleanup_) ASSERT_TRUE(DeleteCache(path.c_str())); - if (!implementation_) { - cache_ = disk_cache::CreateCacheBackend(path, force_creation_, size_, - net::DISK_CACHE); - disk_cache::BackendImpl* impl = - static_cast<disk_cache::BackendImpl*>(cache_); - if (impl) - impl->SetFlags(disk_cache::kNoRandom); - return; - } + if (implementation_) + return InitDiskCacheImpl(path); - InitDiskCacheImpl(path); + cache_ = disk_cache::BackendImpl::CreateBackend(path, force_creation_, size_, + net::DISK_CACHE, + disk_cache::kNoRandom); } void DiskCacheTestWithCache::InitDiskCacheImpl(const std::wstring& path) { diff --git a/net/disk_cache/disk_cache_test_util.cc b/net/disk_cache/disk_cache_test_util.cc index 24c3925..a1afb1e 100644 --- a/net/disk_cache/disk_cache_test_util.cc +++ b/net/disk_cache/disk_cache_test_util.cc @@ -83,6 +83,7 @@ bool CheckCacheIntegrity(const std::wstring& path, bool new_eviction) { return false; if (new_eviction) cache->SetNewEviction(); + cache->SetFlags(disk_cache::kNoRandom); if (!cache->Init()) return false; return cache->SelfCheck() >= 0; diff --git a/net/disk_cache/eviction.cc b/net/disk_cache/eviction.cc index dfbdc25..bdcef6b 100644 --- a/net/disk_cache/eviction.cc +++ b/net/disk_cache/eviction.cc @@ -472,16 +472,16 @@ void Eviction::ReportListStats() { rankings_->GetPrev(NULL, Rankings::DELETED)); if (last1.get()) - CACHE_UMA(AGE, "NoUseAge", header_->experiment, + CACHE_UMA(AGE, "NoUseAge", 0, Time::FromInternalValue(last1.get()->Data()->last_used)); if (last2.get()) - CACHE_UMA(AGE, "LowUseAge", header_->experiment, + CACHE_UMA(AGE, "LowUseAge", 0, Time::FromInternalValue(last2.get()->Data()->last_used)); if (last3.get()) - CACHE_UMA(AGE, "HighUseAge", header_->experiment, + CACHE_UMA(AGE, "HighUseAge", 0, Time::FromInternalValue(last3.get()->Data()->last_used)); if (last4.get()) - CACHE_UMA(AGE, "DeletedAge", header_->experiment, + CACHE_UMA(AGE, "DeletedAge", 0, Time::FromInternalValue(last4.get()->Data()->last_used)); } |