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

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

Issue 2874833005: SimpleCache: read small files all at once. (Closed)
Patch Set: Add some metrics and an experiment knob. Not really happy with coverage, though. Created 3 years, 5 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_SYNCHRONOUS_ENTRY_H_ 5 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_
6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_ 6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 int32_t data_size_[kSimpleEntryStreamCount]; 72 int32_t data_size_[kSimpleEntryStreamCount];
73 int32_t sparse_data_size_; 73 int32_t sparse_data_size_;
74 }; 74 };
75 75
76 struct SimpleEntryCreationResults { 76 struct SimpleEntryCreationResults {
77 explicit SimpleEntryCreationResults(SimpleEntryStat entry_stat); 77 explicit SimpleEntryCreationResults(SimpleEntryStat entry_stat);
78 ~SimpleEntryCreationResults(); 78 ~SimpleEntryCreationResults();
79 79
80 SimpleSynchronousEntry* sync_entry; 80 SimpleSynchronousEntry* sync_entry;
81 scoped_refptr<net::GrowableIOBuffer> stream_0_data; 81 scoped_refptr<net::GrowableIOBuffer> stream_0_data;
82
83 // |stream_1_data| may be null (in which case stream_1_crc32 will be unset)
84 scoped_refptr<net::GrowableIOBuffer> stream_1_data;
82 SimpleEntryStat entry_stat; 85 SimpleEntryStat entry_stat;
83 uint32_t stream_0_crc32; 86 uint32_t stream_0_crc32;
87 uint32_t stream_1_crc32;
pasko 2017/07/18 13:46:31 are you packing this to make the sizeof(SimpleEntr
Maks Orlovich 2017/07/21 18:37:34 Done.
84 int result; 88 int result;
85 }; 89 };
86 90
87 // Worker thread interface to the very simple cache. This interface is not 91 // Worker thread interface to the very simple cache. This interface is not
88 // thread safe, and callers must ensure that it is only ever accessed from 92 // thread safe, and callers must ensure that it is only ever accessed from
89 // a single thread between synchronization points. 93 // a single thread between synchronization points.
90 class SimpleSynchronousEntry { 94 class SimpleSynchronousEntry {
91 public: 95 public:
92 struct CRCRecord { 96 struct CRCRecord {
93 CRCRecord(); 97 CRCRecord();
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 CRCRequest* crc_request, 187 CRCRequest* crc_request,
184 SimpleEntryStat* entry_stat, 188 SimpleEntryStat* entry_stat,
185 net::IOBuffer* out_buf, 189 net::IOBuffer* out_buf,
186 int* out_result); 190 int* out_result);
187 void WriteData(const EntryOperationData& in_entry_op, 191 void WriteData(const EntryOperationData& in_entry_op,
188 net::IOBuffer* in_buf, 192 net::IOBuffer* in_buf,
189 SimpleEntryStat* out_entry_stat, 193 SimpleEntryStat* out_entry_stat,
190 int* out_result); 194 int* out_result);
191 int CheckEOFRecord(int index, 195 int CheckEOFRecord(int index,
192 const SimpleEntryStat& entry_stat, 196 const SimpleEntryStat& entry_stat,
193 uint32_t expected_crc32) const; 197 uint32_t expected_crc32);
194 198
195 void ReadSparseData(const EntryOperationData& in_entry_op, 199 void ReadSparseData(const EntryOperationData& in_entry_op,
196 net::IOBuffer* out_buf, 200 net::IOBuffer* out_buf,
197 base::Time* out_last_used, 201 base::Time* out_last_used,
198 int* out_result); 202 int* out_result);
199 void WriteSparseData(const EntryOperationData& in_entry_op, 203 void WriteSparseData(const EntryOperationData& in_entry_op,
200 net::IOBuffer* in_buf, 204 net::IOBuffer* in_buf,
201 uint64_t max_sparse_data_size, 205 uint64_t max_sparse_data_size,
202 SimpleEntryStat* out_entry_stat, 206 SimpleEntryStat* out_entry_stat,
203 int* out_result); 207 int* out_result);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 279
276 // Read the header and key at the beginning of the file, and validate that 280 // Read the header and key at the beginning of the file, and validate that
277 // they are correct. If this entry was opened with a key, the key is checked 281 // they are correct. If this entry was opened with a key, the key is checked
278 // for a match. If not, then the |key_| member is set based on the value in 282 // for a match. If not, then the |key_| member is set based on the value in
279 // this header. Records histograms if any check is failed. 283 // this header. Records histograms if any check is failed.
280 bool CheckHeaderAndKey(int file_index); 284 bool CheckHeaderAndKey(int file_index);
281 285
282 // Returns a net error, i.e. net::OK on success. 286 // Returns a net error, i.e. net::OK on success.
283 int InitializeForOpen(SimpleEntryStat* out_entry_stat, 287 int InitializeForOpen(SimpleEntryStat* out_entry_stat,
284 scoped_refptr<net::GrowableIOBuffer>* stream_0_data, 288 scoped_refptr<net::GrowableIOBuffer>* stream_0_data,
285 uint32_t* out_stream_0_crc32); 289 uint32_t* out_stream_0_crc32,
290 scoped_refptr<net::GrowableIOBuffer>* stream_1_data,
291 uint32_t* out_stream_1_crc32);
286 292
287 // Writes the header and key to a newly-created stream file. |index| is the 293 // Writes the header and key to a newly-created stream file. |index| is the
288 // index of the stream. Returns true on success; returns false and sets 294 // index of the stream. Returns true on success; returns false and sets
289 // |*out_result| on failure. 295 // |*out_result| on failure.
290 bool InitializeCreatedFile(int index, CreateEntryResult* out_result); 296 bool InitializeCreatedFile(int index, CreateEntryResult* out_result);
291 297
292 // Returns a net error, including net::OK on success and net::FILE_EXISTS 298 // Returns a net error, including net::OK on success and net::FILE_EXISTS
293 // when the entry already exists. 299 // when the entry already exists.
294 int InitializeForCreate(SimpleEntryStat* out_entry_stat); 300 int InitializeForCreate(SimpleEntryStat* out_entry_stat);
295 301
296 // Allocates and fills a buffer with stream 0 data in |stream_0_data|, then 302 // Allocates and fills a buffer with stream 0 data in |stream_0_data|, then
297 // checks its crc32. 303 // checks its crc32. May also optionally read in |stream_1_data| and its
304 // crc, but might decide not to.
298 int ReadAndValidateStream0( 305 int ReadAndValidateStream0(
299 int file_size, 306 int file_size,
300 SimpleEntryStat* out_entry_stat, 307 SimpleEntryStat* out_entry_stat,
301 scoped_refptr<net::GrowableIOBuffer>* stream_0_data, 308 scoped_refptr<net::GrowableIOBuffer>* stream_0_data,
302 uint32_t* out_stream_0_crc32); 309 uint32_t* out_stream_0_crc32,
310 scoped_refptr<net::GrowableIOBuffer>* stream_1_data,
311 uint32_t* out_stream_1_crc32);
303 312
304 int GetEOFRecordData(int index, 313 // Reads the EOF record for stream |stream_index| from the appropriate file,
314 // or in memory prefetched version in [prefetch_buf, prefetch_buf + file_size)
315 // using |entry_stat| for layout info, and putting result into
316 // |*eof_record|. Sanity-checks the result.
317 // Returns net status, and records any failures to UMA.
318 //
319 // Note that non-null |prefetch_buf| may only be specified if stream_index is
320 // 0 or 1.
321 int GetEOFRecordData(char* prefetch_buf,
322 int file_size,
323 int stream_index,
305 const SimpleEntryStat& entry_stat, 324 const SimpleEntryStat& entry_stat,
306 bool* out_has_crc32, 325 SimpleFileEOF* eof_record);
307 bool* out_has_key_sha256, 326
308 uint32_t* out_crc32, 327 // Reads either from |prefetch_buf| --- if that's not null --- or files_[0].
309 int32_t* out_data_size) const; 328 // Range-checks all the in-memory reads.
329 bool ReadFromFileOrPrefetched(char* prefetch_buf,
330 int file_size,
331 int offset,
332 int size,
333 char* dest);
334
335 // Extracts out the payload of stream |stream_index|, reading either from
336 // [prefetch_buf, prefetch_buf + file_size), if |prefetch_buf| is non-null,
337 // or the file. |entry_stat| will be used to determine file layout, though
338 // |extra_size| additional bytes will be read past the stream payload end.
339 //
340 // |*stream_data| will be pointed to a fresh buffer with the results,
341 // and |*out_crc32| will get the checksum, which will be verified against
342 // |eof_record|.
343 int PreReadStreamPayload(char* prefetch_buf,
344 int file_size,
345 int stream_index,
346 int extra_size,
347 const SimpleEntryStat& entry_stat,
348 const SimpleFileEOF& eof_record,
349 scoped_refptr<net::GrowableIOBuffer>* stream_data,
350 uint32_t* out_crc32);
351
310 void Doom() const; 352 void Doom() const;
311 353
312 // Opens the sparse data file and scans it if it exists. 354 // Opens the sparse data file and scans it if it exists.
313 bool OpenSparseFileIfExists(int32_t* out_sparse_data_size); 355 bool OpenSparseFileIfExists(int32_t* out_sparse_data_size);
314 356
315 // Creates and initializes the sparse data file. 357 // Creates and initializes the sparse data file.
316 bool CreateSparseFile(); 358 bool CreateSparseFile();
317 359
318 // Closes the sparse data file. 360 // Closes the sparse data file.
319 void CloseSparseFile(); 361 void CloseSparseFile();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 int64_t sparse_tail_offset_; 431 int64_t sparse_tail_offset_;
390 432
391 // True if the entry was created, or false if it was opened. Used to log 433 // True if the entry was created, or false if it was opened. Used to log
392 // SimpleCache.*.EntryCreatedWithStream2Omitted only for created entries. 434 // SimpleCache.*.EntryCreatedWithStream2Omitted only for created entries.
393 bool files_created_; 435 bool files_created_;
394 }; 436 };
395 437
396 } // namespace disk_cache 438 } // namespace disk_cache
397 439
398 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_ 440 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698