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

Side by Side Diff: cc/resources/resource_pool.cc

Issue 2130683002: [Experiment] purge-and-suspend Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated Created 4 years, 5 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 "cc/resources/resource_pool.h" 5 #include "cc/resources/resource_pool.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/allocator/allocator_extension.h"
13 #include "base/format_macros.h" 14 #include "base/format_macros.h"
14 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
15 #include "base/threading/thread_task_runner_handle.h" 16 #include "base/threading/thread_task_runner_handle.h"
16 #include "base/trace_event/memory_dump_manager.h" 17 #include "base/trace_event/memory_dump_manager.h"
17 #include "cc/base/container_util.h" 18 #include "cc/base/container_util.h"
18 #include "cc/resources/resource_provider.h" 19 #include "cc/resources/resource_provider.h"
19 #include "cc/resources/resource_util.h" 20 #include "cc/resources/resource_util.h"
20 #include "cc/resources/scoped_resource.h" 21 #include "cc/resources/scoped_resource.h"
21 22
22 namespace cc { 23 namespace cc {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 in_use_memory_usage_bytes_(0), 69 in_use_memory_usage_bytes_(0),
69 total_memory_usage_bytes_(0), 70 total_memory_usage_bytes_(0),
70 total_resource_count_(0), 71 total_resource_count_(0),
71 task_runner_(task_runner), 72 task_runner_(task_runner),
72 evict_expired_resources_pending_(false), 73 evict_expired_resources_pending_(false),
73 resource_expiration_delay_( 74 resource_expiration_delay_(
74 base::TimeDelta::FromMilliseconds(kResourceExpirationDelayMs)), 75 base::TimeDelta::FromMilliseconds(kResourceExpirationDelayMs)),
75 weak_ptr_factory_(this) { 76 weak_ptr_factory_(this) {
76 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( 77 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
77 this, "cc::ResourcePool", task_runner_.get()); 78 this, "cc::ResourcePool", task_runner_.get());
79
80 memory_pressure_listener_.reset(new base::MemoryPressureListener(
81 base::Bind(&ResourcePool::OnMemoryPressure, base::Unretained(this))));
78 } 82 }
79 83
80 ResourcePool::~ResourcePool() { 84 ResourcePool::~ResourcePool() {
81 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( 85 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
82 this); 86 this);
83 87
84 DCHECK_EQ(0u, in_use_resources_.size()); 88 DCHECK_EQ(0u, in_use_resources_.size());
85 89
86 while (!busy_resources_.empty()) { 90 while (!busy_resources_.empty()) {
87 DidFinishUsingResource(PopBack(&busy_resources_)); 91 DidFinishUsingResource(PopBack(&busy_resources_));
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 } 291 }
288 292
289 void ResourcePool::SetResourceUsageLimits(size_t max_memory_usage_bytes, 293 void ResourcePool::SetResourceUsageLimits(size_t max_memory_usage_bytes,
290 size_t max_resource_count) { 294 size_t max_resource_count) {
291 max_memory_usage_bytes_ = max_memory_usage_bytes; 295 max_memory_usage_bytes_ = max_memory_usage_bytes;
292 max_resource_count_ = max_resource_count; 296 max_resource_count_ = max_resource_count;
293 297
294 ReduceResourceUsage(); 298 ReduceResourceUsage();
295 } 299 }
296 300
301 void ResourcePool::OnMemoryPressure(
302 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
303 while (!unused_resources_.empty())
304 DeleteResource(PopBack(&unused_resources_));
305 base::allocator::ReleaseFreeMemory();
esprehn 2016/08/05 23:00:57 yeah...
tasak 2016/08/08 04:47:36 Acknowledged.
306 }
307
297 void ResourcePool::ReduceResourceUsage() { 308 void ResourcePool::ReduceResourceUsage() {
298 while (!unused_resources_.empty()) { 309 while (!unused_resources_.empty()) {
299 if (!ResourceUsageTooHigh()) 310 if (!ResourceUsageTooHigh())
300 break; 311 break;
301 312
302 // LRU eviction pattern. Most recently used might be blocked by 313 // LRU eviction pattern. Most recently used might be blocked by
303 // a read lock fence but it's still better to evict the least 314 // a read lock fence but it's still better to evict the least
304 // recently used as it prevents a resource that is hard to reuse 315 // recently used as it prevents a resource that is hard to reuse
305 // because of unique size from being kept around. Resources that 316 // because of unique size from being kept around. Resources that
306 // can't be locked for write might also not be truly free-able. 317 // can't be locked for write might also not be truly free-able.
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 for (const auto& resource : busy_resources_) { 443 for (const auto& resource : busy_resources_) {
433 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */); 444 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */);
434 } 445 }
435 for (const auto& entry : in_use_resources_) { 446 for (const auto& entry : in_use_resources_) {
436 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */); 447 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */);
437 } 448 }
438 return true; 449 return true;
439 } 450 }
440 451
441 } // namespace cc 452 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698