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

Side by Side Diff: gpu/command_buffer/client/mapped_memory.h

Issue 23130004: Enforce a memory limit on MappedMemoryManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix another namespace error Created 7 years, 4 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 GPU_COMMAND_BUFFER_CLIENT_MAPPED_MEMORY_H_ 5 #ifndef GPU_COMMAND_BUFFER_CLIENT_MAPPED_MEMORY_H_
6 #define GPU_COMMAND_BUFFER_CLIENT_MAPPED_MEMORY_H_ 6 #define GPU_COMMAND_BUFFER_CLIENT_MAPPED_MEMORY_H_
7 7
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "gpu/command_buffer/client/fenced_allocator.h" 9 #include "gpu/command_buffer/client/fenced_allocator.h"
10 #include "gpu/command_buffer/common/buffer.h" 10 #include "gpu/command_buffer/common/buffer.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 // Frees a block of memory, pending the passage of a token. That memory won't 72 // Frees a block of memory, pending the passage of a token. That memory won't
73 // be re-allocated until the token has passed through the command stream. 73 // be re-allocated until the token has passed through the command stream.
74 // 74 //
75 // Parameters: 75 // Parameters:
76 // pointer: the pointer to the memory block to free. 76 // pointer: the pointer to the memory block to free.
77 // token: the token value to wait for before re-using the memory. 77 // token: the token value to wait for before re-using the memory.
78 void FreePendingToken(void* pointer, unsigned int token) { 78 void FreePendingToken(void* pointer, unsigned int token) {
79 allocator_.FreePendingToken(pointer, token); 79 allocator_.FreePendingToken(pointer, token);
80 } 80 }
81 81
82 // Frees any blocks who's tokens have passed. 82 // Frees any blocks whose tokens have passed.
83 void FreeUnused() { 83 void FreeUnused() {
84 allocator_.FreeUnused(); 84 allocator_.FreeUnused();
85 } 85 }
86 86
87 // Returns true if pointer is in the range of this block. 87 // Returns true if pointer is in the range of this block.
88 bool IsInChunk(void* pointer) const { 88 bool IsInChunk(void* pointer) const {
89 return pointer >= shm_.ptr && 89 return pointer >= shm_.ptr &&
90 pointer < reinterpret_cast<const int8*>(shm_.ptr) + shm_.size; 90 pointer < reinterpret_cast<const int8*>(shm_.ptr) + shm_.size;
91 } 91 }
92 92
93 // Returns true of any memory in this chuck is in use. 93 // Returns true of any memory in this chunk is in use.
94 bool InUse() { 94 bool InUse() {
95 return allocator_.InUse(); 95 return allocator_.InUse();
96 } 96 }
97 97
98 size_t bytes_in_use() const {
99 return allocator_.bytes_in_use();
100 }
101
98 private: 102 private:
99 int32 shm_id_; 103 int32 shm_id_;
100 gpu::Buffer shm_; 104 gpu::Buffer shm_;
101 FencedAllocatorWrapper allocator_; 105 FencedAllocatorWrapper allocator_;
102 106
103 DISALLOW_COPY_AND_ASSIGN(MemoryChunk); 107 DISALLOW_COPY_AND_ASSIGN(MemoryChunk);
104 }; 108 };
105 109
106 // Manages MemoryChucks. 110 // Manages MemoryChunks.
107 class GPU_EXPORT MappedMemoryManager { 111 class GPU_EXPORT MappedMemoryManager {
108 public: 112 public:
109 explicit MappedMemoryManager(CommandBufferHelper* helper); 113 enum MemoryLimit {
114 kNoLimit = 0,
115 };
116
117 // |unused_memory_reclaim_limit|: When exceeded this causes pending memory
118 // to be reclaimed before allocating more memory.
119 MappedMemoryManager(CommandBufferHelper* helper,
120 size_t unused_memory_reclaim_limit);
110 121
111 ~MappedMemoryManager(); 122 ~MappedMemoryManager();
112 123
113 unsigned int chunk_size_multiple() const { 124 unsigned int chunk_size_multiple() const {
114 return chunk_size_multiple_; 125 return chunk_size_multiple_;
115 } 126 }
116 127
117 void set_chunk_size_multiple(unsigned int multiple) { 128 void set_chunk_size_multiple(unsigned int multiple) {
118 chunk_size_multiple_ = multiple; 129 chunk_size_multiple_ = multiple;
119 } 130 }
(...skipping 19 matching lines...) Expand all
139 // 150 //
140 // Parameters: 151 // Parameters:
141 // pointer: the pointer to the memory block to free. 152 // pointer: the pointer to the memory block to free.
142 // token: the token value to wait for before re-using the memory. 153 // token: the token value to wait for before re-using the memory.
143 void FreePendingToken(void* pointer, int32 token); 154 void FreePendingToken(void* pointer, int32 token);
144 155
145 // Free Any Shared memory that is not in use. 156 // Free Any Shared memory that is not in use.
146 void FreeUnused(); 157 void FreeUnused();
147 158
148 // Used for testing 159 // Used for testing
149 size_t num_chunks() { 160 size_t num_chunks() const {
150 return chunks_.size(); 161 return chunks_.size();
151 } 162 }
152 163
164 // Used for testing
165 size_t allocated_memory() const {
166 return allocated_memory_;
167 }
168
153 private: 169 private:
154 typedef ScopedVector<MemoryChunk> MemoryChunkVector; 170 typedef ScopedVector<MemoryChunk> MemoryChunkVector;
155 171
156 // size a chunk is rounded up to. 172 // size a chunk is rounded up to.
157 unsigned int chunk_size_multiple_; 173 unsigned int chunk_size_multiple_;
158 CommandBufferHelper* helper_; 174 CommandBufferHelper* helper_;
159 MemoryChunkVector chunks_; 175 MemoryChunkVector chunks_;
176 size_t allocated_memory_;
177 size_t max_free_bytes_;
160 178
161 DISALLOW_COPY_AND_ASSIGN(MappedMemoryManager); 179 DISALLOW_COPY_AND_ASSIGN(MappedMemoryManager);
162 }; 180 };
163 181
164 } // namespace gpu 182 } // namespace gpu
165 183
166 #endif // GPU_COMMAND_BUFFER_CLIENT_MAPPED_MEMORY_H_ 184 #endif // GPU_COMMAND_BUFFER_CLIENT_MAPPED_MEMORY_H_
167 185
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/gles2_implementation_unittest.cc ('k') | gpu/command_buffer/client/mapped_memory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698