OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_ | 5 #ifndef CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_ |
6 #define CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_ | 6 #define CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
10 #include "base/containers/linked_list.h" | 10 #include "base/containers/linked_list.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
13 #include "base/trace_event/process_memory_dump.h" | |
13 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
14 | 15 |
15 namespace base { | 16 namespace base { |
16 class DiscardableSharedMemory; | 17 class DiscardableSharedMemory; |
17 } | 18 } |
18 | 19 |
19 namespace content { | 20 namespace content { |
21 typedef int32_t DiscardableSharedMemoryId; | |
20 | 22 |
21 // Implements a heap of discardable shared memory. An array of free lists | 23 // Implements a heap of discardable shared memory. An array of free lists |
22 // is used to keep track of free blocks. | 24 // is used to keep track of free blocks. |
23 class CONTENT_EXPORT DiscardableSharedMemoryHeap { | 25 class CONTENT_EXPORT DiscardableSharedMemoryHeap { |
24 public: | 26 public: |
25 class CONTENT_EXPORT Span : public base::LinkNode<Span> { | 27 class CONTENT_EXPORT Span : public base::LinkNode<Span> { |
26 public: | 28 public: |
27 ~Span(); | 29 ~Span(); |
28 | 30 |
29 base::DiscardableSharedMemory* shared_memory() { return shared_memory_; } | 31 base::DiscardableSharedMemory* shared_memory() { return shared_memory_; } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 | 78 |
77 // Release shared memory segments that have been purged. | 79 // Release shared memory segments that have been purged. |
78 void ReleasePurgedMemory(); | 80 void ReleasePurgedMemory(); |
79 | 81 |
80 // Returns total bytes of memory in heap. | 82 // Returns total bytes of memory in heap. |
81 size_t GetSize() const; | 83 size_t GetSize() const; |
82 | 84 |
83 // Returns bytes of memory currently in the free lists. | 85 // Returns bytes of memory currently in the free lists. |
84 size_t GetSizeOfFreeLists() const; | 86 size_t GetSizeOfFreeLists() const; |
85 | 87 |
88 // Dumps memory statistics for chrome://tracing. | |
89 bool DumpMemoryStatisticsInto(base::trace_event::ProcessMemoryDump* pmd); | |
90 | |
86 private: | 91 private: |
87 class ScopedMemorySegment { | 92 class ScopedMemorySegment { |
88 public: | 93 public: |
89 ScopedMemorySegment(DiscardableSharedMemoryHeap* heap, | 94 ScopedMemorySegment(DiscardableSharedMemoryHeap* heap, |
90 scoped_ptr<base::DiscardableSharedMemory> shared_memory, | 95 scoped_ptr<base::DiscardableSharedMemory> shared_memory, |
91 size_t size, | 96 size_t size, |
97 DiscardableSharedMemoryId id, | |
92 const base::Closure& deleted_callback); | 98 const base::Closure& deleted_callback); |
93 ~ScopedMemorySegment(); | 99 ~ScopedMemorySegment(); |
94 | 100 |
95 bool IsUsed() const; | 101 bool IsUsed() const; |
96 bool IsResident() const; | 102 bool IsResident() const; |
103 void DumpMemoryStatisticsInto( | |
reveman
2015/04/27 13:28:11
nit: maybe use the same name as MemoryDumpProvider
ssid
2015/04/27 14:27:01
Done.
| |
104 base::trace_event::ProcessMemoryDump* pmd) const; | |
97 | 105 |
98 private: | 106 private: |
99 DiscardableSharedMemoryHeap* const heap_; | 107 DiscardableSharedMemoryHeap* const heap_; |
100 scoped_ptr<base::DiscardableSharedMemory> shared_memory_; | 108 scoped_ptr<base::DiscardableSharedMemory> shared_memory_; |
101 const size_t size_; | 109 const size_t size_; |
110 const DiscardableSharedMemoryId id_; | |
102 const base::Closure deleted_callback_; | 111 const base::Closure deleted_callback_; |
103 | 112 |
104 DISALLOW_COPY_AND_ASSIGN(ScopedMemorySegment); | 113 DISALLOW_COPY_AND_ASSIGN(ScopedMemorySegment); |
105 }; | 114 }; |
106 | 115 |
107 void InsertIntoFreeList(scoped_ptr<Span> span); | 116 void InsertIntoFreeList(scoped_ptr<Span> span); |
108 scoped_ptr<Span> RemoveFromFreeList(Span* span); | 117 scoped_ptr<Span> RemoveFromFreeList(Span* span); |
109 scoped_ptr<Span> Carve(Span* span, size_t blocks); | 118 scoped_ptr<Span> Carve(Span* span, size_t blocks); |
110 void RegisterSpan(Span* span); | 119 void RegisterSpan(Span* span); |
111 void UnregisterSpan(Span* span); | 120 void UnregisterSpan(Span* span); |
112 bool IsMemoryUsed(const base::DiscardableSharedMemory* shared_memory, | 121 bool IsMemoryUsed(const base::DiscardableSharedMemory* shared_memory, |
113 size_t size); | 122 size_t size); |
114 bool IsMemoryResident(const base::DiscardableSharedMemory* shared_memory); | 123 bool IsMemoryResident(const base::DiscardableSharedMemory* shared_memory); |
115 void ReleaseMemory(const base::DiscardableSharedMemory* shared_memory, | 124 void ReleaseMemory(const base::DiscardableSharedMemory* shared_memory, |
116 size_t size); | 125 size_t size); |
126 void DumpSegmentStatistics(const base::DiscardableSharedMemory* shared_memory, | |
reveman
2015/04/27 13:28:11
nit: same here, maybe keep this consistent: DumpIn
ssid
2015/04/27 14:27:01
Done.
| |
127 size_t segment_size, | |
128 DiscardableSharedMemoryId id, | |
129 base::trace_event::ProcessMemoryDump* pmd); | |
117 | 130 |
118 size_t block_size_; | 131 size_t block_size_; |
119 size_t num_blocks_; | 132 size_t num_blocks_; |
120 size_t num_free_blocks_; | 133 size_t num_free_blocks_; |
121 | 134 |
122 // Vector of memory segments. | 135 // Vector of memory segments. |
123 ScopedVector<ScopedMemorySegment> memory_segments_; | 136 ScopedVector<ScopedMemorySegment> memory_segments_; |
124 | 137 |
125 // Mapping from first/last block of span to Span instance. | 138 // Mapping from first/last block of span to Span instance. |
126 typedef base::hash_map<size_t, Span*> SpanMap; | 139 typedef base::hash_map<size_t, Span*> SpanMap; |
127 SpanMap spans_; | 140 SpanMap spans_; |
128 | 141 |
129 // Array of linked-lists with free discardable memory regions. For i < 256, | 142 // Array of linked-lists with free discardable memory regions. For i < 256, |
130 // where the 1st entry is located at index 0 of the array, the kth entry | 143 // where the 1st entry is located at index 0 of the array, the kth entry |
131 // is a free list of runs that consist of k blocks. The 256th entry is a | 144 // is a free list of runs that consist of k blocks. The 256th entry is a |
132 // free list of runs that have length >= 256 blocks. | 145 // free list of runs that have length >= 256 blocks. |
133 base::LinkedList<Span> free_spans_[256]; | 146 base::LinkedList<Span> free_spans_[256]; |
134 | 147 |
135 DISALLOW_COPY_AND_ASSIGN(DiscardableSharedMemoryHeap); | 148 DISALLOW_COPY_AND_ASSIGN(DiscardableSharedMemoryHeap); |
136 }; | 149 }; |
137 | 150 |
138 } // namespace content | 151 } // namespace content |
139 | 152 |
140 #endif // CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_ | 153 #endif // CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_ |
OLD | NEW |