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

Side by Side Diff: content/common/discardable_shared_memory_heap.h

Issue 1100073004: Adding discardable memory dump provider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing comments. Created 5 years, 8 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 unified diff | Download patch
OLDNEW
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 {
20 21
21 // Implements a heap of discardable shared memory. An array of free lists 22 // Implements a heap of discardable shared memory. An array of free lists
22 // is used to keep track of free blocks. 23 // is used to keep track of free blocks.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 77
77 // Release shared memory segments that have been purged. 78 // Release shared memory segments that have been purged.
78 void ReleasePurgedMemory(); 79 void ReleasePurgedMemory();
79 80
80 // Returns total bytes of memory in heap. 81 // Returns total bytes of memory in heap.
81 size_t GetSize() const; 82 size_t GetSize() const;
82 83
83 // Returns bytes of memory currently in the free lists. 84 // Returns bytes of memory currently in the free lists.
84 size_t GetSizeOfFreeLists() const; 85 size_t GetSizeOfFreeLists() const;
85 86
87 // Dumps memory statistics for chrome://tracing.
88 bool DumpMemoryStatisticsInto(base::trace_event::ProcessMemoryDump* pmd);
89
86 private: 90 private:
87 class ScopedMemorySegment { 91 class ScopedMemorySegment {
88 public: 92 public:
89 ScopedMemorySegment(DiscardableSharedMemoryHeap* heap, 93 ScopedMemorySegment(DiscardableSharedMemoryHeap* heap,
90 scoped_ptr<base::DiscardableSharedMemory> shared_memory, 94 scoped_ptr<base::DiscardableSharedMemory> shared_memory,
91 size_t size, 95 size_t size,
92 const base::Closure& deleted_callback); 96 const base::Closure& deleted_callback);
93 ~ScopedMemorySegment(); 97 ~ScopedMemorySegment();
94 98
95 bool IsUsed() const; 99 bool IsUsed() const;
96 bool IsResident() const; 100 bool IsResident() const;
97 101
98 private: 102 private:
103 friend class DiscardableSharedMemoryHeap;
reveman 2015/04/24 14:19:36 hm, sorry I missed this in my previous review. Wha
ssid 2015/04/27 11:19:21 Yes, I tried to explain this indirection in last p
104
99 DiscardableSharedMemoryHeap* const heap_; 105 DiscardableSharedMemoryHeap* const heap_;
100 scoped_ptr<base::DiscardableSharedMemory> shared_memory_; 106 scoped_ptr<base::DiscardableSharedMemory> shared_memory_;
101 const size_t size_; 107 const size_t size_;
reveman 2015/04/24 14:19:36 I think we should add "const DiscardableSharedMemo
ssid 2015/04/27 11:19:21 Done.
102 const base::Closure deleted_callback_; 108 const base::Closure deleted_callback_;
103 109
104 DISALLOW_COPY_AND_ASSIGN(ScopedMemorySegment); 110 DISALLOW_COPY_AND_ASSIGN(ScopedMemorySegment);
105 }; 111 };
106 112
107 void InsertIntoFreeList(scoped_ptr<Span> span); 113 void InsertIntoFreeList(scoped_ptr<Span> span);
108 scoped_ptr<Span> RemoveFromFreeList(Span* span); 114 scoped_ptr<Span> RemoveFromFreeList(Span* span);
109 scoped_ptr<Span> Carve(Span* span, size_t blocks); 115 scoped_ptr<Span> Carve(Span* span, size_t blocks);
110 void RegisterSpan(Span* span); 116 void RegisterSpan(Span* span);
111 void UnregisterSpan(Span* span); 117 void UnregisterSpan(Span* span);
112 bool IsMemoryUsed(const base::DiscardableSharedMemory* shared_memory, 118 bool IsMemoryUsed(const base::DiscardableSharedMemory* shared_memory,
113 size_t size); 119 size_t size);
114 bool IsMemoryResident(const base::DiscardableSharedMemory* shared_memory); 120 bool IsMemoryResident(const base::DiscardableSharedMemory* shared_memory);
115 void ReleaseMemory(const base::DiscardableSharedMemory* shared_memory, 121 void ReleaseMemory(const base::DiscardableSharedMemory* shared_memory,
116 size_t size); 122 size_t size);
reveman 2015/04/24 14:19:36 to do what I suggested above we'd need something l
ssid 2015/04/27 11:19:21 Also with ProcessMemoryDump* .
117 123
118 size_t block_size_; 124 size_t block_size_;
119 size_t num_blocks_; 125 size_t num_blocks_;
120 size_t num_free_blocks_; 126 size_t num_free_blocks_;
121 127
122 // Vector of memory segments. 128 // Vector of memory segments.
123 ScopedVector<ScopedMemorySegment> memory_segments_; 129 ScopedVector<ScopedMemorySegment> memory_segments_;
124 130
125 // Mapping from first/last block of span to Span instance. 131 // Mapping from first/last block of span to Span instance.
126 typedef base::hash_map<size_t, Span*> SpanMap; 132 typedef base::hash_map<size_t, Span*> SpanMap;
127 SpanMap spans_; 133 SpanMap spans_;
128 134
129 // Array of linked-lists with free discardable memory regions. For i < 256, 135 // 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 136 // 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 137 // 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. 138 // free list of runs that have length >= 256 blocks.
133 base::LinkedList<Span> free_spans_[256]; 139 base::LinkedList<Span> free_spans_[256];
134 140
135 DISALLOW_COPY_AND_ASSIGN(DiscardableSharedMemoryHeap); 141 DISALLOW_COPY_AND_ASSIGN(DiscardableSharedMemoryHeap);
136 }; 142 };
137 143
138 } // namespace content 144 } // namespace content
139 145
140 #endif // CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_ 146 #endif // CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698