Commit cec3fa89 authored by Nicholas Ormrod's avatar Nicholas Ormrod Committed by Sara Golemon

Fix block overhead estimation in tests

Summary:
folly/test/ArenaTest.h assumes that goodMallocSize will account
for the block overhead, if the size is +1. However, when compiling
without jemalloc (as, I would imagine, most of our open-source clients
do), goodMallocSize(64 + 1) returns 65, which is less than 64 +
sizeof(Block), and so the tests fail.

I have added a constant to Arena.h which exposes the overhead taken by
the Block, and changed the tests to use that value instead of 1.
(Arena::getTotalSize relies on the totalAllocatedSize_ variable, which
is only non-trivially set in allocateSlow, where the size of the heap is
added to sizeof(Block)).

Test Plan: fbconfig --allocator=malloc folly/test:arena_test && fbmake runtests

Reviewed By: jon.coens@fb.com

Subscribers: sdwilsh, njormrod

FB internal diff: D1512231
parent 5899b4ed
...@@ -157,6 +157,7 @@ class Arena { ...@@ -157,6 +157,7 @@ class Arena {
static constexpr size_t kDefaultMinBlockSize = 4096 - sizeof(Block); static constexpr size_t kDefaultMinBlockSize = 4096 - sizeof(Block);
static constexpr size_t kNoSizeLimit = 0; static constexpr size_t kNoSizeLimit = 0;
static constexpr size_t kDefaultMaxAlign = alignof(Block); static constexpr size_t kDefaultMaxAlign = alignof(Block);
static constexpr size_t kBlockOverhead = sizeof(Block);
private: private:
bool isAligned(uintptr_t address) const { bool isAligned(uintptr_t address) const {
......
...@@ -39,7 +39,7 @@ TEST(Arena, SizeSanity) { ...@@ -39,7 +39,7 @@ TEST(Arena, SizeSanity) {
size_t* ptr = static_cast<size_t*>(arena.allocate(sizeof(long))); size_t* ptr = static_cast<size_t*>(arena.allocate(sizeof(long)));
allocatedItems.insert(ptr); allocatedItems.insert(ptr);
minimum_size += requestedBlockSize; minimum_size += requestedBlockSize;
maximum_size += goodMallocSize(requestedBlockSize + 1); maximum_size += goodMallocSize(requestedBlockSize + SysArena::kBlockOverhead);
EXPECT_TRUE(arena.totalSize() >= minimum_size); EXPECT_TRUE(arena.totalSize() >= minimum_size);
EXPECT_TRUE(arena.totalSize() <= maximum_size); EXPECT_TRUE(arena.totalSize() <= maximum_size);
VLOG(4) << minimum_size << " < " << arena.totalSize() << " < " VLOG(4) << minimum_size << " < " << arena.totalSize() << " < "
...@@ -59,7 +59,8 @@ TEST(Arena, SizeSanity) { ...@@ -59,7 +59,8 @@ TEST(Arena, SizeSanity) {
allocatedItems.insert(ptr); allocatedItems.insert(ptr);
} }
minimum_size += 10 * requestedBlockSize; minimum_size += 10 * requestedBlockSize;
maximum_size += 10 * goodMallocSize(requestedBlockSize + 1); maximum_size += 10 * goodMallocSize(requestedBlockSize
+ SysArena::kBlockOverhead);
EXPECT_TRUE(arena.totalSize() >= minimum_size); EXPECT_TRUE(arena.totalSize() >= minimum_size);
EXPECT_TRUE(arena.totalSize() <= maximum_size); EXPECT_TRUE(arena.totalSize() <= maximum_size);
VLOG(4) << minimum_size << " < " << arena.totalSize() << " < " VLOG(4) << minimum_size << " < " << arena.totalSize() << " < "
...@@ -69,7 +70,8 @@ TEST(Arena, SizeSanity) { ...@@ -69,7 +70,8 @@ TEST(Arena, SizeSanity) {
ptr = static_cast<size_t*>(arena.allocate(10 * requestedBlockSize)); ptr = static_cast<size_t*>(arena.allocate(10 * requestedBlockSize));
allocatedItems.insert(ptr); allocatedItems.insert(ptr);
minimum_size += 10 * requestedBlockSize; minimum_size += 10 * requestedBlockSize;
maximum_size += goodMallocSize(10 * requestedBlockSize + 1); maximum_size += goodMallocSize(10 * requestedBlockSize
+ SysArena::kBlockOverhead);
EXPECT_TRUE(arena.totalSize() >= minimum_size); EXPECT_TRUE(arena.totalSize() >= minimum_size);
EXPECT_TRUE(arena.totalSize() <= maximum_size); EXPECT_TRUE(arena.totalSize() <= maximum_size);
VLOG(4) << minimum_size << " < " << arena.totalSize() << " < " VLOG(4) << minimum_size << " < " << arena.totalSize() << " < "
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment