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

Unified Diff: content/common/host_discardable_shared_memory_manager.cc

Issue 1409743002: Re-land: base: Use MADV_REMOVE instead of ftruncate to purge discardable memory segments. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update comments Created 5 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
Index: content/common/host_discardable_shared_memory_manager.cc
diff --git a/content/common/host_discardable_shared_memory_manager.cc b/content/common/host_discardable_shared_memory_manager.cc
index 90eee02594c38a9629b84a443c3ed0076ba2c9e2..e371c8c8795ad22aa2ce93754de6c98e04e2ebe5 100644
--- a/content/common/host_discardable_shared_memory_manager.cc
+++ b/content/common/host_discardable_shared_memory_manager.cc
@@ -325,6 +325,9 @@ void HostDiscardableSharedMemoryManager::AllocateLockedDiscardableSharedMemory(
return;
}
+ // Close file descriptor to avoid running out.
+ memory->Close();
+
base::CheckedNumeric<size_t> checked_bytes_allocated = bytes_allocated_;
checked_bytes_allocated += memory->mapped_size();
if (!checked_bytes_allocated.IsValid()) {
@@ -335,11 +338,6 @@ void HostDiscardableSharedMemoryManager::AllocateLockedDiscardableSharedMemory(
bytes_allocated_ = checked_bytes_allocated.ValueOrDie();
BytesAllocatedChanged(bytes_allocated_);
-#if !defined(DISCARDABLE_SHARED_MEMORY_SHRINKING)
- // Close file descriptor to avoid running out.
- memory->Close();
-#endif
-
scoped_refptr<MemorySegment> segment(new MemorySegment(memory.Pass()));
process_segments[id] = segment.get();
segments_.push_back(segment.get());
@@ -431,15 +429,6 @@ void HostDiscardableSharedMemoryManager::ReduceMemoryUsageUntilWithinLimit(
// Attempt to purge LRU segment. When successful, released the memory.
if (segment->memory()->Purge(current_time)) {
-#if defined(DISCARDABLE_SHARED_MEMORY_SHRINKING)
- size_t size = segment->memory()->mapped_size();
- DCHECK_GE(bytes_allocated_, size);
- bytes_allocated_ -= size;
- // Shrink memory segment. This will immediately release the memory to
- // the OS.
- segment->memory()->Shrink();
- DCHECK_EQ(segment->memory()->mapped_size(), 0u);
-#endif
ReleaseMemory(segment->memory());
continue;
}
« base/memory/discardable_shared_memory.cc ('K') | « base/memory/discardable_shared_memory_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698