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

Side by Side Diff: content/browser/memory/memory_coordinator_impl.cc

Issue 2731913002: NotForReview: Expose the global memory budget (chromium side)
Patch Set: Add --simulate-memory-pressure Created 3 years, 9 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/browser/memory/memory_coordinator_impl.h" 5 #include "content/browser/memory/memory_coordinator_impl.h"
6 6
7 #include "base/memory/memory_coordinator_client_registry.h" 7 #include "base/memory/memory_coordinator_client_registry.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/process/process_handle.h" 10 #include "base/process/process_handle.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 // for the role of this class. 82 // for the role of this class.
83 class MemoryCoordinatorHandleImpl : public mojom::MemoryCoordinatorHandle { 83 class MemoryCoordinatorHandleImpl : public mojom::MemoryCoordinatorHandle {
84 public: 84 public:
85 MemoryCoordinatorHandleImpl(mojom::MemoryCoordinatorHandleRequest request, 85 MemoryCoordinatorHandleImpl(mojom::MemoryCoordinatorHandleRequest request,
86 MemoryCoordinatorImpl* coordinator, 86 MemoryCoordinatorImpl* coordinator,
87 int render_process_id); 87 int render_process_id);
88 ~MemoryCoordinatorHandleImpl() override; 88 ~MemoryCoordinatorHandleImpl() override;
89 89
90 // mojom::MemoryCoordinatorHandle: 90 // mojom::MemoryCoordinatorHandle:
91 void AddChild(mojom::ChildMemoryCoordinatorPtr child) override; 91 void AddChild(mojom::ChildMemoryCoordinatorPtr child) override;
92 void GetGlobalBudgetHandle(
93 const GetGlobalBudgetHandleCallback& callback) override {
94 auto handle = coordinator_->global_budget_handle_->Clone(
95 mojo::SharedBufferHandle::AccessMode::READ_ONLY);
96 callback.Run(std::move(handle));
97 }
98 void SetGlobalBudgetUpdateInterval(uint32_t interval_ms) override {
99 base::TimeDelta interval = base::TimeDelta::FromMilliseconds(interval_ms);
100 coordinator_->condition_observer_->ScheduleUpdateCondition(interval);
101 }
92 102
93 mojom::ChildMemoryCoordinatorPtr& child() { return child_; } 103 mojom::ChildMemoryCoordinatorPtr& child() { return child_; }
94 mojo::Binding<mojom::MemoryCoordinatorHandle>& binding() { return binding_; } 104 mojo::Binding<mojom::MemoryCoordinatorHandle>& binding() { return binding_; }
95 105
96 private: 106 private:
97 MemoryCoordinatorImpl* coordinator_; 107 MemoryCoordinatorImpl* coordinator_;
98 int render_process_id_; 108 int render_process_id_;
99 mojom::ChildMemoryCoordinatorPtr child_; 109 mojom::ChildMemoryCoordinatorPtr child_;
100 mojo::Binding<mojom::MemoryCoordinatorHandle> binding_; 110 mojo::Binding<mojom::MemoryCoordinatorHandle> binding_;
101 111
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 MemoryCoordinatorImplSingletonTraits>::get(); 154 MemoryCoordinatorImplSingletonTraits>::get();
145 } 155 }
146 156
147 MemoryCoordinatorImpl::MemoryCoordinatorImpl( 157 MemoryCoordinatorImpl::MemoryCoordinatorImpl(
148 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 158 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
149 std::unique_ptr<MemoryMonitor> memory_monitor) 159 std::unique_ptr<MemoryMonitor> memory_monitor)
150 : delegate_(GetContentClient()->browser()->GetMemoryCoordinatorDelegate()), 160 : delegate_(GetContentClient()->browser()->GetMemoryCoordinatorDelegate()),
151 memory_monitor_(std::move(memory_monitor)), 161 memory_monitor_(std::move(memory_monitor)),
152 condition_observer_( 162 condition_observer_(
153 base::MakeUnique<MemoryConditionObserver>(this, task_runner)), 163 base::MakeUnique<MemoryConditionObserver>(this, task_runner)),
154 minimum_state_transition_period_(base::TimeDelta::FromSeconds( 164 minimum_state_transition_period_(
155 kDefaultMinimumTransitionPeriodSeconds)) { 165 base::TimeDelta::FromSeconds(kDefaultMinimumTransitionPeriodSeconds)),
166 global_budget_handle_(mojo::SharedBufferHandle::Create(sizeof(int64_t))),
167 global_budget_mapping_(global_budget_handle_->Map(sizeof(int64_t))) {
156 DCHECK(memory_monitor_.get()); 168 DCHECK(memory_monitor_.get());
169 DCHECK(global_budget_mapping_.get());
157 base::MemoryCoordinatorProxy::SetMemoryCoordinator(this); 170 base::MemoryCoordinatorProxy::SetMemoryCoordinator(this);
171 UpdateGlobalBudget(-1);
158 } 172 }
159 173
160 MemoryCoordinatorImpl::~MemoryCoordinatorImpl() { 174 MemoryCoordinatorImpl::~MemoryCoordinatorImpl() {
161 base::MemoryCoordinatorProxy::SetMemoryCoordinator(nullptr); 175 base::MemoryCoordinatorProxy::SetMemoryCoordinator(nullptr);
162 } 176 }
163 177
164 void MemoryCoordinatorImpl::Start() { 178 void MemoryCoordinatorImpl::Start() {
165 DCHECK(CalledOnValidThread()); 179 DCHECK(CalledOnValidThread());
166 DCHECK(last_state_change_.is_null()); 180 DCHECK(last_state_change_.is_null());
167 181
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 239
226 void MemoryCoordinatorImpl::RecordMemoryPressure( 240 void MemoryCoordinatorImpl::RecordMemoryPressure(
227 base::MemoryPressureMonitor::MemoryPressureLevel level) { 241 base::MemoryPressureMonitor::MemoryPressureLevel level) {
228 // TODO(bashi): Record memory pressure level. 242 // TODO(bashi): Record memory pressure level.
229 } 243 }
230 244
231 MemoryState MemoryCoordinatorImpl::GetCurrentMemoryState() const { 245 MemoryState MemoryCoordinatorImpl::GetCurrentMemoryState() const {
232 return browser_memory_state_; 246 return browser_memory_state_;
233 } 247 }
234 248
249 int64_t MemoryCoordinatorImpl::GetGlobalBudget() {
250 return *reinterpret_cast<int64_t*>(global_budget_mapping_.get());
251 }
252
253 void MemoryCoordinatorImpl::SetGlobalBudgetUpdateInterval(
254 uint32_t interval_ms) {
255 condition_observer_->ScheduleUpdateCondition(
256 base::TimeDelta::FromMilliseconds(interval_ms));
257 }
258
235 void MemoryCoordinatorImpl::ForceSetMemoryCondition(MemoryCondition condition, 259 void MemoryCoordinatorImpl::ForceSetMemoryCondition(MemoryCondition condition,
236 base::TimeDelta duration) { 260 base::TimeDelta duration) {
237 UpdateConditionIfNeeded(condition); 261 UpdateConditionIfNeeded(condition);
238 condition_observer_->ScheduleUpdateCondition(duration); 262 condition_observer_->ScheduleUpdateCondition(duration);
239 } 263 }
240 264
241 void MemoryCoordinatorImpl::Observe(int type, 265 void MemoryCoordinatorImpl::Observe(int type,
242 const NotificationSource& source, 266 const NotificationSource& source,
243 const NotificationDetails& details) { 267 const NotificationDetails& details) {
244 DCHECK(type == NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED); 268 DCHECK(type == NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 SetChildMemoryState(iter.first, state); 326 SetChildMemoryState(iter.first, state);
303 } 327 }
304 // Idea: Purge memory from background processes. 328 // Idea: Purge memory from background processes.
305 } else if (next_condition == MemoryCondition::CRITICAL) { 329 } else if (next_condition == MemoryCondition::CRITICAL) {
306 // Set THROTTLED state to all clients/processes. 330 // Set THROTTLED state to all clients/processes.
307 UpdateBrowserStateAndNotifyStateToClients(MemoryState::THROTTLED); 331 UpdateBrowserStateAndNotifyStateToClients(MemoryState::THROTTLED);
308 NotifyStateToChildren(MemoryState::THROTTLED); 332 NotifyStateToChildren(MemoryState::THROTTLED);
309 } 333 }
310 } 334 }
311 335
336 void MemoryCoordinatorImpl::UpdateGlobalBudget(int budget) {
337 *reinterpret_cast<int64_t*>(global_budget_mapping_.get()) = budget;
338 }
339
312 void MemoryCoordinatorImpl::DiscardTab() { 340 void MemoryCoordinatorImpl::DiscardTab() {
313 if (delegate_) 341 if (delegate_)
314 delegate_->DiscardTab(); 342 delegate_->DiscardTab();
315 } 343 }
316 344
317 RenderProcessHost* MemoryCoordinatorImpl::GetRenderProcessHost( 345 RenderProcessHost* MemoryCoordinatorImpl::GetRenderProcessHost(
318 int render_process_id) { 346 int render_process_id) {
319 return RenderProcessHost::FromID(render_process_id); 347 return RenderProcessHost::FromID(render_process_id);
320 } 348 }
321 349
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 463
436 MemoryCoordinatorImpl::ChildInfo::ChildInfo() {} 464 MemoryCoordinatorImpl::ChildInfo::ChildInfo() {}
437 465
438 MemoryCoordinatorImpl::ChildInfo::ChildInfo(const ChildInfo& rhs) { 466 MemoryCoordinatorImpl::ChildInfo::ChildInfo(const ChildInfo& rhs) {
439 // This is a nop, but exists for compatibility with STL containers. 467 // This is a nop, but exists for compatibility with STL containers.
440 } 468 }
441 469
442 MemoryCoordinatorImpl::ChildInfo::~ChildInfo() {} 470 MemoryCoordinatorImpl::ChildInfo::~ChildInfo() {}
443 471
444 } // namespace content 472 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/memory/memory_coordinator_impl.h ('k') | content/child/memory/child_memory_coordinator_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698