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

Side by Side Diff: base/memory/discardable_memory_manager.cc

Issue 195863005: Use DiscardableMemoryManager on Android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix base.gypi Created 6 years, 8 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 | Annotate | Revision Log
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 "base/memory/discardable_memory_manager.h" 5 #include "base/memory/discardable_memory_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/containers/hash_tables.h" 8 #include "base/containers/hash_tables.h"
9 #include "base/containers/mru_cache.h" 9 #include "base/containers/mru_cache.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 AutoLock lock(lock_); 77 AutoLock lock(lock_);
78 AllocationMap::iterator it = allocations_.Peek(allocation); 78 AllocationMap::iterator it = allocations_.Peek(allocation);
79 DCHECK(it != allocations_.end()); 79 DCHECK(it != allocations_.end());
80 const AllocationInfo& info = it->second; 80 const AllocationInfo& info = it->second;
81 81
82 if (info.purgable) { 82 if (info.purgable) {
83 size_t bytes_purgable = info.bytes; 83 size_t bytes_purgable = info.bytes;
84 DCHECK_LE(bytes_purgable, bytes_allocated_); 84 DCHECK_LE(bytes_purgable, bytes_allocated_);
85 bytes_allocated_ -= bytes_purgable; 85 bytes_allocated_ -= bytes_purgable;
86 BytesAllocatedChanged(); 86 BytesAllocatedChanged();
87 } else {
88 // Note that Purge() which is called below requires the Allocation instance
89 // to be unlocked.
90 allocation->ReleaseLock();
reveman 2014/04/26 00:13:37 It's currently up to the client to call Discardabl
87 } 91 }
92
93 // Purge the allocation here while the mutex is acquired to let the underlying
94 // Allocation instance not have to deal with synchronization on its own.
95 allocation->Purge();
reveman 2014/04/26 00:13:37 I don't think we should do this here. I prefer to
96
88 allocations_.Erase(it); 97 allocations_.Erase(it);
89 } 98 }
90 99
91 bool DiscardableMemoryManager::AcquireLock(Allocation* allocation, 100 bool DiscardableMemoryManager::AcquireLock(Allocation* allocation,
92 bool* purged) { 101 bool* purged) {
93 AutoLock lock(lock_); 102 AutoLock lock(lock_);
94 // Note: |allocations_| is an MRU cache, and use of |Get| here updates that 103 // Note: |allocations_| is an MRU cache, and use of |Get| here updates that
95 // cache. 104 // cache.
96 AllocationMap::iterator it = allocations_.Get(allocation); 105 AllocationMap::iterator it = allocations_.Get(allocation);
97 DCHECK(it != allocations_.end()); 106 DCHECK(it != allocations_.end());
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 void DiscardableMemoryManager::EnforcePolicyWithLockAcquired() { 226 void DiscardableMemoryManager::EnforcePolicyWithLockAcquired() {
218 PurgeLRUWithLockAcquiredUntilUsageIsWithin(memory_limit_); 227 PurgeLRUWithLockAcquiredUntilUsageIsWithin(memory_limit_);
219 } 228 }
220 229
221 void DiscardableMemoryManager::BytesAllocatedChanged() const { 230 void DiscardableMemoryManager::BytesAllocatedChanged() const {
222 TRACE_COUNTER_ID1("base", "DiscardableMemoryUsage", this, bytes_allocated_); 231 TRACE_COUNTER_ID1("base", "DiscardableMemoryUsage", this, bytes_allocated_);
223 } 232 }
224 233
225 } // namespace internal 234 } // namespace internal
226 } // namespace base 235 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698