@@ -67,7 +67,7 @@ class AllocatorMemoryTiersTest : public AllocatorTest<AllocatorT> {
6767
6868 void testMultiTiersBackgroundMovers () {
6969 typename AllocatorT::Config config;
70- config.setCacheSize (4 * Slab::kSize );
70+ config.setCacheSize (10 * Slab::kSize );
7171 config.enableCachePersistence (" /tmp" );
7272 config.usePosixForShm ();
7373 config.configureMemoryTiers ({
@@ -76,47 +76,42 @@ class AllocatorMemoryTiersTest : public AllocatorTest<AllocatorT> {
7676 MemoryTierCacheConfig::fromFile (" /tmp/b" + std::to_string (::getpid ()))
7777 .setRatio (1 )
7878 });
79- config.enableBackgroundEvictor (std::make_shared<FreeThresholdStrategy>(10 , 20 , 4 , 2 ),
79+ config.enableBackgroundEvictor (std::make_shared<FreeThresholdStrategy>(2 , 10 , 100 , 40 ),
8080 std::chrono::milliseconds (10 ),1 );
8181 config.enableBackgroundPromoter (std::make_shared<PromotionStrategy>(5 , 4 , 2 ),
8282 std::chrono::milliseconds (10 ),1 );
8383
8484 auto allocator = std::make_unique<AllocatorT>(AllocatorT::SharedMemNew, config);
8585 ASSERT (allocator != nullptr );
86-
8786 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- }
9987
100- ASSERT_GT (numAllocatedItems, 0 );
88+ auto poolId = allocator-> addPool ( " default " , numBytes );
10189
10290 const unsigned int keyLen = 100 ;
103- const unsigned int nSizes = 10 ;
104- const auto sizes =
105- this ->getValidAllocSizes (*allocator, poolId, nSizes, keyLen);
91+ std::vector<uint32_t > sizes = {100 };
10692 this ->fillUpPoolUntilEvictions (*allocator, poolId, sizes, keyLen);
93+
94+ const auto key = this ->getRandomNewKey (*allocator, keyLen);
95+ auto handle = util::allocateAccessible (*allocator, poolId, key, sizes[0 ]);
96+ ASSERT_NE (nullptr , handle);
97+ const uint8_t cid = allocator->getAllocInfo (handle->getMemory ()).classId ;
98+
99+ // wait for bg movers
100+ std::this_thread::sleep_for (std::chrono::seconds (1 ));
107101
108102 auto stats = allocator->getGlobalCacheStats ();
109103 auto perclassEstats = allocator->getBackgroundMoverClassStats (MoverDir::Evict);
110104 auto perclassPstats = allocator->getBackgroundMoverClassStats (MoverDir::Promote);
111105
112- EXPECT_GT (1 , stats.evictionStats .numMovedItems );
113- EXPECT_GT (1 , stats.promotionStats .numMovedItems );
106+ EXPECT_GT (stats.evictionStats .numMovedItems ,1 );
107+ EXPECT_GT (stats.evictionStats .runCount ,1 );
108+ EXPECT_GT (stats.promotionStats .numMovedItems ,1 );
114109
115- auto cid = 2 ;
116- EXPECT_GT (1 , perclassEstats[0 ][0 ][cid]);
117- EXPECT_GT (1 , perclassPstats[1 ][0 ][cid]);
110+ EXPECT_GT (perclassEstats[0 ][0 ][cid], 1 );
111+ EXPECT_GT (perclassPstats[1 ][0 ][cid], 1 );
118112
119113 auto slabStats = allocator->getAllocationClassStats (0 ,0 ,cid);
114+
120115 ASSERT_GE (slabStats.approxFreePercent ,10 );
121116 }
122117
0 commit comments