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

Unified Diff: content/common/host_discardable_shared_memory_manager.cc

Issue 1413163006: Revert of 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: 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
« no previous file with comments | « base/memory/discardable_shared_memory_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 e371c8c8795ad22aa2ce93754de6c98e04e2ebe5..90eee02594c38a9629b84a443c3ed0076ba2c9e2 100644
--- a/content/common/host_discardable_shared_memory_manager.cc
+++ b/content/common/host_discardable_shared_memory_manager.cc
@@ -325,9 +325,6 @@
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()) {
@@ -337,6 +334,11 @@
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();
@@ -429,6 +431,15 @@
// 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;
}
« no previous file with comments | « 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