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

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

Issue 2874833005: SimpleCache: read small files all at once. (Closed)
Patch Set: Group and array up data + crc to cut down on code dupe and excessive arg counts. Created 3 years, 4 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_ENTRY_IMPL_H_ 5 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_
6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_ 6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 SimpleEntryImpl(net::CacheType cache_type, 75 SimpleEntryImpl(net::CacheType cache_type,
76 const base::FilePath& path, 76 const base::FilePath& path,
77 uint64_t entry_hash, 77 uint64_t entry_hash,
78 OperationsMode operations_mode, 78 OperationsMode operations_mode,
79 SimpleBackendImpl* backend, 79 SimpleBackendImpl* backend,
80 net::NetLog* net_log); 80 net::NetLog* net_log);
81 81
82 void SetActiveEntryProxy( 82 void SetActiveEntryProxy(
83 std::unique_ptr<ActiveEntryProxy> active_entry_proxy); 83 std::unique_ptr<ActiveEntryProxy> active_entry_proxy);
84 84
85 // Adds another reader/writer to this entry, if possible, returning |this| to 85 // Adds another reader/writer to this entry, if possible, returning |this| to
pasko 2017/08/04 01:28:34 nit: perhaps mention somewhere in this file that i
Maks Orlovich 2017/08/04 18:35:44 Acknowledged.
pasko 2017/08/09 12:28:21 sry, it was a leftover comment when I thought that
86 // |entry|. 86 // |entry|.
87 int OpenEntry(Entry** entry, const CompletionCallback& callback); 87 int OpenEntry(Entry** entry, const CompletionCallback& callback);
88 88
89 // Creates this entry, if possible. Returns |this| to |entry|. 89 // Creates this entry, if possible. Returns |this| to |entry|.
pasko 2017/08/04 01:28:34 same nit about comment as OpenEntry
Maks Orlovich 2017/08/04 18:35:44 Doesn't apply since Create fails if the entry alre
pasko 2017/08/09 12:28:21 Acknowledged.
90 int CreateEntry(Entry** entry, const CompletionCallback& callback); 90 int CreateEntry(Entry** entry, const CompletionCallback& callback);
91 91
92 // Identical to Backend::Doom() except that it accepts a CompletionCallback. 92 // Identical to Backend::Doom() except that it accepts a CompletionCallback.
93 int DoomEntry(const CompletionCallback& callback); 93 int DoomEntry(const CompletionCallback& callback);
94 94
95 const std::string& key() const { return key_; } 95 const std::string& key() const { return key_; }
96 uint64_t entry_hash() const { return entry_hash_; } 96 uint64_t entry_hash() const { return entry_hash_; }
97 97
98 // The key is not a constructor parameter to the SimpleEntryImpl, because 98 // The key is not a constructor parameter to the SimpleEntryImpl, because
99 // during cache iteration, it's necessary to open entries by their hash 99 // during cache iteration, it's necessary to open entries by their hash
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 void DoomOperationComplete(const CompletionCallback& callback, 294 void DoomOperationComplete(const CompletionCallback& callback,
295 State state_to_restore, 295 State state_to_restore,
296 int result); 296 int result);
297 297
298 // Reports reads result potentially refining status based on |crc_result|. 298 // Reports reads result potentially refining status based on |crc_result|.
299 // |crc_result| is permitted to be null. 299 // |crc_result| is permitted to be null.
300 void RecordReadResultConsideringChecksum( 300 void RecordReadResultConsideringChecksum(
301 int result, 301 int result,
302 std::unique_ptr<SimpleSynchronousEntry::CRCRequest> crc_result) const; 302 std::unique_ptr<SimpleSynchronousEntry::CRCRequest> crc_result) const;
303 303
304 // Called after completion of asynchronous IO and receiving file metadata for 304 // Called after completion of asynchronous IO and receiving file metadata for
pasko 2017/08/04 01:28:34 it can also be called after reading the stream fro
Maks Orlovich 2017/08/04 18:35:43 Rephrased.
305 // the entry in |entry_stat|. Updates the metadata in the entry and in the 305 // the entry in |entry_stat|. Updates the metadata in the entry and in the
306 // index to make them available on next IO operations. 306 // index to make them available on next IO operations.
307 void UpdateDataFromEntryStat(const SimpleEntryStat& entry_stat); 307 void UpdateDataFromEntryStat(const SimpleEntryStat& entry_stat);
308 308
309 int64_t GetDiskUsage() const; 309 int64_t GetDiskUsage() const;
310 310
311 // Used to report histograms. 311 // Used to report histograms.
312 void RecordReadIsParallelizable(const SimpleEntryOperation& operation) const; 312 void RecordReadIsParallelizable(const SimpleEntryOperation& operation) const;
313 void RecordWriteDependencyType(const SimpleEntryOperation& operation) const; 313 void RecordWriteDependencyType(const SimpleEntryOperation& operation) const;
314 314
315 // Reads from the stream 0 data kept in memory. 315 // Completes a read from the stream data kept in memory, logging metrics
316 int ReadStream0Data(net::IOBuffer* buf, int offset, int buf_len); 316 // and updating metadata as appropriate. If |callback| is non-null, it will
317 // be posted to with the return code.
318 void ReadInMemoryStreamData(net::GrowableIOBuffer* in_buf,
pasko 2017/08/04 01:28:34 naming bikeshed: 'Stream' is slightly confusing be
Maks Orlovich 2017/08/04 18:35:44 Done.
319 int offset,
320 int buf_len,
321 net::IOBuffer* out_buf,
322 const CompletionCallback& callback);
317 323
318 // Copies data from |buf| to the internal in-memory buffer for stream 0. If 324 // Copies data from |buf| to the internal in-memory buffer for stream 0. If
319 // |truncate| is set to true, the target buffer will be truncated at |offset| 325 // |truncate| is set to true, the target buffer will be truncated at |offset|
320 // + |buf_len| before being written. 326 // + |buf_len| before being written.
321 int SetStream0Data(net::IOBuffer* buf, 327 int SetStream0Data(net::IOBuffer* buf,
322 int offset, int buf_len, 328 int offset, int buf_len,
323 bool truncate); 329 bool truncate);
324 330
325 // Updates |crc32s_| and |crc32s_end_offset_| for a write of the data in 331 // Updates |crc32s_| and |crc32s_end_offset_| for a write of the data in
326 // |buffer| on |stream_index|, starting at |offset| and of length |length|. 332 // |buffer| on |stream_index|, starting at |offset| and of length |length|.
327 void AdvanceCrc(net::IOBuffer* buffer, 333 void AdvanceCrc(net::IOBuffer* buffer,
328 int offset, 334 int offset,
329 int length, 335 int length,
330 int stream_index); 336 int stream_index);
331 337
332 std::unique_ptr<ActiveEntryProxy> active_entry_proxy_; 338 std::unique_ptr<ActiveEntryProxy> active_entry_proxy_;
333 339
334 // All nonstatic SimpleEntryImpl methods should always be called on the IO 340 // All nonstatic SimpleEntryImpl methods should always be called on the IO
335 // thread, in all cases. |io_thread_checker_| documents and enforces this. 341 // thread, in all cases. |io_thread_checker_| documents and enforces this.
336 base::ThreadChecker io_thread_checker_; 342 base::ThreadChecker io_thread_checker_;
337 343
338 const base::WeakPtr<SimpleBackendImpl> backend_; 344 const base::WeakPtr<SimpleBackendImpl> backend_;
339 const net::CacheType cache_type_; 345 const net::CacheType cache_type_;
340 const scoped_refptr<base::TaskRunner> worker_pool_; 346 const scoped_refptr<base::TaskRunner> worker_pool_;
341 const base::FilePath path_; 347 const base::FilePath path_;
342 const uint64_t entry_hash_; 348 const uint64_t entry_hash_;
343 const bool use_optimistic_operations_; 349 const bool use_optimistic_operations_;
350 bool is_initial_stream1_read_; // used for metrics only.
344 std::string key_; 351 std::string key_;
345 352
346 // |last_used_|, |last_modified_| and |data_size_| are copied from the 353 // |last_used_|, |last_modified_| and |data_size_| are copied from the
347 // synchronous entry at the completion of each item of asynchronous IO. 354 // synchronous entry at the completion of each item of asynchronous IO.
348 // TODO(clamy): Unify last_used_ with data in the index. 355 // TODO(clamy): Unify last_used_ with data in the index.
349 base::Time last_used_; 356 base::Time last_used_;
350 base::Time last_modified_; 357 base::Time last_modified_;
351 int32_t data_size_[kSimpleEntryStreamCount]; 358 int32_t data_size_[kSimpleEntryStreamCount];
352 int32_t sparse_data_size_; 359 int32_t sparse_data_size_;
353 360
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 // Unlike other streams, stream 0 data is read from the disk when the entry is 403 // Unlike other streams, stream 0 data is read from the disk when the entry is
397 // opened, and then kept in memory. All read/write operations on stream 0 404 // opened, and then kept in memory. All read/write operations on stream 0
398 // affect the |stream_0_data_| buffer. When the entry is closed, 405 // affect the |stream_0_data_| buffer. When the entry is closed,
399 // |stream_0_data_| is written to the disk. 406 // |stream_0_data_| is written to the disk.
400 // Stream 0 is kept in memory because it is stored in the same file as stream 407 // Stream 0 is kept in memory because it is stored in the same file as stream
401 // 1 on disk, to reduce the number of file descriptors and save disk space. 408 // 1 on disk, to reduce the number of file descriptors and save disk space.
402 // This strategy allows stream 1 to change size easily. Since stream 0 is only 409 // This strategy allows stream 1 to change size easily. Since stream 0 is only
403 // used to write HTTP headers, the memory consumption of keeping it in memory 410 // used to write HTTP headers, the memory consumption of keeping it in memory
404 // is acceptable. 411 // is acceptable.
405 scoped_refptr<net::GrowableIOBuffer> stream_0_data_; 412 scoped_refptr<net::GrowableIOBuffer> stream_0_data_;
413
414 // Sometimes stream 1 data is prefetched when stream 0 is first read, to make
415 // the first read call on stream 1 synchronous. If a write to the stream
pasko 2017/08/04 01:28:34 oops, it's not synchronous because we PostTask eve
Maks Orlovich 2017/08/04 18:35:43 So did I, actually. I think this was the original
416 // occurs on the entry the prefetch buffer is discarded. It may also be
417 // null if it wasn't prefetched in the first place.
418 scoped_refptr<net::GrowableIOBuffer> stream_1_prefetch_data_;
406 }; 419 };
407 420
408 } // namespace disk_cache 421 } // namespace disk_cache
409 422
410 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_ 423 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698