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

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: fix problem with segment having been released before we try to purge 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..539136179e3affa9d0b61f74a7945311cd9476dc 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());
@@ -429,17 +427,14 @@ void HostDiscardableSharedMemoryManager::ReduceMemoryUsageUntilWithinLimit(
scoped_refptr<MemorySegment> segment = segments_.back();
segments_.pop_back();
+ // Simply drop the reference and continue if memory has already been
+ // unmapped. This happens when a memory segment has been deleted by
+ // the client.
+ if (!segment->memory()->mapped_size())
+ continue;
+
// 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') | content/common/host_discardable_shared_memory_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698