Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 // The cache is stored on disk as a collection of block-files, plus an index | 5 // The cache is stored on disk as a collection of block-files, plus an index |
| 6 // file plus a collection of external files. | 6 // file plus a collection of external files. |
| 7 // | 7 // |
| 8 // Any data blob bigger than kMaxBlockSize (net/addr.h) will be stored on a | 8 // Any data blob bigger than kMaxBlockSize (net/addr.h) will be stored on a |
| 9 // separate file named f_xxx where x is a hexadecimal number. Shorter data will | 9 // separate file named f_xxx where x is a hexadecimal number. Shorter data will |
| 10 // be stored as a series of blocks on a block-file. In any case, CacheAddr | 10 // be stored as a series of blocks on a block-file. In any case, CacheAddr |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 CacheAddr rankings_node; // Rankings node for this entry. | 116 CacheAddr rankings_node; // Rankings node for this entry. |
| 117 int32 reuse_count; // How often is this entry used. | 117 int32 reuse_count; // How often is this entry used. |
| 118 int32 refetch_count; // How often is this fetched from the net. | 118 int32 refetch_count; // How often is this fetched from the net. |
| 119 int32 state; // Current state. | 119 int32 state; // Current state. |
| 120 uint64 creation_time; | 120 uint64 creation_time; |
| 121 int32 key_len; | 121 int32 key_len; |
| 122 CacheAddr long_key; // Optional address of a long key. | 122 CacheAddr long_key; // Optional address of a long key. |
| 123 int32 data_size[4]; // We can store up to 4 data streams for each | 123 int32 data_size[4]; // We can store up to 4 data streams for each |
| 124 CacheAddr data_addr[4]; // entry. | 124 CacheAddr data_addr[4]; // entry. |
| 125 uint32 flags; // Any combination of EntryFlags. | 125 uint32 flags; // Any combination of EntryFlags. |
| 126 int32 pad[5]; | 126 int32 pad[4]; |
| 127 uint32 self_hash; // The hash of EntryStore up to this point. | |
|
gavinp
2011/11/29 15:47:42
Why after the pad, and not before? What do we exp
rvargas (doing something else)
2011/11/29 19:08:56
Yes, that's it. Pad is set to zero, and the expect
| |
| 127 char key[256 - 24 * 4]; // null terminated | 128 char key[256 - 24 * 4]; // null terminated |
| 128 }; | 129 }; |
| 129 | 130 |
| 130 COMPILE_ASSERT(sizeof(EntryStore) == 256, bad_EntyStore); | 131 COMPILE_ASSERT(sizeof(EntryStore) == 256, bad_EntyStore); |
| 131 const int kMaxInternalKeyLength = 4 * sizeof(EntryStore) - | 132 const int kMaxInternalKeyLength = 4 * sizeof(EntryStore) - |
| 132 offsetof(EntryStore, key) - 1; | 133 offsetof(EntryStore, key) - 1; |
| 133 | 134 |
| 134 // Possible states for a given entry. | 135 // Possible states for a given entry. |
| 135 enum EntryState { | 136 enum EntryState { |
| 136 ENTRY_NORMAL = 0, | 137 ENTRY_NORMAL = 0, |
| 137 ENTRY_EVICTED, // The entry was recently evicted from the cache. | 138 ENTRY_EVICTED, // The entry was recently evicted from the cache. |
| 138 ENTRY_DOOMED // The entry was doomed. | 139 ENTRY_DOOMED // The entry was doomed. |
| 139 }; | 140 }; |
| 140 | 141 |
| 141 // Flags that can be applied to an entry. | 142 // Flags that can be applied to an entry. |
| 142 enum EntryFlags { | 143 enum EntryFlags { |
| 143 PARENT_ENTRY = 1, // This entry has children (sparse) entries. | 144 PARENT_ENTRY = 1, // This entry has children (sparse) entries. |
| 144 CHILD_ENTRY = 1 << 1 // Child entry that stores sparse data. | 145 CHILD_ENTRY = 1 << 1 // Child entry that stores sparse data. |
| 145 }; | 146 }; |
| 146 | 147 |
| 147 #pragma pack(push, 4) | 148 #pragma pack(push, 4) |
| 148 // Rankings information for a given entry. | 149 // Rankings information for a given entry. |
| 149 struct RankingsNode { | 150 struct RankingsNode { |
| 150 uint64 last_used; // LRU info. | 151 uint64 last_used; // LRU info. |
| 151 uint64 last_modified; // LRU info. | 152 uint64 last_modified; // LRU info. |
| 152 CacheAddr next; // LRU list. | 153 CacheAddr next; // LRU list. |
| 153 CacheAddr prev; // LRU list. | 154 CacheAddr prev; // LRU list. |
| 154 CacheAddr contents; // Address of the EntryStore. | 155 CacheAddr contents; // Address of the EntryStore. |
| 155 int32 dirty; // The entry is being modifyied. | 156 int32 dirty; // The entry is being modifyied. |
| 156 int32 dummy; // Old files may have a pointer here. | 157 uint32 self_hash; // RankingsNode's hash. |
| 157 }; | 158 }; |
| 158 #pragma pack(pop) | 159 #pragma pack(pop) |
| 159 | 160 |
| 160 COMPILE_ASSERT(sizeof(RankingsNode) == 36, bad_RankingsNode); | 161 COMPILE_ASSERT(sizeof(RankingsNode) == 36, bad_RankingsNode); |
| 161 | 162 |
| 162 const uint32 kBlockMagic = 0xC104CAC3; | 163 const uint32 kBlockMagic = 0xC104CAC3; |
| 163 const int kBlockHeaderSize = 8192; // Two pages: almost 64k entries | 164 const int kBlockHeaderSize = 8192; // Two pages: almost 64k entries |
| 164 const int kMaxBlocks = (kBlockHeaderSize - 80) * 8; | 165 const int kMaxBlocks = (kBlockHeaderSize - 80) * 8; |
| 165 | 166 |
| 166 // Bitmap to track used blocks on a block-file. | 167 // Bitmap to track used blocks on a block-file. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 }; | 254 }; |
| 254 | 255 |
| 255 // The number of blocks stored by a child entry. | 256 // The number of blocks stored by a child entry. |
| 256 const int kNumSparseBits = 1024; | 257 const int kNumSparseBits = 1024; |
| 257 COMPILE_ASSERT(sizeof(SparseData) == sizeof(SparseHeader) + kNumSparseBits / 8, | 258 COMPILE_ASSERT(sizeof(SparseData) == sizeof(SparseHeader) + kNumSparseBits / 8, |
| 258 Invalid_SparseData_bitmap); | 259 Invalid_SparseData_bitmap); |
| 259 | 260 |
| 260 } // namespace disk_cache | 261 } // namespace disk_cache |
| 261 | 262 |
| 262 #endif // NET_DISK_CACHE_DISK_FORMAT_H_ | 263 #endif // NET_DISK_CACHE_DISK_FORMAT_H_ |
| OLD | NEW |