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

Unified Diff: content/common/host_discardable_shared_memory_manager.h

Issue 1009203004: content: Add DeletedDiscardableSharedMemory IPC. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 9 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.h
diff --git a/content/common/host_discardable_shared_memory_manager.h b/content/common/host_discardable_shared_memory_manager.h
index 6998f0d0c0351a120e97e25d1b68ef4e7e51adf2..36de71dcf24802ff087e8fd73d6f9137056b360e 100644
--- a/content/common/host_discardable_shared_memory_manager.h
+++ b/content/common/host_discardable_shared_memory_manager.h
@@ -7,10 +7,11 @@
#include <vector>
+#include "base/containers/hash_tables.h"
#include "base/memory/discardable_memory_shmem_allocator.h"
#include "base/memory/discardable_shared_memory.h"
-#include "base/memory/linked_ptr.h"
#include "base/memory/memory_pressure_listener.h"
+#include "base/memory/ref_counted.h"
#include "base/memory/shared_memory.h"
#include "base/memory/weak_ptr.h"
#include "base/process/process_handle.h"
@@ -18,6 +19,7 @@
#include "content/common/content_export.h"
namespace content {
+typedef int32_t DiscardableSharedMemoryId;
// Implementation of DiscardableMemoryShmemAllocator that allocates and
// manages discardable memory segments for the browser process and child
@@ -41,9 +43,15 @@ class CONTENT_EXPORT HostDiscardableSharedMemoryManager
void AllocateLockedDiscardableSharedMemoryForChild(
base::ProcessHandle process_handle,
size_t size,
+ DiscardableSharedMemoryId id,
base::SharedMemoryHandle* shared_memory_handle);
// Call this to notify the manager that child process associated with
+ // |process_handle| has deleted discardable memory segment with |id|.
+ void ChildDeletedDiscardableSharedMemory(DiscardableSharedMemoryId id,
+ base::ProcessHandle process_handle);
+
+ // Call this to notify the manager that child process associated with
// |process_handle| has been removed. The manager will use this to release
// memory segments allocated for child process to the OS.
void ProcessRemoved(base::ProcessHandle process_handle);
@@ -55,30 +63,44 @@ class CONTENT_EXPORT HostDiscardableSharedMemoryManager
// Reduce memory usage if above current memory limit.
void EnforceMemoryPolicy();
+ // Returns bytes of allocated discardable memory.
+ size_t GetBytesAllocated();
+
private:
- struct MemorySegment {
- MemorySegment(linked_ptr<base::DiscardableSharedMemory> memory,
- base::ProcessHandle process_handle);
+ class MemorySegment : public base::RefCountedThreadSafe<MemorySegment> {
+ public:
+ MemorySegment(scoped_ptr<base::DiscardableSharedMemory> memory);
+
+ base::DiscardableSharedMemory* memory() const { return memory_.get(); }
+
+ private:
+ friend class base::RefCountedThreadSafe<MemorySegment>;
+
~MemorySegment();
- linked_ptr<base::DiscardableSharedMemory> memory;
- base::ProcessHandle process_handle;
+ scoped_ptr<base::DiscardableSharedMemory> memory_;
+
+ DISALLOW_COPY_AND_ASSIGN(MemorySegment);
};
- static bool CompareMemoryUsageTime(const MemorySegment& a,
- const MemorySegment& b) {
+ static bool CompareMemoryUsageTime(const scoped_refptr<MemorySegment>& a,
+ const scoped_refptr<MemorySegment>& b) {
// In this system, LRU memory segment is evicted first.
- return a.memory->last_known_usage() > b.memory->last_known_usage();
+ return a->memory()->last_known_usage() > b->memory()->last_known_usage();
}
void AllocateLockedDiscardableSharedMemory(
base::ProcessHandle process_handle,
size_t size,
+ DiscardableSharedMemoryId id,
base::SharedMemoryHandle* shared_memory_handle);
+ void DeletedDiscardableSharedMemory(DiscardableSharedMemoryId id,
+ base::ProcessHandle process_handle);
void OnMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level);
void ReduceMemoryUsageUntilWithinMemoryLimit();
void ReduceMemoryUsageUntilWithinLimit(size_t limit);
+ void ReleaseMemory(base::DiscardableSharedMemory* memory);
void BytesAllocatedChanged(size_t new_bytes_allocated) const;
// Virtual for tests.
@@ -86,9 +108,13 @@ class CONTENT_EXPORT HostDiscardableSharedMemoryManager
virtual void ScheduleEnforceMemoryPolicy();
base::Lock lock_;
+ typedef base::hash_map<DiscardableSharedMemoryId,
+ scoped_refptr<MemorySegment>> MemorySegmentMap;
+ typedef base::hash_map<base::ProcessHandle, MemorySegmentMap> ProcessMap;
+ ProcessMap processes_;
// Note: The elements in |segments_| are arranged in such a way that they form
// a heap. The LRU memory segment always first.
- typedef std::vector<MemorySegment> MemorySegmentVector;
+ typedef std::vector<scoped_refptr<MemorySegment>> MemorySegmentVector;
MemorySegmentVector segments_;
size_t memory_limit_;
size_t bytes_allocated_;
« no previous file with comments | « content/common/discardable_shared_memory_heap_unittest.cc ('k') | content/common/host_discardable_shared_memory_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698