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

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

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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 "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/adapters.h" 8 #include "base/containers/adapters.h"
9 #include "base/containers/hash_tables.h" 9 #include "base/containers/hash_tables.h"
10 #include "base/containers/mru_cache.h" 10 #include "base/containers/mru_cache.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 AutoLock lock(lock_); 44 AutoLock lock(lock_);
45 soft_memory_limit_ = bytes; 45 soft_memory_limit_ = bytes;
46 } 46 }
47 47
48 void DiscardableMemoryManager::SetHardMemoryLimitExpirationTime( 48 void DiscardableMemoryManager::SetHardMemoryLimitExpirationTime(
49 TimeDelta hard_memory_limit_expiration_time) { 49 TimeDelta hard_memory_limit_expiration_time) {
50 AutoLock lock(lock_); 50 AutoLock lock(lock_);
51 hard_memory_limit_expiration_time_ = hard_memory_limit_expiration_time; 51 hard_memory_limit_expiration_time_ = hard_memory_limit_expiration_time;
52 } 52 }
53 53
54 void DiscardableMemoryManager::ReleaseFreeMemory() {
55 TRACE_EVENT0("base", "DiscardableMemoryManager::ReleaseFreeMemory");
56
57 AutoLock lock(lock_);
58 size_t bytes_allocated_before_releasing_memory = bytes_allocated_;
59 for (auto& entry : allocations_) {
60 Allocation* allocation = entry.first;
61 AllocationInfo* info = &entry.second;
62
63 if (!info->purgable)
64 continue;
65
66 // Skip if memory is still resident, otherwise purge and adjust
67 // |bytes_allocated_|.
68 if (allocation->IsMemoryResident())
69 continue;
70
71 size_t bytes_purgable = info->bytes;
72 DCHECK_LE(bytes_purgable, bytes_allocated_);
73 bytes_allocated_ -= bytes_purgable;
74 info->purgable = false;
75 allocation->Purge();
76 }
77
78 if (bytes_allocated_ != bytes_allocated_before_releasing_memory)
79 BytesAllocatedChanged(bytes_allocated_);
80 }
81
82 bool DiscardableMemoryManager::ReduceMemoryUsage() { 54 bool DiscardableMemoryManager::ReduceMemoryUsage() {
83 return PurgeIfNotUsedSinceHardLimitCutoffUntilWithinSoftMemoryLimit(); 55 return PurgeIfNotUsedSinceHardLimitCutoffUntilWithinSoftMemoryLimit();
84 } 56 }
85 57
86 void DiscardableMemoryManager::ReduceMemoryUsageUntilWithinLimit(size_t bytes) { 58 void DiscardableMemoryManager::ReduceMemoryUsageUntilWithinLimit(size_t bytes) {
87 AutoLock lock(lock_); 59 AutoLock lock(lock_);
88 PurgeIfNotUsedSinceTimestampUntilUsageIsWithinLimitWithLockAcquired(Now(), 60 PurgeIfNotUsedSinceTimestampUntilUsageIsWithinLimitWithLockAcquired(Now(),
89 bytes); 61 bytes);
90 } 62 }
91 63
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 base::debug::SetCrashKeyValue(kDiscardableMemoryUsageKey, 209 base::debug::SetCrashKeyValue(kDiscardableMemoryUsageKey,
238 Uint64ToString(new_bytes_allocated)); 210 Uint64ToString(new_bytes_allocated));
239 } 211 }
240 212
241 TimeTicks DiscardableMemoryManager::Now() const { 213 TimeTicks DiscardableMemoryManager::Now() const {
242 return TimeTicks::Now(); 214 return TimeTicks::Now();
243 } 215 }
244 216
245 } // namespace internal 217 } // namespace internal
246 } // namespace base 218 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/discardable_memory_manager.h ('k') | base/memory/discardable_memory_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698