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

Unified Diff: net/disk_cache/simple/simple_index.cc

Issue 2922973003: RFC: use some in-memory state in SimpleCache to quickly cache-miss some CantConditionalize cases
Patch Set: - Implement support for oracle bytes in MockHttpCache, so the code actually gets exercised in tests… 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 side-by-side diff with in-line comments
Download patch
Index: net/disk_cache/simple/simple_index.cc
diff --git a/net/disk_cache/simple/simple_index.cc b/net/disk_cache/simple/simple_index.cc
index c41c829bdefd808db4ea55dded03e54f4574b641..42b6eafded46cf43f62f7b83b94f04a9372b2c1a 100644
--- a/net/disk_cache/simple/simple_index.cc
+++ b/net/disk_cache/simple/simple_index.cc
@@ -60,7 +60,8 @@ EntryMetadata::EntryMetadata()
EntryMetadata::EntryMetadata(base::Time last_used_time,
base::StrictNumeric<uint32_t> entry_size)
- : last_used_time_seconds_since_epoch_(0), entry_size_(entry_size) {
+ : last_used_time_seconds_since_epoch_(0), entry_size_(0) {
+ SetEntrySize(entry_size); // to round/pack properly.
SetLastUsedTime(last_used_time);
}
@@ -88,11 +89,23 @@ void EntryMetadata::SetLastUsedTime(const base::Time& last_used_time) {
}
uint32_t EntryMetadata::GetEntrySize() const {
- return entry_size_;
+ return entry_size_ & 0xFFFFFF00;
jkarlin 2017/06/08 14:44:06 I'd rather add a byte (or a uint32_t even) to the
+}
+
+uint8_t EntryMetadata::GetOracleByte() const {
+ return entry_size_ & 0xFF;
}
void EntryMetadata::SetEntrySize(base::StrictNumeric<uint32_t> entry_size) {
- entry_size_ = entry_size;
+ uint8_t save_oracle_byte = GetOracleByte();
+ // ### what happens if we overflow here?
+ entry_size_ = ((static_cast<uint32_t>(entry_size) + 255) & 0xFFFFFF00) |
+ save_oracle_byte;
+}
+
+void EntryMetadata::SetOracleByte(uint8_t oracle_byte) {
+ uint32_t save_size = GetEntrySize();
+ entry_size_ = (save_size | oracle_byte);
}
void EntryMetadata::Serialize(base::Pickle* pickle) const {
@@ -104,7 +117,8 @@ void EntryMetadata::Serialize(base::Pickle* pickle) const {
pickle->WriteUInt64(entry_size_);
}
-bool EntryMetadata::Deserialize(base::PickleIterator* it) {
+bool EntryMetadata::Deserialize(base::PickleIterator* it,
+ bool has_oracle_byte) {
DCHECK(it);
int64_t tmp_last_used_time;
uint64_t tmp_entry_size;
@@ -112,7 +126,12 @@ bool EntryMetadata::Deserialize(base::PickleIterator* it) {
tmp_entry_size > std::numeric_limits<decltype(entry_size_)>::max())
return false;
SetLastUsedTime(base::Time::FromInternalValue(tmp_last_used_time));
- entry_size_ = static_cast<uint32_t>(tmp_entry_size);
+ if (has_oracle_byte) {
+ entry_size_ = static_cast<uint32_t>(tmp_entry_size);
+ } else {
+ SetEntrySize(static_cast<uint32_t>(tmp_entry_size));
+ SetOracleByte(0);
+ }
return true;
}
@@ -281,6 +300,15 @@ bool SimpleIndex::Has(uint64_t hash) const {
return !initialized_ || entries_set_.count(hash) > 0;
}
+bool SimpleIndex::HasWithOracleByte(uint64_t entry_hash, uint8_t* oracle_byte) {
+ EntrySet::iterator it = entries_set_.find(entry_hash);
+ if (it == entries_set_.end())
+ // If not initialized, always return true, forcing it to go to the disk.
+ return !initialized_;
+ *oracle_byte = it->second.GetOracleByte();
+ return true;
+}
+
bool SimpleIndex::UseIfExists(uint64_t entry_hash) {
DCHECK(io_thread_checker_.CalledOnValidThread());
// Always update the last used time, even if it is during initialization.
@@ -363,6 +391,16 @@ bool SimpleIndex::UpdateEntrySize(uint64_t entry_hash,
return true;
}
+void SimpleIndex::UpdateEntryOracleByte(uint64_t entry_hash,
+ uint8_t oracle_byte) {
+ DCHECK(io_thread_checker_.CalledOnValidThread());
+ EntrySet::iterator it = entries_set_.find(entry_hash);
+ if (it == entries_set_.end())
+ return;
+ it->second.SetOracleByte(oracle_byte);
+ PostponeWritingToDisk();
+}
+
void SimpleIndex::EvictionDone(int result) {
DCHECK(io_thread_checker_.CalledOnValidThread());
@@ -410,8 +448,9 @@ void SimpleIndex::UpdateEntryIteratorSize(
DCHECK(io_thread_checker_.CalledOnValidThread());
DCHECK_GE(cache_size_, (*it)->second.GetEntrySize());
cache_size_ -= (*it)->second.GetEntrySize();
- cache_size_ += static_cast<uint32_t>(entry_size);
(*it)->second.SetEntrySize(entry_size);
+ // We use GetEntrySize to get consistent rounding.
+ cache_size_ += (*it)->second.GetEntrySize();
}
void SimpleIndex::MergeInitializingSet(

Powered by Google App Engine
This is Rietveld 408576698