Skip to content

Commit e1d1840

Browse files
igchorvinser52
authored andcommitted
basic multi-tier test based on numa bindings
1 parent 2727c05 commit e1d1840

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

cachelib/allocator/tests/AllocatorTypeTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ TYPED_TEST(BaseAllocatorTest, RateMap) { this->testRateMap(); }
410410
TYPED_TEST(BaseAllocatorTest, StatSnapshotTest) {
411411
this->testStatSnapshotTest();
412412
}
413+
TYPED_TEST(BaseAllocatorTest, BasicMultiTier) {this->testBasicMultiTier(); }
413414

414415
namespace { // the tests that cannot be done by TYPED_TEST.
415416

cachelib/allocator/tests/BaseAllocatorTest.h

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6305,6 +6305,86 @@ class BaseAllocatorTest : public AllocatorTest<AllocatorT> {
63056305
});
63066306
EXPECT_EQ(intervalNameExists, 4);
63076307
}
6308+
6309+
void testSingleTierMemoryAllocatorSize() {
6310+
typename AllocatorT::Config config;
6311+
static constexpr size_t cacheSize = 100 * 1024 * 1024; /* 100 MB */
6312+
config.setCacheSize(cacheSize);
6313+
config.enableCachePersistence(folly::sformat("/tmp/single-tier-test/{}", ::getpid()));
6314+
6315+
AllocatorT alloc(AllocatorT::SharedMemNew, config);
6316+
6317+
EXPECT_LE(alloc.allocator_[0]->getMemorySize(), cacheSize);
6318+
}
6319+
6320+
void testSingleTierMemoryAllocatorSizeAnonymous() {
6321+
typename AllocatorT::Config config;
6322+
static constexpr size_t cacheSize = 100 * 1024 * 1024; /* 100 MB */
6323+
config.setCacheSize(cacheSize);
6324+
6325+
AllocatorT alloc(config);
6326+
6327+
EXPECT_LE(alloc.allocator_[0]->getMemorySize(), cacheSize);
6328+
}
6329+
6330+
void testBasicMultiTier() {
6331+
using Item = typename AllocatorT::Item;
6332+
const static std::string data = "data";
6333+
6334+
std::set<std::string> movedKeys;
6335+
auto moveCb = [&](const Item& oldItem, Item& newItem, Item* /* parentPtr */) {
6336+
std::memcpy(newItem.getMemory(), oldItem.getMemory(), oldItem.getSize());
6337+
movedKeys.insert(oldItem.getKey().str());
6338+
};
6339+
6340+
typename AllocatorT::Config config;
6341+
static constexpr size_t cacheSize = 100 * 1024 * 1024; /* 100 MB */
6342+
config.setCacheSize(100 * 1024 * 1024); /* 100 MB */
6343+
config.enableCachePersistence(folly::sformat("/tmp/multi-tier-test/{}", ::getpid()));
6344+
config.configureMemoryTiers({
6345+
MemoryTierCacheConfig::fromShm().setRatio(1)
6346+
.setMemBind(std::string("0")),
6347+
MemoryTierCacheConfig::fromShm().setRatio(1)
6348+
.setMemBind(std::string("0")),
6349+
});
6350+
config.enableMovingOnSlabRelease(moveCb);
6351+
6352+
AllocatorT alloc(AllocatorT::SharedMemNew, config);
6353+
6354+
EXPECT_EQ(alloc.allocator_.size(), 2);
6355+
EXPECT_LE(alloc.allocator_[0]->getMemorySize(), cacheSize / 2);
6356+
EXPECT_LE(alloc.allocator_[1]->getMemorySize(), cacheSize / 2);
6357+
6358+
const size_t numBytes = alloc.getCacheMemoryStats().ramCacheSize;
6359+
auto pid = alloc.addPool("default", numBytes);
6360+
6361+
static constexpr size_t numOps = cacheSize / 1024;
6362+
for (int i = 0; i < numOps; i++) {
6363+
std::string key = std::to_string(i);
6364+
auto h = alloc.allocate(pid, key, 1024);
6365+
EXPECT_TRUE(h);
6366+
6367+
std::memcpy(h->getMemory(), data.data(), data.size());
6368+
6369+
alloc.insertOrReplace(h);
6370+
}
6371+
6372+
EXPECT_TRUE(movedKeys.size() > 0);
6373+
6374+
size_t movedButStillInMemory = 0;
6375+
for (const auto &k : movedKeys) {
6376+
auto h = alloc.find(k);
6377+
6378+
if (h) {
6379+
movedButStillInMemory++;
6380+
/* All moved elements should be in the second tier. */
6381+
EXPECT_TRUE(alloc.allocator_[1]->isMemoryInAllocator(h->getMemory()));
6382+
EXPECT_EQ(data, std::string((char*)h->getMemory(), data.size()));
6383+
}
6384+
}
6385+
6386+
EXPECT_TRUE(movedButStillInMemory > 0);
6387+
}
63086388
};
63096389
} // namespace tests
63106390
} // namespace cachelib

0 commit comments

Comments
 (0)