Fixed arena_test failure due to malloc_usable_size()

Summary:
ArenaTest.MemoryAllocatedBytes on Travis failed:
https://travis-ci.org/facebook/rocksdb/jobs/79887849 . This is probably due to
malloc_usable_size() returning a value greater than the requested size. From
the man page:

   The value returned by malloc_usable_size() may be greater than the requested
   size of the allocation because of alignment and minimum size constraints.
   Although the excess bytes can be overwritten by the application without ill
   effects, this is not good programming practice: the number of excess bytes
   in an allocation depends on the underlying implementation.

Test Plan: make arena_test && ./arena_test

Reviewers: rven, anthony, yhchiang, aekmekji, sdong, igor

Reviewed By: igor

Subscribers: dhruba, leveldb

Differential Revision: https://reviews.facebook.net/D46743
main
Andres Noetzli 9 years ago
parent 34cedaff66
commit c67d206898
  1. 10
      util/arena_test.cc

@ -36,7 +36,7 @@ void MemoryAllocatedBytesTest(size_t huge_page_size) {
arena.Allocate(req_sz); arena.Allocate(req_sz);
} }
expected_memory_allocated = req_sz * N + Arena::kInlineSize; expected_memory_allocated = req_sz * N + Arena::kInlineSize;
ASSERT_EQ(arena.MemoryAllocatedBytes(), expected_memory_allocated); ASSERT_GE(arena.MemoryAllocatedBytes(), expected_memory_allocated);
arena.Allocate(Arena::kInlineSize - 1); arena.Allocate(Arena::kInlineSize - 1);
@ -49,13 +49,13 @@ void MemoryAllocatedBytesTest(size_t huge_page_size) {
arena.Allocate(req_sz); arena.Allocate(req_sz);
} }
if (huge_page_size) { if (huge_page_size) {
ASSERT_TRUE(arena.MemoryAllocatedBytes() == ASSERT_TRUE(arena.MemoryAllocatedBytes() >=
expected_memory_allocated + bsz || expected_memory_allocated + bsz ||
arena.MemoryAllocatedBytes() == arena.MemoryAllocatedBytes() >=
expected_memory_allocated + huge_page_size); expected_memory_allocated + huge_page_size);
} else { } else {
expected_memory_allocated += bsz; expected_memory_allocated += bsz;
ASSERT_EQ(arena.MemoryAllocatedBytes(), expected_memory_allocated); ASSERT_GE(arena.MemoryAllocatedBytes(), expected_memory_allocated);
} }
// requested size > size of a block: // requested size > size of a block:
@ -66,7 +66,7 @@ void MemoryAllocatedBytesTest(size_t huge_page_size) {
arena.Allocate(req_sz); arena.Allocate(req_sz);
} }
expected_memory_allocated += req_sz * N; expected_memory_allocated += req_sz * N;
ASSERT_EQ(arena.MemoryAllocatedBytes(), expected_memory_allocated); ASSERT_GE(arena.MemoryAllocatedBytes(), expected_memory_allocated);
} }
// Make sure we didn't count the allocate but not used memory space in // Make sure we didn't count the allocate but not used memory space in

Loading…
Cancel
Save