Commit 1714b616 authored by tzik's avatar tzik Committed by Commit bot

Avoid cross thread malloc/free pair of IOBuffer on the simple cache

This CL removes a cross thread malloc/free pair from simple disk cache backend.

After a PostTaskAndReply change in http://crrev.com/e5de8d551e80115b, it
destroys |task| part of the given tasks on the target thread, and that
introduced a number of cross thread malloc/free pairs around net::IOBuffer.
The cross thread malloc/free pair increased the apparent size of memory
usage on some Android perf bots by 2~3%, that is likely due to thread
specific free list caches.

BUG=708644

Review-Url: https://codereview.chromium.org/2815563002
Cr-Commit-Position: refs/heads/master@{#464338}
parent 998f8e57
...@@ -973,17 +973,18 @@ void SimpleEntryImpl::WriteDataInternal(int stream_index, ...@@ -973,17 +973,18 @@ void SimpleEntryImpl::WriteDataInternal(int stream_index,
have_written_[0] = true; have_written_[0] = true;
std::unique_ptr<int> result(new int()); std::unique_ptr<int> result(new int());
// Retain a reference to |buf| in |reply| instead of |task|, so that we can
// reduce cross thread malloc/free pairs. The cross thread malloc/free pair
// increases the apparent memory usage due to the thread cached free list.
Closure task = base::Bind( Closure task = base::Bind(
&SimpleSynchronousEntry::WriteData, base::Unretained(synchronous_entry_), &SimpleSynchronousEntry::WriteData, base::Unretained(synchronous_entry_),
SimpleSynchronousEntry::EntryOperationData(stream_index, offset, buf_len, SimpleSynchronousEntry::EntryOperationData(stream_index, offset, buf_len,
truncate, doomed_), truncate, doomed_),
base::RetainedRef(buf), entry_stat.get(), result.get()); base::Unretained(buf), entry_stat.get(), result.get());
Closure reply = base::Bind(&SimpleEntryImpl::WriteOperationComplete, Closure reply = base::Bind(&SimpleEntryImpl::WriteOperationComplete, this,
this, stream_index, callback, base::Passed(&entry_stat),
stream_index, base::Passed(&result), base::RetainedRef(buf));
callback,
base::Passed(&entry_stat),
base::Passed(&result));
worker_pool_->PostTaskAndReply(FROM_HERE, task, reply); worker_pool_->PostTaskAndReply(FROM_HERE, task, reply);
} }
...@@ -1271,7 +1272,8 @@ void SimpleEntryImpl::WriteOperationComplete( ...@@ -1271,7 +1272,8 @@ void SimpleEntryImpl::WriteOperationComplete(
int stream_index, int stream_index,
const CompletionCallback& completion_callback, const CompletionCallback& completion_callback,
std::unique_ptr<SimpleEntryStat> entry_stat, std::unique_ptr<SimpleEntryStat> entry_stat,
std::unique_ptr<int> result) { std::unique_ptr<int> result,
net::IOBuffer* buf) {
if (*result >= 0) if (*result >= 0)
RecordWriteResult(cache_type_, WRITE_RESULT_SUCCESS); RecordWriteResult(cache_type_, WRITE_RESULT_SUCCESS);
else else
......
...@@ -253,10 +253,14 @@ class NET_EXPORT_PRIVATE SimpleEntryImpl : public Entry, ...@@ -253,10 +253,14 @@ class NET_EXPORT_PRIVATE SimpleEntryImpl : public Entry,
std::unique_ptr<int> result); std::unique_ptr<int> result);
// Called after an asynchronous write completes. // Called after an asynchronous write completes.
// |buf| parameter brings back a reference to net::IOBuffer to the original
// thread, so that we can reduce cross thread malloc/free pair.
// See http://crbug.com/708644 for details.
void WriteOperationComplete(int stream_index, void WriteOperationComplete(int stream_index,
const CompletionCallback& completion_callback, const CompletionCallback& completion_callback,
std::unique_ptr<SimpleEntryStat> entry_stat, std::unique_ptr<SimpleEntryStat> entry_stat,
std::unique_ptr<int> result); std::unique_ptr<int> result,
net::IOBuffer* buf);
void ReadSparseOperationComplete( void ReadSparseOperationComplete(
const CompletionCallback& completion_callback, const CompletionCallback& completion_callback,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment