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

Side by Side Diff: net/disk_cache/blockfile/eviction_v3.cc

Issue 1499423004: Remove kint32max. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@kint9
Patch Set: rebase Created 5 years 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
« no previous file with comments | « net/disk_cache/blockfile/eviction.cc ('k') | net/disk_cache/blockfile/index_table_v3.h » ('j') | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // The eviction policy is a very simple pure LRU, so the elements at the end of 5 // The eviction policy is a very simple pure LRU, so the elements at the end of
6 // the list are evicted until kCleanUpMargin free space is available. There is 6 // the list are evicted until kCleanUpMargin free space is available. There is
7 // only one list in use (Rankings::NO_USE), and elements are sent to the front 7 // only one list in use (Rankings::NO_USE), and elements are sent to the front
8 // of the list whenever they are accessed. 8 // of the list whenever they are accessed.
9 9
10 // The new (in-development) eviction policy adds re-use as a factor to evict 10 // The new (in-development) eviction policy adds re-use as a factor to evict
(...skipping 10 matching lines...) Expand all
21 // When we have to evict an element, first we try to use the last element from 21 // When we have to evict an element, first we try to use the last element from
22 // the NO_USE list, then we move to the LOW_USE and only then we evict an entry 22 // the NO_USE list, then we move to the LOW_USE and only then we evict an entry
23 // from the HIGH_USE. We attempt to keep entries on the cache for at least 23 // from the HIGH_USE. We attempt to keep entries on the cache for at least
24 // kTargetTime hours (with frequently accessed items stored for longer periods), 24 // kTargetTime hours (with frequently accessed items stored for longer periods),
25 // but if we cannot do that, we fall-back to keep each list roughly the same 25 // but if we cannot do that, we fall-back to keep each list roughly the same
26 // size so that we have a chance to see an element again and move it to another 26 // size so that we have a chance to see an element again and move it to another
27 // list. 27 // list.
28 28
29 #include "net/disk_cache/blockfile/eviction_v3.h" 29 #include "net/disk_cache/blockfile/eviction_v3.h"
30 30
31 #include <stdint.h>
32
33 #include <limits>
34
31 #include "base/bind.h" 35 #include "base/bind.h"
32 #include "base/compiler_specific.h" 36 #include "base/compiler_specific.h"
33 #include "base/logging.h" 37 #include "base/logging.h"
34 #include "base/message_loop/message_loop.h" 38 #include "base/message_loop/message_loop.h"
35 #include "base/strings/string_util.h" 39 #include "base/strings/string_util.h"
36 #include "base/time/time.h" 40 #include "base/time/time.h"
37 #include "net/disk_cache/blockfile/backend_impl_v3.h" 41 #include "net/disk_cache/blockfile/backend_impl_v3.h"
38 #include "net/disk_cache/blockfile/entry_impl_v3.h" 42 #include "net/disk_cache/blockfile/entry_impl_v3.h"
39 #include "net/disk_cache/blockfile/experiments.h" 43 #include "net/disk_cache/blockfile/experiments.h"
40 #include "net/disk_cache/blockfile/histogram_macros_v3.h" 44 #include "net/disk_cache/blockfile/histogram_macros_v3.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 171
168 trimming_ = false; 172 trimming_ = false;
169 Trace("*** Trim Cache end ***"); 173 Trace("*** Trim Cache end ***");
170 return; 174 return;
171 } 175 }
172 176
173 void EvictionV3::OnOpenEntry(EntryImplV3* entry) { 177 void EvictionV3::OnOpenEntry(EntryImplV3* entry) {
174 EntryStore* info = entry->entry()->Data(); 178 EntryStore* info = entry->entry()->Data();
175 DCHECK_EQ(ENTRY_NORMAL, info->state); 179 DCHECK_EQ(ENTRY_NORMAL, info->state);
176 180
177 if (info->reuse_count < kint32max) { 181 if (info->reuse_count < std::numeric_limits<int32_t>::max()) {
178 info->reuse_count++; 182 info->reuse_count++;
179 entry->entry()->set_modified(); 183 entry->entry()->set_modified();
180 184
181 // We may need to move this to a new list. 185 // We may need to move this to a new list.
182 if (1 == info->reuse_count) { 186 if (1 == info->reuse_count) {
183 rankings_->Remove(entry->rankings(), Rankings::NO_USE, true); 187 rankings_->Remove(entry->rankings(), Rankings::NO_USE, true);
184 rankings_->Insert(entry->rankings(), false, Rankings::LOW_USE); 188 rankings_->Insert(entry->rankings(), false, Rankings::LOW_USE);
185 entry->entry()->Store(); 189 entry->entry()->Store();
186 } else if (kHighUse == info->reuse_count) { 190 } else if (kHighUse == info->reuse_count) {
187 rankings_->Remove(entry->rankings(), Rankings::LOW_USE, true); 191 rankings_->Remove(entry->rankings(), Rankings::LOW_USE, true);
188 rankings_->Insert(entry->rankings(), false, Rankings::HIGH_USE); 192 rankings_->Insert(entry->rankings(), false, Rankings::HIGH_USE);
189 entry->entry()->Store(); 193 entry->entry()->Store();
190 } 194 }
191 } 195 }
192 } 196 }
193 197
194 void EvictionV3::OnCreateEntry(EntryImplV3* entry) { 198 void EvictionV3::OnCreateEntry(EntryImplV3* entry) {
195 EntryStore* info = entry->entry()->Data(); 199 EntryStore* info = entry->entry()->Data();
196 switch (info->state) { 200 switch (info->state) {
197 case ENTRY_NORMAL: { 201 case ENTRY_NORMAL: {
198 DCHECK(!info->reuse_count); 202 DCHECK(!info->reuse_count);
199 DCHECK(!info->refetch_count); 203 DCHECK(!info->refetch_count);
200 break; 204 break;
201 }; 205 };
202 case ENTRY_EVICTED: { 206 case ENTRY_EVICTED: {
203 if (info->refetch_count < kint32max) 207 if (info->refetch_count < std::numeric_limits<int32_t>::max())
204 info->refetch_count++; 208 info->refetch_count++;
205 209
206 if (info->refetch_count > kHighUse && info->reuse_count < kHighUse) { 210 if (info->refetch_count > kHighUse && info->reuse_count < kHighUse) {
207 info->reuse_count = kHighUse; 211 info->reuse_count = kHighUse;
208 } else { 212 } else {
209 info->reuse_count++; 213 info->reuse_count++;
210 } 214 }
211 info->state = ENTRY_NORMAL; 215 info->state = ENTRY_NORMAL;
212 entry->entry()->Store(); 216 entry->entry()->Store();
213 rankings_->Remove(entry->rankings(), Rankings::DELETED, true); 217 rankings_->Remove(entry->rankings(), Rankings::DELETED, true);
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 if (last3.get()) 507 if (last3.get())
504 CACHE_UMA(AGE, "HighUseAge", 0, 508 CACHE_UMA(AGE, "HighUseAge", 0,
505 Time::FromInternalValue(last3.get()->Data()->last_used)); 509 Time::FromInternalValue(last3.get()->Data()->last_used));
506 if (last4.get()) 510 if (last4.get())
507 CACHE_UMA(AGE, "DeletedAge", 0, 511 CACHE_UMA(AGE, "DeletedAge", 0,
508 Time::FromInternalValue(last4.get()->Data()->last_used)); 512 Time::FromInternalValue(last4.get()->Data()->last_used));
509 } 513 }
510 #endif // defined(V3_NOT_JUST_YET_READY). 514 #endif // defined(V3_NOT_JUST_YET_READY).
511 515
512 } // namespace disk_cache 516 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/blockfile/eviction.cc ('k') | net/disk_cache/blockfile/index_table_v3.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698