|
19 | 19 | #include "cachelib/allocator/CacheAllocatorConfig.h" |
20 | 20 | #include "cachelib/allocator/MemoryTierCacheConfig.h" |
21 | 21 | #include "cachelib/allocator/tests/TestBase.h" |
| 22 | +#include "cachelib/allocator/FreeThresholdStrategy.h" |
| 23 | +#include "cachelib/allocator/PromotionStrategy.h" |
22 | 24 |
|
23 | 25 | namespace facebook { |
24 | 26 | namespace cachelib { |
@@ -62,6 +64,58 @@ class AllocatorMemoryTiersTest : public AllocatorTest<AllocatorT> { |
62 | 64 | ASSERT(handle != nullptr); |
63 | 65 | ASSERT_NO_THROW(alloc->insertOrReplace(handle)); |
64 | 66 | } |
| 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 | + } |
65 | 119 |
|
66 | 120 | void testMultiTiersValidMixed() { |
67 | 121 | typename AllocatorT::Config config; |
|
0 commit comments