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

Unified Diff: base/memory/discardable_memory_manager.cc

Issue 681713002: Update from chromium https://crrev.com/301315 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/discardable_memory_manager.cc
diff --git a/base/memory/discardable_memory_manager.cc b/base/memory/discardable_memory_manager.cc
index 5f5e604cf47a935f40b2f57fbf9f50f239e76225..faf583b485fded9a42c6ccfc3be43a6b110121c8 100644
--- a/base/memory/discardable_memory_manager.cc
+++ b/base/memory/discardable_memory_manager.cc
@@ -51,6 +51,34 @@ void DiscardableMemoryManager::SetHardMemoryLimitExpirationTime(
hard_memory_limit_expiration_time_ = hard_memory_limit_expiration_time;
}
+void DiscardableMemoryManager::ReleaseFreeMemory() {
+ TRACE_EVENT0("base", "DiscardableMemoryManager::ReleaseFreeMemory");
+
+ AutoLock lock(lock_);
+ size_t bytes_allocated_before_releasing_memory = bytes_allocated_;
+ for (auto& entry : allocations_) {
+ Allocation* allocation = entry.first;
+ AllocationInfo* info = &entry.second;
+
+ if (!info->purgable)
+ continue;
+
+ // Skip if memory is still resident, otherwise purge and adjust
+ // |bytes_allocated_|.
+ if (allocation->IsMemoryResident())
+ continue;
+
+ size_t bytes_purgable = info->bytes;
+ DCHECK_LE(bytes_purgable, bytes_allocated_);
+ bytes_allocated_ -= bytes_purgable;
+ info->purgable = false;
+ allocation->Purge();
+ }
+
+ if (bytes_allocated_ != bytes_allocated_before_releasing_memory)
+ BytesAllocatedChanged(bytes_allocated_);
+}
+
bool DiscardableMemoryManager::ReduceMemoryUsage() {
return PurgeIfNotUsedSinceHardLimitCutoffUntilWithinSoftMemoryLimit();
}
« 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