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

Issue 1222153004: [tracing] Simplify and improve thread-hopping logic of memory-infra (Closed)

Created:
5 years, 5 months ago by Primiano Tucci (use gerrit)
Modified:
5 years, 5 months ago
Reviewers:
dsinclair, petrcermak
CC:
chromium-reviews, tracing+reviews_chromium.org, wfh+watch_chromium.org, erikwright+watch_chromium.org, jam, darin-cc_chromium.org
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

[tracing] Simplify and improve thread-hopping logic of memory-infra By contract MemoryDumpManager invokes the MemoryDumpProvider's OnMemoryDump() method on the thread specified (by the MDP) in the RegisterDumpProvider() call. At the same time, it guarantees that at most one MDP is enabled at any time. This is to avoid to have the MDPs dealing with thread-safety. Assuming to have the following situation: MDP_1 @ Thread_A, MDP_2 @ Thread_B, MDP_3 @ Thread_A, MDP_4 @ Thread_B The way ProcessMemoryDump would have acted before this change is: CreateProcessDump(): PostTask(Thread_A, ContinueAsyncProcessDump(MDP_1)) PostTask(Thread_B, ContinueAsyncProcessDump(MDP_2)) PostTask(Thread_A, ContinueAsyncProcessDump(MDP_3)) PostTask(Thread_B, ContinueAsyncProcessDump(MDP_4)) On each ContinueAsyncProcessDump() in each thread: AutoLock(lock_) MDP_X->OnMemoryDump() if (last_dump) FinalizeAndAddToTrace() This strategy has two problems: 1) performance-wise: it is suboptimal, as it performs more thread hops than necessary (ABAB instead of just AB). 2) It is deadlock prone: essentially this spawns N tasks on various threads and then linearizes them on the |lock_|. This can cause deadlocks if other tasks on the message loops have dependencies. This is the case of crbug.com/505725, which is fixed by this CL. The new strategy is conceptually simpler, smarter and avoids inter-locking the message loops, as follows: - The MDPs are kept in order according to their thread affinity. - When CreateProcessDump() is invoked, only one task (the first in the set) is posted. - Each task, which corresponds to an invocation of ContinueAsyncProcessDump() invokes the dump provider without taking the lock_. When done posts the next task (or finalizes the dump). By posting one task at a time we still guarantee that the OnMemoryDump calls are linearized (per PMD) even if the lock is not taken. Furthermore, given the order of the MDP set, the thread hopping is reduced to the minimum. The only tricky part of this CL is dealing with changes of the dump providers (i.e. calls to (Un)RegisterDumpProvider) while an asynchronous process dump is in progress. In this (very unlikely) case the choice is to abort the current dump. BUG=497144, 505725 Committed: https://crrev.com/ca7a49016df9b30f326811246d70f7472dea4d66 Cr-Commit-Position: refs/heads/master@{#337580}

Patch Set 1 #

Patch Set 2 : Add test #

Patch Set 3 : Fix win #

Total comments: 51

Patch Set 4 : petrcermak's review #

Total comments: 1

Patch Set 5 : Re dsinclair #7 #

Unified diffs Side-by-side diffs Delta from patch set Stats (+366 lines, -217 lines) Patch
M base/trace_event/memory_dump_manager.h View 1 2 3 6 chunks +72 lines, -22 lines 0 comments Download
M base/trace_event/memory_dump_manager.cc View 1 2 3 4 10 chunks +205 lines, -191 lines 0 comments Download
M base/trace_event/memory_dump_manager_unittest.cc View 1 2 3 7 chunks +85 lines, -4 lines 0 comments Download
M content/browser/tracing/tracing_controller_impl.cc View 1 1 chunk +4 lines, -0 lines 0 comments Download

Messages

Total messages: 12 (4 generated)
Primiano Tucci (use gerrit)
Dan, Petr, can I ask all your four eyes on this? I will write tests ...
5 years, 5 months ago (2015-07-02 15:37:26 UTC) #2
petrcermak
This is some really great work!!! Just a couple of mostly style comments... Thanks, Petr ...
5 years, 5 months ago (2015-07-03 11:04:17 UTC) #4
Primiano Tucci (use gerrit)
https://codereview.chromium.org/1222153004/diff/60001/base/trace_event/memory_dump_manager.cc File base/trace_event/memory_dump_manager.cc (right): https://codereview.chromium.org/1222153004/diff/60001/base/trace_event/memory_dump_manager.cc#newcode174 base/trace_event/memory_dump_manager.cc:174: << " Please file a crbug."; On 2015/07/03 11:04:15, ...
5 years, 5 months ago (2015-07-03 15:05:45 UTC) #5
petrcermak
LGTM. Thanks! Petr
5 years, 5 months ago (2015-07-03 15:20:09 UTC) #6
dsinclair
lgtm w/ nit. https://codereview.chromium.org/1222153004/diff/80001/base/trace_event/memory_dump_manager.cc File base/trace_event/memory_dump_manager.cc (right): https://codereview.chromium.org/1222153004/diff/80001/base/trace_event/memory_dump_manager.cc#newcode331 base/trace_event/memory_dump_manager.cc:331: "(crbug.com/461788), disabling it for current process. ...
5 years, 5 months ago (2015-07-06 17:40:25 UTC) #7
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1222153004/100001
5 years, 5 months ago (2015-07-07 08:50:52 UTC) #10
commit-bot: I haz the power
Committed patchset #5 (id:100001)
5 years, 5 months ago (2015-07-07 10:28:50 UTC) #11
commit-bot: I haz the power
5 years, 5 months ago (2015-07-07 10:29:44 UTC) #12
Message was sent while issue was closed.
Patchset 5 (id:??) landed as
https://crrev.com/ca7a49016df9b30f326811246d70f7472dea4d66
Cr-Commit-Position: refs/heads/master@{#337580}

Powered by Google App Engine
This is Rietveld 408576698