|
25 | 25 | #include <mutex> |
26 | 26 | #include <set> |
27 | 27 | #include <thread> |
| 28 | +#include <unordered_map> |
28 | 29 | #include <vector> |
29 | 30 |
|
30 | 31 | #include "cachelib/allocator/CacheAllocator.h" |
@@ -247,17 +248,31 @@ class AllocatorHitStatsTest : public SlabAllocatorTestBase { |
247 | 248 | std::vector<std::string> keys; |
248 | 249 | const unsigned int nKeys = 1000; |
249 | 250 | unsigned int initialAllocs = 0; |
| 251 | + std::unordered_map<ClassId, uint64_t> pool1Alloc; |
250 | 252 | while (keys.size() != nKeys) { |
251 | 253 | const auto keyLen = folly::Random::rand32(10, 100); |
252 | 254 | const auto allocSize = folly::Random::rand32(100, 1024 * 1024 - 1000); |
253 | 255 | auto str = cachelib::test_util::getRandomAsciiStr(keyLen); |
254 | 256 | ++initialAllocs; |
| 257 | + auto classId = alloc.getAllocClassId(poolId, str, allocSize); |
255 | 258 | auto handle = util::allocateAccessible(alloc, poolId, str, allocSize); |
256 | 259 | if (handle) { |
257 | 260 | keys.push_back(str); |
| 261 | + pool1Alloc[classId] += alloc.getAllocationSize(classId, poolId); |
258 | 262 | } |
259 | 263 | } |
260 | 264 |
|
| 265 | + // Adjust pool alloc size for each class to its ceiling slab size |
| 266 | + // and calculate the total |
| 267 | + uint64_t pool1AllocSize = 0; |
| 268 | + for (const auto& cAlloc : pool1Alloc) { |
| 269 | + pool1AllocSize += (cAlloc.second + Slab::kSize - 1) / Slab::kSize; |
| 270 | + } |
| 271 | + pool1AllocSize *= Slab::kSize; |
| 272 | + const auto tempCacheStats = alloc.getGlobalCacheStats(); |
| 273 | + ASSERT_EQ(tempCacheStats.poolUsedSize.size(), MemoryPoolManager::kMaxPools); |
| 274 | + ASSERT_EQ(tempCacheStats.poolUsedSize[0], pool1AllocSize); |
| 275 | + |
261 | 276 | if (!evictedKeys.empty()) { |
262 | 277 | for (const auto& key : evictedKeys) { |
263 | 278 | auto it = std::find(keys.begin(), keys.end(), key); |
|
0 commit comments