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

Side by Side Diff: net/disk_cache/simple/simple_index.h

Issue 2922973003: RFC: use some in-memory state in SimpleCache to quickly cache-miss some CantConditionalize cases
Patch Set: cleanup naming in SimpleCache impl of this some Created 3 years, 6 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_ 5 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_
6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_ 6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <list> 10 #include <list>
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 base::Time GetLastUsedTime() const; 51 base::Time GetLastUsedTime() const;
52 void SetLastUsedTime(const base::Time& last_used_time); 52 void SetLastUsedTime(const base::Time& last_used_time);
53 53
54 uint32_t RawTimeForSorting() const { 54 uint32_t RawTimeForSorting() const {
55 return last_used_time_seconds_since_epoch_; 55 return last_used_time_seconds_since_epoch_;
56 } 56 }
57 57
58 uint32_t GetEntrySize() const; 58 uint32_t GetEntrySize() const;
59 void SetEntrySize(base::StrictNumeric<uint32_t> entry_size); 59 void SetEntrySize(base::StrictNumeric<uint32_t> entry_size);
60 60
61 uint8_t GetMemoryEntryData() const { return memory_entry_data_; }
62 void SetMemoryEntryData(uint8_t val) { memory_entry_data_ = val; }
63
61 // Serialize the data into the provided pickle. 64 // Serialize the data into the provided pickle.
62 void Serialize(base::Pickle* pickle) const; 65 void Serialize(base::Pickle* pickle) const;
63 bool Deserialize(base::PickleIterator* it); 66 bool Deserialize(base::PickleIterator* it, bool has_memory_entry_data);
64 67
65 static base::TimeDelta GetLowerEpsilonForTimeComparisons() { 68 static base::TimeDelta GetLowerEpsilonForTimeComparisons() {
66 return base::TimeDelta::FromSeconds(1); 69 return base::TimeDelta::FromSeconds(1);
67 } 70 }
68 static base::TimeDelta GetUpperEpsilonForTimeComparisons() { 71 static base::TimeDelta GetUpperEpsilonForTimeComparisons() {
69 return base::TimeDelta(); 72 return base::TimeDelta();
70 } 73 }
71 74
72 static const int kOnDiskSizeBytes = 16; 75 static const int kOnDiskSizeBytes = 16;
73 76
74 private: 77 private:
75 friend class SimpleIndexFileTest; 78 friend class SimpleIndexFileTest;
76 79
77 // There are tens of thousands of instances of EntryMetadata in memory, so the 80 // There are tens of thousands of instances of EntryMetadata in memory, so the
78 // size of each entry matters. Even when the values used to set these members 81 // size of each entry matters. Even when the values used to set these members
79 // are originally calculated as >32-bit types, the actual necessary size for 82 // are originally calculated as >32-bit types, the actual necessary size for
80 // each shouldn't exceed 32 bits, so we use 32-bit types here. 83 // each shouldn't exceed 32 bits, so we use 32-bit types here.
81 uint32_t last_used_time_seconds_since_epoch_; 84 uint32_t last_used_time_seconds_since_epoch_;
82 uint32_t entry_size_; // Storage size in bytes. 85 // Storage size in 256-byte blocks
pasko 2017/06/13 14:30:05 4K blocks, if rounded upwards would probably be ev
Maks Orlovich 2017/06/13 14:58:47 Hmm, maybe. Plus: it would also prevent things fro
86 uint32_t entry_size_ : 24;
87 uint8_t memory_entry_data_ : 8;
pasko 2017/06/13 14:30:05 it would be cleaner to reserve one bit that says w
Maks Orlovich 2017/06/13 14:58:47 Hmm, maybe with a bool GetMemoryEntryData(uint64_t
83 }; 88 };
84 static_assert(sizeof(EntryMetadata) == 8, "incorrect metadata size"); 89 static_assert(sizeof(EntryMetadata) == 8, "incorrect metadata size");
85 90
86 // This class is not Thread-safe. 91 // This class is not Thread-safe.
87 class NET_EXPORT_PRIVATE SimpleIndex 92 class NET_EXPORT_PRIVATE SimpleIndex
88 : public base::SupportsWeakPtr<SimpleIndex> { 93 : public base::SupportsWeakPtr<SimpleIndex> {
89 public: 94 public:
90 // Used in histograms. Please only add entries at the end. 95 // Used in histograms. Please only add entries at the end.
91 enum IndexInitMethod { 96 enum IndexInitMethod {
92 INITIALIZE_METHOD_RECOVERED = 0, 97 INITIALIZE_METHOD_RECOVERED = 0,
(...skipping 27 matching lines...) Expand all
120 void Insert(uint64_t entry_hash); 125 void Insert(uint64_t entry_hash);
121 void Remove(uint64_t entry_hash); 126 void Remove(uint64_t entry_hash);
122 127
123 // Check whether the index has the entry given the hash of its key. 128 // Check whether the index has the entry given the hash of its key.
124 bool Has(uint64_t entry_hash) const; 129 bool Has(uint64_t entry_hash) const;
125 130
126 // Update the last used time of the entry with the given key and return true 131 // Update the last used time of the entry with the given key and return true
127 // iff the entry exist in the index. 132 // iff the entry exist in the index.
128 bool UseIfExists(uint64_t entry_hash); 133 bool UseIfExists(uint64_t entry_hash);
129 134
135 uint8_t GetMemoryEntryData(uint64_t entry_hash) const;
136 void SetMemoryEntryData(uint64_t entry_hash, uint8_t value);
137
130 void WriteToDisk(IndexWriteToDiskReason reason); 138 void WriteToDisk(IndexWriteToDiskReason reason);
131 139
132 // Update the size (in bytes) of an entry, in the metadata stored in the 140 // Update the size (in bytes) of an entry, in the metadata stored in the
133 // index. This should be the total disk-file size including all streams of the 141 // index. This should be the total disk-file size including all streams of the
134 // entry. 142 // entry.
135 bool UpdateEntrySize(uint64_t entry_hash, 143 bool UpdateEntrySize(uint64_t entry_hash,
136 base::StrictNumeric<uint32_t> entry_size); 144 base::StrictNumeric<uint32_t> entry_size);
137 145
138 using EntrySet = std::unordered_map<uint64_t, EntryMetadata>; 146 using EntrySet = std::unordered_map<uint64_t, EntryMetadata>;
139 147
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 253
246 // Set to true when the app is on the background. When the app is in the 254 // Set to true when the app is on the background. When the app is in the
247 // background we can write the index much more frequently, to insure fresh 255 // background we can write the index much more frequently, to insure fresh
248 // index on next startup. 256 // index on next startup.
249 bool app_on_background_; 257 bool app_on_background_;
250 }; 258 };
251 259
252 } // namespace disk_cache 260 } // namespace disk_cache
253 261
254 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_ 262 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698