Commit 5c672ce7 authored by Giuseppe Ottaviano's avatar Giuseppe Ottaviano Committed by Facebook GitHub Bot

Fix IOBufQueue.ClearAndTryReuseLargestBuffer with jemalloc

Summary: `IOBuf` capacity can be rounded up if supported by the allocator, and the round-up is done including the size of the shared info struct in `createCombined()`, so requesting 8 and 16 can return buffers with the same capacity, breaking the test.

Reviewed By: yfeldblum

Differential Revision: D33004319

fbshipit-source-id: 2bfbeaf7249e89325f9d2b11aa844c1ae1b1ceca
parent 4c88c71c
...@@ -130,7 +130,7 @@ TEST(IOBufQueue, Reset) { ...@@ -130,7 +130,7 @@ TEST(IOBufQueue, Reset) {
IOBufQueue queue(clOptions); IOBufQueue queue(clOptions);
queue.preallocate(8, 8); queue.preallocate(8, 8);
queue.append(SCL("Hello ")); queue.append(SCL("Hello "));
queue.preallocate(16, 16); queue.preallocate(128, 128);
queue.append(SCL("World")); queue.append(SCL("World"));
EXPECT_EQ(2, queue.front()->countChainElements()); EXPECT_EQ(2, queue.front()->countChainElements());
queue.reset(); queue.reset();
...@@ -143,13 +143,15 @@ TEST(IOBufQueue, ClearAndTryReuseLargestBuffer) { ...@@ -143,13 +143,15 @@ TEST(IOBufQueue, ClearAndTryReuseLargestBuffer) {
queue.preallocate(8, 8); queue.preallocate(8, 8);
queue.append(SCL("Hello ")); queue.append(SCL("Hello "));
queue.preallocate(16, 16); // Separate allocation sizes enough that, if they're internally rounded up,
// all the buffers have different capacities.
queue.preallocate(128, 128);
queue.append(SCL("World ")); queue.append(SCL("World "));
// The current tail will be kept. // The current tail will be kept.
const IOBuf* kept = queue.front()->prev(); const IOBuf* kept = queue.front()->prev();
// The new tail is larger but cannot be reused because it's shared. // The new tail is larger but cannot be reused because it's shared.
queue.preallocate(32, 32); queue.preallocate(256, 256);
queue.append(SCL("abc")); queue.append(SCL("abc"));
const auto shared = queue.front()->prev()->cloneOne(); const auto shared = queue.front()->prev()->cloneOne();
EXPECT_EQ(3, queue.front()->countChainElements()); EXPECT_EQ(3, queue.front()->countChainElements());
......
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