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

Side by Side Diff: gpu/command_buffer/client/mapped_memory_unittest.cc

Issue 23130004: Enforce a memory limit on MappedMemoryManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More code review feedback incorporated 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 #include "gpu/command_buffer/client/mapped_memory.h" 5 #include "gpu/command_buffer/client/mapped_memory.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "gpu/command_buffer/client/cmd_buffer_helper.h" 10 #include "gpu/command_buffer/client/cmd_buffer_helper.h"
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 ASSERT_TRUE(mem2); 299 ASSERT_TRUE(mem2);
300 ASSERT_TRUE(mem3); 300 ASSERT_TRUE(mem3);
301 EXPECT_NE(-1, id1); 301 EXPECT_NE(-1, id1);
302 EXPECT_EQ(id1, id2); 302 EXPECT_EQ(id1, id2);
303 EXPECT_NE(id2, id3); 303 EXPECT_NE(id2, id3);
304 EXPECT_EQ(0u, offset1); 304 EXPECT_EQ(0u, offset1);
305 EXPECT_EQ(kSize, offset2); 305 EXPECT_EQ(kSize, offset2);
306 EXPECT_EQ(0u, offset3); 306 EXPECT_EQ(0u, offset3);
307 } 307 }
308 308
309 TEST_F(MappedMemoryManagerTest, MemoryLimit) {
310 const unsigned int kSize = 1024;
311 // Reset the manager with a memory limit.
312 manager_.reset(new MappedMemoryManager(helper_.get(), 2 * kSize));
313 const unsigned int kChunkSize = 2 * 1024;
314 manager_->set_chunk_size_multiple(2 * kSize);
315
316 // Allocate half a chunk worth of memory.
317 int32 id1 = -1;
318 unsigned int offset1 = 0xFFFFFFFFU;
319 void* mem1 = manager_->Alloc(kSize, &id1, &offset1);
320 ASSERT_TRUE(mem1);
321 EXPECT_NE(-1, id1);
322 EXPECT_EQ(0u, offset1);
323
324 // Allocate half a chunk worth of memory again.
325 // The same chunk will be used.
326 int32 id2 = -1;
327 unsigned int offset2 = 0xFFFFFFFFU;
328 void* mem2 = manager_->Alloc(kSize, &id2, &offset2);
329 ASSERT_TRUE(mem2);
330 EXPECT_NE(-1, id2);
331 EXPECT_EQ(kSize, offset2);
332
333 // Allocate half a chunk worth of memory.
334 int32 id3 = -1;
335 unsigned int offset3 = 0xFFFFFFFFU;
336 void* mem3 = manager_->Alloc(kSize, &id3, &offset3);
337 ASSERT_TRUE(mem3);
338 EXPECT_NE(-1, id3);
339 EXPECT_EQ(0u, offset3);
340
341 // Expect two chunks to be allocated, even though
342 // the memory limit was set to be one chunk.
343 // This proves the memory limit is a soft limit, rather
344 // than a hard one.
345 EXPECT_EQ(2 * kChunkSize, manager_->allocated_memory());
346 }
347
348 TEST_F(MappedMemoryManagerTest, MemoryLimitWithReuse) {
349 const unsigned int kSize = 1024;
350 // Reset the manager with a memory limit.
351 manager_.reset(new MappedMemoryManager(helper_.get(), 2 * kSize));
352 const unsigned int kChunkSize = 2 * 1024;
353 manager_->set_chunk_size_multiple(kChunkSize);
354
355 // Allocate half a chunk worth of memory.
356 int32 id1 = -1;
357 unsigned int offset1 = 0xFFFFFFFFU;
358 void* mem1 = manager_->Alloc(kSize, &id1, &offset1);
359 ASSERT_TRUE(mem1);
360 EXPECT_NE(-1, id1);
361 EXPECT_EQ(0u, offset1);
362
363 // Allocate half a chunk worth of memory again.
364 // The same chunk will be used.
365 int32 id2 = -1;
366 unsigned int offset2 = 0xFFFFFFFFU;
367 void* mem2 = manager_->Alloc(kSize, &id2, &offset2);
368 ASSERT_TRUE(mem2);
369 EXPECT_NE(-1, id2);
370 EXPECT_EQ(kSize, offset2);
371
372 // Free one successful allocation, pending fence.
373 int32 token = helper_.get()->InsertToken();
374 manager_->FreePendingToken(mem2, token);
375
376 // The way we hooked up the helper and engine, it won't process commands
377 // until it has to wait for something. Which means the token shouldn't have
378 // passed yet at this point.
379 EXPECT_GT(token, GetToken());
380
381 // Since we didn't call helper_.finish() the token did not pass.
382 // We won't be able to claim the free memory without waiting and
383 // as we've already met the memory limit we'll have to wait
384 // on the token.
385 int32 id3 = -1;
386 unsigned int offset3 = 0xFFFFFFFFU;
387 void* mem3 = manager_->Alloc(kSize, &id3, &offset3);
388 ASSERT_TRUE(mem3);
389 EXPECT_NE(-1, id3);
390 // It will reuse the space from the second allocation just freed.
391 EXPECT_EQ(kSize, offset3);
392
393 // Expect one chunk to be allocated
394 EXPECT_EQ(1 * kChunkSize, manager_->allocated_memory());
395 }
396
309 } // namespace gpu 397 } // namespace gpu
OLDNEW
« gpu/command_buffer/client/mapped_memory.cc ('K') | « gpu/command_buffer/client/mapped_memory.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698