Commit 59b71bbb authored by Dan Melnic's avatar Dan Melnic Committed by Facebook GitHub Bot

IOBuf combine allocations only within size classes

Summary: IOBuf allocate SharedInfo in the same allocation only if we do not cross into the next class size

Reviewed By: jrahman

Differential Revision: D27353914

fbshipit-source-id: 65be3641d7eaa0588bf26101ce02668fb827eee9
parent 25cfb031
......@@ -276,6 +276,21 @@ unique_ptr<IOBuf> IOBuf::create(std::size_t capacity) {
if (capacity <= kDefaultCombinedBufSize) {
return createCombined(capacity);
}
// if we have nallocx, we want to allocate the capacity and the overhead in
// a single allocation only if we do not cross into the next allocation class
// for some buffer sizes, this can use about 25% extra memory
if (canNallocx()) {
auto mallocSize = goodMallocSize(capacity);
// round capacity to a multiple of 8
size_t minSize = ((capacity + 7) & ~7) + sizeof(SharedInfo);
// if we do not have space for the overhead, allocate the mem separateley
if (mallocSize < minSize) {
auto* buf = checkedMalloc(mallocSize);
return takeOwnership(buf, mallocSize, static_cast<size_t>(0));
}
}
return createSeparate(capacity);
}
......
......@@ -73,10 +73,8 @@ TEST(IOBuf, Simple) {
}
void testAllocSize(uint32_t requestedCapacity) {
auto expectedSize = IOBuf::goodSize(requestedCapacity);
unique_ptr<IOBuf> iobuf(IOBuf::create(requestedCapacity));
EXPECT_GE(iobuf->capacity(), requestedCapacity);
EXPECT_EQ(iobuf->capacity(), expectedSize);
}
TEST(IOBuf, AllocSizes) {
......
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