Chromium Code Reviews| Index: gpu/command_buffer/client/mapped_memory.cc |
| diff --git a/gpu/command_buffer/client/mapped_memory.cc b/gpu/command_buffer/client/mapped_memory.cc |
| index 82829d48ec1cda6fd7534f596b95acbce03b8522..de07d14447762e993d2bd055f8f1731617499582 100644 |
| --- a/gpu/command_buffer/client/mapped_memory.cc |
| +++ b/gpu/command_buffer/client/mapped_memory.cc |
| @@ -18,9 +18,12 @@ MemoryChunk::MemoryChunk( |
| allocator_(shm.size, helper, shm.ptr) { |
| } |
| -MappedMemoryManager::MappedMemoryManager(CommandBufferHelper* helper) |
| +MappedMemoryManager::MappedMemoryManager(CommandBufferHelper* helper, |
| + size_t memory_limit) |
| : chunk_size_multiple_(1), |
| - helper_(helper) { |
| + helper_(helper), |
| + allocated_memory_(0), |
| + max_free_bytes_(memory_limit) { |
| } |
| MappedMemoryManager::~MappedMemoryManager() { |
| @@ -36,10 +39,12 @@ void* MappedMemoryManager::Alloc( |
| unsigned int size, int32* shm_id, unsigned int* shm_offset) { |
| GPU_DCHECK(shm_id); |
| GPU_DCHECK(shm_offset); |
|
no sievers
2013/08/20 15:59:17
Can you put 'if (size <= allocated_memory_)' aroun
kaanb
2013/08/20 22:15:46
Done.
|
| - // See if any of the chucks can satisfy this request. |
| + size_t total_bytes_in_use = 0; |
| + // See if any of the chunks can satisfy this request. |
| for (size_t ii = 0; ii < chunks_.size(); ++ii) { |
| MemoryChunk* chunk = chunks_[ii]; |
| chunk->FreeUnused(); |
| + total_bytes_in_use += chunk->bytes_in_use(); |
| if (chunk->GetLargestFreeSizeWithoutWaiting() >= size) { |
| void* mem = chunk->Alloc(size); |
| GPU_DCHECK(mem); |
| @@ -49,6 +54,25 @@ void* MappedMemoryManager::Alloc( |
| } |
| } |
| + // If there is a memory limit being enforced and total free |
| + // memory (allocated_memory_ - total_bytes_in_use) is larger than |
| + // the limit try waiting. |
| + if (max_free_bytes_ != kNoLimit && |
| + (allocated_memory_ - total_bytes_in_use) >= max_free_bytes_) { |
|
epenner
2013/08/20 18:02:03
Please add a trace in this if statement.
kaanb
2013/08/20 22:15:46
Done.
|
| + for (size_t ii = 0; ii < chunks_.size(); ++ii) { |
| + MemoryChunk* chunk = chunks_[ii]; |
| + chunk->FreeUnused(); |
|
no sievers
2013/08/20 02:46:54
Should we skip the call to FreeUnused() here since
kaanb
2013/08/20 22:15:46
Done.
|
| + if (chunk->GetLargestFreeSizeWithWaiting() >= size) { |
| + void* mem = chunk->Alloc(size); |
| + GPU_DCHECK(mem); |
| + *shm_id = chunk->shm_id(); |
| + *shm_offset = chunk->GetOffset(mem); |
| + return mem; |
| + } |
| + } |
| + LOG(INFO) << "Exceeding memory limit: " << max_free_bytes_; |
|
no sievers
2013/08/20 02:46:54
Hmm that might be spammy. How about a trace event
kaanb
2013/08/20 22:15:46
I put the trace event in this method.
|
| + } |
| + |
| // Make a new chunk to satisfy the request. |
| CommandBuffer* cmd_buf = helper_->command_buffer(); |
| unsigned int chunk_size = |
| @@ -59,6 +83,7 @@ void* MappedMemoryManager::Alloc( |
| if (id < 0) |
| return NULL; |
| MemoryChunk* mc = new MemoryChunk(id, shm, helper_); |
| + allocated_memory_ += mc->GetSize(); |
| chunks_.push_back(mc); |
| void* mem = mc->Alloc(size); |
| GPU_DCHECK(mem); |
| @@ -97,6 +122,7 @@ void MappedMemoryManager::FreeUnused() { |
| chunk->FreeUnused(); |
| if (!chunk->InUse()) { |
| cmd_buf->DestroyTransferBuffer(chunk->shm_id()); |
| + allocated_memory_ -= chunk->GetSize(); |
| iter = chunks_.erase(iter); |
| } else { |
| ++iter; |
| @@ -105,6 +131,3 @@ void MappedMemoryManager::FreeUnused() { |
| } |
| } // namespace gpu |
| - |
| - |
| - |