@@ -221,6 +221,69 @@ class AllocatorMemoryTiersTest : public AllocatorTest<AllocatorT> {
221221 alloc.getCacheMemoryStats ().slabsApproxFreePercentages [1 ]);
222222 }
223223 }
224+
225+ void testMultiTiersDisableEvictionToMemory () {
226+ auto config = makeDefaultConfig ();
227+ config.setCacheSize (4 * Slab::kSize );
228+ // Always allocate to fist tier.
229+ config.forceAllocationTier = 0 ;
230+ // Don't evict to memory.
231+ config.disableEvictionToMemory = true ;
232+ {
233+ AllocatorT alloc (AllocatorT::SharedMemNew, config);
234+ auto pool = alloc.addPool (" default" ,
235+ alloc.getCacheMemoryStats ().cacheSize );
236+ {
237+ // Allocate first key.
238+ auto handle = alloc.allocate (pool, " key1" , Slab::kSize / 2 );
239+ ASSERT (handle != nullptr );
240+ std::string data = " lorem ipsum the first" ;
241+ std::memcpy (reinterpret_cast <char *>(handle->getMemory ()), data.data (),
242+ data.size ());
243+ alloc.insertOrReplace (handle);
244+ // Item in the first tier.
245+ ASSERT_NE (alloc.getCacheMemoryStats ().slabsApproxFreePercentages [0 ],
246+ 100.0 );
247+ // Second tier is empty.
248+ ASSERT_EQ (alloc.getCacheMemoryStats ().slabsApproxFreePercentages [1 ],
249+ 100.0 );
250+ }
251+ {
252+ // Allocate second key.
253+ std::cout << alloc.getCacheMemoryStats ().slabsApproxFreePercentages [0 ]
254+ << std::endl;
255+ std::cout << alloc.getCacheMemoryStats ().slabsApproxFreePercentages [1 ]
256+ << std::endl;
257+ auto handle = alloc.allocate (pool, " key2" , Slab::kSize / 2 );
258+ ASSERT (handle != nullptr );
259+ std::string data2 = " lorem ipsum the second" ;
260+ std::memcpy (reinterpret_cast <char *>(handle->getMemory ()), data2.data (),
261+ data2.size ());
262+ alloc.insertOrReplace (handle);
263+ // Item in the first tier.
264+ ASSERT_NE (alloc.getCacheMemoryStats ().slabsApproxFreePercentages [0 ],
265+ 100.0 );
266+ // Second tier is empty.
267+ ASSERT_EQ (alloc.getCacheMemoryStats ().slabsApproxFreePercentages [1 ],
268+ 100.0 );
269+ std::cout << alloc.getCacheMemoryStats ().slabsApproxFreePercentages [0 ]
270+ << std::endl;
271+ std::cout << alloc.getCacheMemoryStats ().slabsApproxFreePercentages [1 ]
272+ << std::endl;
273+ }
274+ {
275+ // Check if key1 was evicted.
276+ auto found = alloc.find (" key1" );
277+ ASSERT_EQ (found, nullptr );
278+ }
279+ {
280+ // Check if key2 is present.
281+ auto found = alloc.find (" key2" );
282+ ASSERT_NE (found, nullptr );
283+ ASSERT_EQ (found->getSize (), Slab::kSize / 2 );
284+ }
285+ }
286+ }
224287};
225288} // namespace tests
226289} // namespace cachelib
0 commit comments