| 115 | } |
| 116 | |
| 117 | PoolId MemoryAllocator::addPool(folly::StringPiece name, |
| 118 | size_t size, |
| 119 | const std::set<uint32_t>& allocSizes, |
| 120 | bool ensureProvisionable) { |
| 121 | const std::set<uint32_t>& poolAllocSizes = |
| 122 | allocSizes.empty() ? config_.allocSizes : allocSizes; |
| 123 | |
| 124 | if (poolAllocSizes.size() > MemoryAllocator::kMaxClasses) { |
| 125 | throw std::invalid_argument("Too many allocation classes"); |
| 126 | } |
| 127 | |
| 128 | if (ensureProvisionable && |
| 129 | cachelib::Slab::kSize * poolAllocSizes.size() > size) { |
| 130 | throw std::invalid_argument(fmt::format( |
| 131 | "Pool {} cannot have at least one slab for each allocation class. " |
| 132 | "{} bytes required, {} bytes given.", |
| 133 | name, |
| 134 | cachelib::Slab::kSize * poolAllocSizes.size(), |
| 135 | size)); |
| 136 | } |
| 137 | |
| 138 | return memoryPoolManager_.createNewPool(name, size, poolAllocSizes); |
| 139 | } |
| 140 | |
| 141 | PoolId MemoryAllocator::getPoolId(std::string_view name) const noexcept { |
| 142 | try { |