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

Side by Side Diff: content/common/host_discardable_shared_memory_manager.cc

Issue 1306243003: Add support to create memory allocator dump in base::DiscardableMemory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits. Created 5 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/common/host_discardable_shared_memory_manager.h" 5 #include "content/common/host_discardable_shared_memory_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/atomic_sequence_num.h" 9 #include "base/atomic_sequence_num.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 13 matching lines...) Expand all
24 #include "content/common/child_process_host_impl.h" 24 #include "content/common/child_process_host_impl.h"
25 #include "content/common/discardable_shared_memory_heap.h" 25 #include "content/common/discardable_shared_memory_heap.h"
26 #include "content/public/common/child_process_host.h" 26 #include "content/public/common/child_process_host.h"
27 27
28 namespace content { 28 namespace content {
29 namespace { 29 namespace {
30 30
31 class DiscardableMemoryImpl : public base::DiscardableMemory { 31 class DiscardableMemoryImpl : public base::DiscardableMemory {
32 public: 32 public:
33 DiscardableMemoryImpl(scoped_ptr<base::DiscardableSharedMemory> shared_memory, 33 DiscardableMemoryImpl(scoped_ptr<base::DiscardableSharedMemory> shared_memory,
34 size_t size,
reveman 2015/08/21 18:05:24 can we use shared_memory->mapped_size() instead?
ssid 2015/08/24 14:52:10 Done.
34 const base::Closure& deleted_callback) 35 const base::Closure& deleted_callback)
35 : shared_memory_(shared_memory.Pass()), 36 : shared_memory_(shared_memory.Pass()),
37 size_(size),
36 deleted_callback_(deleted_callback), 38 deleted_callback_(deleted_callback),
37 is_locked_(true) {} 39 is_locked_(true) {}
38 40
39 ~DiscardableMemoryImpl() override { 41 ~DiscardableMemoryImpl() override {
40 if (is_locked_) 42 if (is_locked_)
41 shared_memory_->Unlock(0, 0); 43 shared_memory_->Unlock(0, 0);
42 44
43 deleted_callback_.Run(); 45 deleted_callback_.Run();
44 } 46 }
45 47
(...skipping 11 matching lines...) Expand all
57 DCHECK(is_locked_); 59 DCHECK(is_locked_);
58 60
59 shared_memory_->Unlock(0, 0); 61 shared_memory_->Unlock(0, 0);
60 is_locked_ = false; 62 is_locked_ = false;
61 } 63 }
62 void* data() const override { 64 void* data() const override {
63 DCHECK(is_locked_); 65 DCHECK(is_locked_);
64 return shared_memory_->memory(); 66 return shared_memory_->memory();
65 } 67 }
66 68
69 base::trace_event::MemoryAllocatorDump* CreateMemoryAllocatorDump(
70 const char* name,
71 base::trace_event::ProcessMemoryDump* pmd) override {
72 // The memory could have been purged by the heap, but we still create a
reveman 2015/08/21 18:05:24 note: there's no heap in this case
ssid 2015/08/24 14:52:10 Done.
73 // dump. So, the size can be inaccurate.
74 base::trace_event::MemoryAllocatorDump* dump =
75 pmd->CreateAllocatorDump(name);
76 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
77 base::trace_event::MemoryAllocatorDump::kUnitsBytes, size_);
78 return dump;
79 }
80
67 private: 81 private:
68 scoped_ptr<base::DiscardableSharedMemory> shared_memory_; 82 scoped_ptr<base::DiscardableSharedMemory> shared_memory_;
83 size_t size_;
69 const base::Closure deleted_callback_; 84 const base::Closure deleted_callback_;
70 bool is_locked_; 85 bool is_locked_;
71 86
72 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryImpl); 87 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryImpl);
73 }; 88 };
74 89
75 base::LazyInstance<HostDiscardableSharedMemoryManager> 90 base::LazyInstance<HostDiscardableSharedMemoryManager>
76 g_discardable_shared_memory_manager = LAZY_INSTANCE_INITIALIZER; 91 g_discardable_shared_memory_manager = LAZY_INSTANCE_INITIALIZER;
77 92
78 #if defined(OS_ANDROID) 93 #if defined(OS_ANDROID)
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 AllocateLockedDiscardableSharedMemory(current_process_handle, 155 AllocateLockedDiscardableSharedMemory(current_process_handle,
141 ChildProcessHost::kInvalidUniqueID, 156 ChildProcessHost::kInvalidUniqueID,
142 size, new_id, &handle); 157 size, new_id, &handle);
143 CHECK(base::SharedMemory::IsHandleValid(handle)); 158 CHECK(base::SharedMemory::IsHandleValid(handle));
144 scoped_ptr<base::DiscardableSharedMemory> memory( 159 scoped_ptr<base::DiscardableSharedMemory> memory(
145 new base::DiscardableSharedMemory(handle)); 160 new base::DiscardableSharedMemory(handle));
146 CHECK(memory->Map(size)); 161 CHECK(memory->Map(size));
147 // Close file descriptor to avoid running out. 162 // Close file descriptor to avoid running out.
148 memory->Close(); 163 memory->Close();
149 return make_scoped_ptr(new DiscardableMemoryImpl( 164 return make_scoped_ptr(new DiscardableMemoryImpl(
150 memory.Pass(), 165 memory.Pass(), size,
151 base::Bind( 166 base::Bind(
152 &HostDiscardableSharedMemoryManager::DeletedDiscardableSharedMemory, 167 &HostDiscardableSharedMemoryManager::DeletedDiscardableSharedMemory,
153 base::Unretained(this), new_id, ChildProcessHost::kInvalidUniqueID))); 168 base::Unretained(this), new_id, ChildProcessHost::kInvalidUniqueID)));
154 } 169 }
155 170
156 bool HostDiscardableSharedMemoryManager::OnMemoryDump( 171 bool HostDiscardableSharedMemoryManager::OnMemoryDump(
157 const base::trace_event::MemoryDumpArgs& args, 172 const base::trace_event::MemoryDumpArgs& args,
158 base::trace_event::ProcessMemoryDump* pmd) { 173 base::trace_event::ProcessMemoryDump* pmd) {
159 base::AutoLock lock(lock_); 174 base::AutoLock lock(lock_);
160 for (const auto& process_entry : processes_) { 175 for (const auto& process_entry : processes_) {
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 471
457 enforce_memory_policy_pending_ = true; 472 enforce_memory_policy_pending_ = true;
458 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 473 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
459 FROM_HERE, 474 FROM_HERE,
460 base::Bind(&HostDiscardableSharedMemoryManager::EnforceMemoryPolicy, 475 base::Bind(&HostDiscardableSharedMemoryManager::EnforceMemoryPolicy,
461 weak_ptr_factory_.GetWeakPtr()), 476 weak_ptr_factory_.GetWeakPtr()),
462 base::TimeDelta::FromMilliseconds(kEnforceMemoryPolicyDelayMs)); 477 base::TimeDelta::FromMilliseconds(kEnforceMemoryPolicyDelayMs));
463 } 478 }
464 479
465 } // namespace content 480 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698