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; |
} |