| 99 | } |
| 100 | |
| 101 | PoolId MemoryPoolManager::createNewPool(folly::StringPiece name, |
| 102 | size_t poolSize, |
| 103 | const std::set<uint32_t>& allocSizes) { |
| 104 | std::unique_lock l(lock_); |
| 105 | if (poolsByName_.find(name) != poolsByName_.end()) { |
| 106 | throw std::invalid_argument("Duplicate pool"); |
| 107 | } |
| 108 | |
| 109 | if (nextPoolId_ == kMaxPools) { |
| 110 | throw std::logic_error("All pools exhausted"); |
| 111 | } |
| 112 | |
| 113 | const size_t remaining = getRemainingSizeLocked(); |
| 114 | if (remaining < poolSize) { |
| 115 | // not enough memory to create a new pool. |
| 116 | throw std::invalid_argument(fmt::format( |
| 117 | "Not enough memory ({} bytes) to create a new pool of size {} bytes", |
| 118 | remaining, |
| 119 | poolSize)); |
| 120 | } |
| 121 | |
| 122 | const PoolId id = nextPoolId_; |
| 123 | pools_[id] = |
| 124 | std::make_unique<MemoryPool>(id, poolSize, slabAlloc_, allocSizes); |
| 125 | poolsByName_.insert({name.str(), id}); |
| 126 | nextPoolId_++; |
| 127 | return id; |
| 128 | } |
| 129 | |
| 130 | bool MemoryPoolManager::provisionPool( |
| 131 | PoolId pid, const std::vector<uint32_t>& slabsDistribution) { |