Skip to content

Commit a474465

Browse files
committed
simple tests
1 parent c5f7404 commit a474465

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

cachelib/allocator/tests/AllocatorMemoryTiersTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ using LruAllocatorMemoryTiersTest = AllocatorMemoryTiersTest<LruAllocator>;
2626
TEST_F(LruAllocatorMemoryTiersTest, MultiTiersFromFileInvalid) { this->testMultiTiersFormFileInvalid(); }
2727
TEST_F(LruAllocatorMemoryTiersTest, MultiTiersFromFileValid) { this->testMultiTiersFromFileValid(); }
2828
TEST_F(LruAllocatorMemoryTiersTest, MultiTiersValidMixed) { this->testMultiTiersValidMixed(); }
29+
TEST_F(LruAllocatorMemoryTiersTest, MultiTiersBackgroundMovers ) { this->testMultiTiersBackgroundMovers(); }
2930
TEST_F(LruAllocatorMemoryTiersTest, MultiTiersNumaBindingsSysVValid) { this->testMultiTiersNumaBindingsSysVValid(); }
3031
TEST_F(LruAllocatorMemoryTiersTest, MultiTiersNumaBindingsPosixValid) { this->testMultiTiersNumaBindingsPosixValid(); }
3132

cachelib/allocator/tests/AllocatorMemoryTiersTest.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "cachelib/allocator/CacheAllocatorConfig.h"
2020
#include "cachelib/allocator/MemoryTierCacheConfig.h"
2121
#include "cachelib/allocator/tests/TestBase.h"
22+
#include "cachelib/allocator/FreeThresholdStrategy.h"
23+
#include "cachelib/allocator/PromotionStrategy.h"
2224

2325
namespace facebook {
2426
namespace cachelib {
@@ -62,6 +64,58 @@ class AllocatorMemoryTiersTest : public AllocatorTest<AllocatorT> {
6264
ASSERT(handle != nullptr);
6365
ASSERT_NO_THROW(alloc->insertOrReplace(handle));
6466
}
67+
68+
void testMultiTiersBackgroundMovers() {
69+
typename AllocatorT::Config config;
70+
config.setCacheSize(4 * Slab::kSize);
71+
config.enableCachePersistence("/tmp");
72+
config.usePosixForShm();
73+
config.configureMemoryTiers({
74+
MemoryTierCacheConfig::fromShm()
75+
.setRatio(1),
76+
MemoryTierCacheConfig::fromFile("/tmp/b" + std::to_string(::getpid()))
77+
.setRatio(1)
78+
});
79+
config.enableBackgroundEvictor(std::make_shared<FreeThresholdStrategy>(10, 20, 4, 2),
80+
std::chrono::milliseconds(10),1);
81+
config.enableBackgroundPromoter(std::make_shared<PromotionStrategy>(5, 4, 2),
82+
std::chrono::milliseconds(10),1);
83+
84+
auto allocator = std::make_unique<AllocatorT>(AllocatorT::SharedMemNew, config);
85+
ASSERT(allocator != nullptr);
86+
87+
const size_t numBytes = allocator->getCacheMemoryStats().cacheSize;
88+
const size_t kItemSize = 100;
89+
auto poolId = allocator->addPool("default", numBytes);
90+
91+
const int numItems = 10000;
92+
93+
int numAllocatedItems = 0;
94+
for (unsigned int i = 0; i < numItems; i++) {
95+
auto handle = util::allocateAccessible(
96+
*allocator, poolId, folly::to<std::string>(i), kItemSize, 0);
97+
++numAllocatedItems;
98+
}
99+
100+
ASSERT_GT(numAllocatedItems, 0);
101+
102+
const unsigned int keyLen = 100;
103+
const unsigned int nSizes = 10;
104+
const auto sizes =
105+
this->getValidAllocSizes(*allocator, poolId, nSizes, keyLen);
106+
this->fillUpPoolUntilEvictions(*allocator, poolId, sizes, keyLen);
107+
108+
auto stats = allocator->getGlobalCacheStats();
109+
auto perclassEstats = allocator->getBackgroundMoverClassStats(MoverDir::Evict);
110+
auto perclassPstats = allocator->getBackgroundMoverClassStats(MoverDir::Promote);
111+
112+
EXPECT_GT(1, stats.evictionStats.numMovedItems);
113+
EXPECT_GT(1, stats.promotionStats.numMovedItems);
114+
115+
auto cid = 2;
116+
EXPECT_GT(1, perclassEstats[0][0][cid]);
117+
EXPECT_GT(1, perclassPstats[1][0][cid]);
118+
}
65119

66120
void testMultiTiersValidMixed() {
67121
typename AllocatorT::Config config;

0 commit comments

Comments
 (0)