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

Side by Side Diff: net/disk_cache/simple/simple_entry_impl.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_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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
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,
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 first_stream1_read_; // used for metrics only.
pasko 2017/07/18 13:46:31 nit: for less ambiguity: is_initial_stream1_read?
Maks Orlovich 2017/07/21 18:37:33 Done.
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 // SimpleEntryImpl should not be deleted while an operation is running as that 393 // SimpleEntryImpl should not be deleted while an operation is running as that
387 // would leak the SimpleSynchronousEntry. 394 // would leak the SimpleSynchronousEntry.
388 SimpleSynchronousEntry* synchronous_entry_; 395 SimpleSynchronousEntry* synchronous_entry_;
389 396
390 std::queue<SimpleEntryOperation> pending_operations_; 397 std::queue<SimpleEntryOperation> pending_operations_;
391 398
392 net::NetLogWithSource net_log_; 399 net::NetLogWithSource net_log_;
393 400
394 std::unique_ptr<SimpleEntryOperation> executing_operation_; 401 std::unique_ptr<SimpleEntryOperation> executing_operation_;
395 402
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
pasko 2017/07/18 13:46:31 this "Unlike other streams" will need to be update
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
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