Skip to content

Commit

Permalink
Fixed arena_test failure due to malloc_usable_size()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
4tXJ7f committed Sep 11, 2015
1 parent 34cedaf commit c67d206
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions util/arena_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void MemoryAllocatedBytesTest(size_t huge_page_size) {
arena.Allocate(req_sz);
}
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);

Expand All @@ -49,13 +49,13 @@ void MemoryAllocatedBytesTest(size_t huge_page_size) {
arena.Allocate(req_sz);
}
if (huge_page_size) {
ASSERT_TRUE(arena.MemoryAllocatedBytes() ==
ASSERT_TRUE(arena.MemoryAllocatedBytes() >=
expected_memory_allocated + bsz ||
arena.MemoryAllocatedBytes() ==
arena.MemoryAllocatedBytes() >=
expected_memory_allocated + huge_page_size);
} else {
expected_memory_allocated += bsz;
ASSERT_EQ(arena.MemoryAllocatedBytes(), expected_memory_allocated);
ASSERT_GE(arena.MemoryAllocatedBytes(), expected_memory_allocated);
}

// requested size > size of a block:
Expand All @@ -66,7 +66,7 @@ void MemoryAllocatedBytesTest(size_t huge_page_size) {
arena.Allocate(req_sz);
}
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
Expand Down

0 comments on commit c67d206

Please sign in to comment.