@@ -221,6 +221,61 @@ class AllocatorMemoryTiersTest : public AllocatorTest<AllocatorT> {
221
221
alloc.getCacheMemoryStats ().slabsApproxFreePercentages [1 ]);
222
222
}
223
223
}
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
+ auto handle = alloc.allocate (pool, " key2" , Slab::kSize / 2 );
254
+ ASSERT (handle != nullptr );
255
+ std::string data2 = " lorem ipsum the second" ;
256
+ std::memcpy (reinterpret_cast <char *>(handle->getMemory ()), data2.data (),
257
+ data2.size ());
258
+ alloc.insertOrReplace (handle);
259
+ // Item in the first tier.
260
+ ASSERT_NE (alloc.getCacheMemoryStats ().slabsApproxFreePercentages [0 ],
261
+ 100.0 );
262
+ // Second tier is empty.
263
+ ASSERT_EQ (alloc.getCacheMemoryStats ().slabsApproxFreePercentages [1 ],
264
+ 100.0 );
265
+ }
266
+ {
267
+ // Check if key1 was evicted.
268
+ auto found = alloc.find (" key1" );
269
+ ASSERT_EQ (found, nullptr );
270
+ }
271
+ {
272
+ // Check if key2 is present.
273
+ auto found = alloc.find (" key2" );
274
+ ASSERT_NE (found, nullptr );
275
+ ASSERT_EQ (found->getSize (), Slab::kSize / 2 );
276
+ }
277
+ }
278
+ }
224
279
};
225
280
} // namespace tests
226
281
} // namespace cachelib
0 commit comments