From cec3fa895b00598fc2f2c60f7591bf5969ef7fd3 Mon Sep 17 00:00:00 2001 From: Nicholas Ormrod Date: Fri, 22 Aug 2014 10:07:25 -0700 Subject: [PATCH] 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 --- folly/Arena.h | 1 + folly/test/ArenaTest.cpp | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/folly/Arena.h b/folly/Arena.h index e08ca064..ce758e5b 100644 --- a/folly/Arena.h +++ b/folly/Arena.h @@ -157,6 +157,7 @@ class Arena { static constexpr size_t kDefaultMinBlockSize = 4096 - sizeof(Block); static constexpr size_t kNoSizeLimit = 0; static constexpr size_t kDefaultMaxAlign = alignof(Block); + static constexpr size_t kBlockOverhead = sizeof(Block); private: bool isAligned(uintptr_t address) const { diff --git a/folly/test/ArenaTest.cpp b/folly/test/ArenaTest.cpp index 4d77e207..6c05fa2e 100644 --- a/folly/test/ArenaTest.cpp +++ b/folly/test/ArenaTest.cpp @@ -39,7 +39,7 @@ TEST(Arena, SizeSanity) { size_t* ptr = static_cast(arena.allocate(sizeof(long))); allocatedItems.insert(ptr); minimum_size += requestedBlockSize; - maximum_size += goodMallocSize(requestedBlockSize + 1); + maximum_size += goodMallocSize(requestedBlockSize + SysArena::kBlockOverhead); EXPECT_TRUE(arena.totalSize() >= minimum_size); EXPECT_TRUE(arena.totalSize() <= maximum_size); VLOG(4) << minimum_size << " < " << arena.totalSize() << " < " @@ -59,7 +59,8 @@ TEST(Arena, SizeSanity) { allocatedItems.insert(ptr); } 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() <= maximum_size); VLOG(4) << minimum_size << " < " << arena.totalSize() << " < " @@ -69,7 +70,8 @@ TEST(Arena, SizeSanity) { ptr = static_cast(arena.allocate(10 * requestedBlockSize)); allocatedItems.insert(ptr); 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() <= maximum_size); VLOG(4) << minimum_size << " < " << arena.totalSize() << " < " -- 2.34.1