Commit ac08f57b authored by vmpstr's avatar vmpstr Committed by Commit bot

cc: Add cache purging to software image decode controller.

This patch adds code that reacts to memory state change signals to
purge unlocked discardable memory when we're throttled or suspended.

R=ericrk@chromium.org
CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_precise_blink_rel

Review-Url: https://codereview.chromium.org/2364683004
Cr-Commit-Position: refs/heads/master@{#420750}
parent 26ed6abe
...@@ -37,7 +37,11 @@ const size_t kMaxHighQualityImageSizeBytes = 64 * 1024 * 1024; ...@@ -37,7 +37,11 @@ const size_t kMaxHighQualityImageSizeBytes = 64 * 1024 * 1024;
// The number of entries to keep around in the cache. This limit can be breached // The number of entries to keep around in the cache. This limit can be breached
// if more items are locked. That is, locked items ignore this limit. // if more items are locked. That is, locked items ignore this limit.
const size_t kMaxItemsInCache = 1000; // Depending on the memory state of the system, we limit the amount of items
// differently.
const size_t kNormalMaxItemsInCache = 1000;
const size_t kThrottledMaxItemsInCache = 100;
const size_t kSuspendedMaxItemsInCache = 0;
// If the size of the original sized image breaches kMemoryRatioToSubrect but we // If the size of the original sized image breaches kMemoryRatioToSubrect but we
// don't need to scale the image, consider caching only the needed subrect. // don't need to scale the image, consider caching only the needed subrect.
...@@ -173,7 +177,8 @@ SoftwareImageDecodeController::SoftwareImageDecodeController( ...@@ -173,7 +177,8 @@ SoftwareImageDecodeController::SoftwareImageDecodeController(
: decoded_images_(ImageMRUCache::NO_AUTO_EVICT), : decoded_images_(ImageMRUCache::NO_AUTO_EVICT),
at_raster_decoded_images_(ImageMRUCache::NO_AUTO_EVICT), at_raster_decoded_images_(ImageMRUCache::NO_AUTO_EVICT),
locked_images_budget_(locked_memory_limit_bytes), locked_images_budget_(locked_memory_limit_bytes),
format_(format) { format_(format),
max_items_in_cache_(kNormalMaxItemsInCache) {
// In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview).
// Don't register a dump provider in these cases. // Don't register a dump provider in these cases.
if (base::ThreadTaskRunnerHandle::IsSet()) { if (base::ThreadTaskRunnerHandle::IsSet()) {
...@@ -747,8 +752,8 @@ void SoftwareImageDecodeController::UnrefAtRasterImage(const ImageKey& key) { ...@@ -747,8 +752,8 @@ void SoftwareImageDecodeController::UnrefAtRasterImage(const ImageKey& key) {
void SoftwareImageDecodeController::ReduceCacheUsage() { void SoftwareImageDecodeController::ReduceCacheUsage() {
TRACE_EVENT0("cc", "SoftwareImageDecodeController::ReduceCacheUsage"); TRACE_EVENT0("cc", "SoftwareImageDecodeController::ReduceCacheUsage");
base::AutoLock lock(lock_); base::AutoLock lock(lock_);
size_t num_to_remove = (decoded_images_.size() > kMaxItemsInCache) size_t num_to_remove = (decoded_images_.size() > max_items_in_cache_)
? (decoded_images_.size() - kMaxItemsInCache) ? (decoded_images_.size() - max_items_in_cache_)
: 0; : 0;
for (auto it = decoded_images_.rbegin(); for (auto it = decoded_images_.rbegin();
num_to_remove != 0 && it != decoded_images_.rend();) { num_to_remove != 0 && it != decoded_images_.rend();) {
...@@ -1085,22 +1090,24 @@ size_t SoftwareImageDecodeController::MemoryBudget::GetCurrentUsageSafe() ...@@ -1085,22 +1090,24 @@ size_t SoftwareImageDecodeController::MemoryBudget::GetCurrentUsageSafe()
void SoftwareImageDecodeController::OnMemoryStateChange( void SoftwareImageDecodeController::OnMemoryStateChange(
base::MemoryState state) { base::MemoryState state) {
switch (state) { {
case base::MemoryState::NORMAL: base::AutoLock hold(lock_);
// TODO(tasak): go back to normal state. switch (state) {
break; case base::MemoryState::NORMAL:
case base::MemoryState::THROTTLED: max_items_in_cache_ = kNormalMaxItemsInCache;
// TODO(tasak): make the limits of this component's caches smaller to break;
// save memory usage. case base::MemoryState::THROTTLED:
break; max_items_in_cache_ = kThrottledMaxItemsInCache;
case base::MemoryState::SUSPENDED: break;
// TODO(tasak): free this component's caches as much as possible before case base::MemoryState::SUSPENDED:
// suspending renderer. max_items_in_cache_ = kSuspendedMaxItemsInCache;
break; break;
case base::MemoryState::UNKNOWN: case base::MemoryState::UNKNOWN:
// NOT_REACHED. NOTREACHED();
break; return;
}
} }
ReduceCacheUsage();
} }
} // namespace cc } // namespace cc
...@@ -288,6 +288,7 @@ class CC_EXPORT SoftwareImageDecodeController ...@@ -288,6 +288,7 @@ class CC_EXPORT SoftwareImageDecodeController
MemoryBudget locked_images_budget_; MemoryBudget locked_images_budget_;
ResourceFormat format_; ResourceFormat format_;
size_t max_items_in_cache_;
// Used to uniquely identify DecodedImages for memory traces. // Used to uniquely identify DecodedImages for memory traces.
base::AtomicSequenceNumber next_tracing_id_; base::AtomicSequenceNumber next_tracing_id_;
......
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