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

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

Issue 2815563002: Avoid cross thread malloc / free pair of IOBuffer on the simple cache (Closed)
Patch Set: +comment Created 3 years, 8 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
« no previous file with comments | « net/disk_cache/simple/simple_entry_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "net/disk_cache/simple/simple_entry_impl.h" 5 #include "net/disk_cache/simple/simple_entry_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstring> 8 #include <cstring>
9 #include <limits> 9 #include <limits>
10 #include <utility> 10 #include <utility>
(...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 // |last_modified_| yet, we make this approximation. 966 // |last_modified_| yet, we make this approximation.
967 last_used_ = last_modified_ = base::Time::Now(); 967 last_used_ = last_modified_ = base::Time::Now();
968 968
969 have_written_[stream_index] = true; 969 have_written_[stream_index] = true;
970 // Writing on stream 1 affects the placement of stream 0 in the file, the EOF 970 // Writing on stream 1 affects the placement of stream 0 in the file, the EOF
971 // record will have to be rewritten. 971 // record will have to be rewritten.
972 if (stream_index == 1) 972 if (stream_index == 1)
973 have_written_[0] = true; 973 have_written_[0] = true;
974 974
975 std::unique_ptr<int> result(new int()); 975 std::unique_ptr<int> result(new int());
976
977 // Retain a reference to |buf| in |reply| instead of |task|, so that we can
978 // reduce cross thread malloc/free pairs. The cross thread malloc/free pair
979 // increases the apparent memory usage due to the thread cached free list.
976 Closure task = base::Bind( 980 Closure task = base::Bind(
977 &SimpleSynchronousEntry::WriteData, base::Unretained(synchronous_entry_), 981 &SimpleSynchronousEntry::WriteData, base::Unretained(synchronous_entry_),
978 SimpleSynchronousEntry::EntryOperationData(stream_index, offset, buf_len, 982 SimpleSynchronousEntry::EntryOperationData(stream_index, offset, buf_len,
979 truncate, doomed_), 983 truncate, doomed_),
980 base::RetainedRef(buf), entry_stat.get(), result.get()); 984 base::Unretained(buf), entry_stat.get(), result.get());
981 Closure reply = base::Bind(&SimpleEntryImpl::WriteOperationComplete, 985 Closure reply = base::Bind(&SimpleEntryImpl::WriteOperationComplete, this,
982 this, 986 stream_index, callback, base::Passed(&entry_stat),
983 stream_index, 987 base::Passed(&result), base::RetainedRef(buf));
984 callback,
985 base::Passed(&entry_stat),
986 base::Passed(&result));
987 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply); 988 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply);
988 } 989 }
989 990
990 void SimpleEntryImpl::ReadSparseDataInternal( 991 void SimpleEntryImpl::ReadSparseDataInternal(
991 int64_t sparse_offset, 992 int64_t sparse_offset,
992 net::IOBuffer* buf, 993 net::IOBuffer* buf,
993 int buf_len, 994 int buf_len,
994 const CompletionCallback& callback) { 995 const CompletionCallback& callback) {
995 DCHECK(io_thread_checker_.CalledOnValidThread()); 996 DCHECK(io_thread_checker_.CalledOnValidThread());
996 ScopedOperationRunner operation_runner(this); 997 ScopedOperationRunner operation_runner(this);
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
1264 CreateNetLogReadWriteCompleteCallback(*result)); 1265 CreateNetLogReadWriteCompleteCallback(*result));
1265 } 1266 }
1266 1267
1267 EntryOperationComplete(completion_callback, *entry_stat, std::move(result)); 1268 EntryOperationComplete(completion_callback, *entry_stat, std::move(result));
1268 } 1269 }
1269 1270
1270 void SimpleEntryImpl::WriteOperationComplete( 1271 void SimpleEntryImpl::WriteOperationComplete(
1271 int stream_index, 1272 int stream_index,
1272 const CompletionCallback& completion_callback, 1273 const CompletionCallback& completion_callback,
1273 std::unique_ptr<SimpleEntryStat> entry_stat, 1274 std::unique_ptr<SimpleEntryStat> entry_stat,
1274 std::unique_ptr<int> result) { 1275 std::unique_ptr<int> result,
1276 net::IOBuffer* buf) {
1275 if (*result >= 0) 1277 if (*result >= 0)
1276 RecordWriteResult(cache_type_, WRITE_RESULT_SUCCESS); 1278 RecordWriteResult(cache_type_, WRITE_RESULT_SUCCESS);
1277 else 1279 else
1278 RecordWriteResult(cache_type_, WRITE_RESULT_SYNC_WRITE_FAILURE); 1280 RecordWriteResult(cache_type_, WRITE_RESULT_SYNC_WRITE_FAILURE);
1279 if (net_log_.IsCapturing()) { 1281 if (net_log_.IsCapturing()) {
1280 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_WRITE_END, 1282 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_WRITE_END,
1281 CreateNetLogReadWriteCompleteCallback(*result)); 1283 CreateNetLogReadWriteCompleteCallback(*result));
1282 } 1284 }
1283 1285
1284 if (*result < 0) { 1286 if (*result < 0) {
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
1562 } 1564 }
1563 crc32s_end_offset_[stream_index] = offset + length; 1565 crc32s_end_offset_[stream_index] = offset + length;
1564 } else if (offset < crc32s_end_offset_[stream_index]) { 1566 } else if (offset < crc32s_end_offset_[stream_index]) {
1565 // If a range for which the crc32 was already computed is rewritten, the 1567 // If a range for which the crc32 was already computed is rewritten, the
1566 // computation of the crc32 need to start from 0 again. 1568 // computation of the crc32 need to start from 0 again.
1567 crc32s_end_offset_[stream_index] = 0; 1569 crc32s_end_offset_[stream_index] = 0;
1568 } 1570 }
1569 } 1571 }
1570 1572
1571 } // namespace disk_cache 1573 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/simple/simple_entry_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698