in cachelib/allocator/memory/MemoryPool.cpp [91:143]
void MemoryPool::checkState() const {
if (id_ < 0) {
throw std::invalid_argument(
folly::sformat("Invaild MemoryPool id {}", id_));
}
const size_t currAlloc = currAllocSize_;
const size_t currSlabAlloc = currSlabAllocSize_;
if (currAlloc > currSlabAlloc) {
throw std::invalid_argument(
folly::sformat("Alloc size {} is more than total slab alloc size {}",
currAlloc,
currSlabAlloc));
}
if (acSizes_.size() == 0 || ac_.size() == 0) {
throw std::invalid_argument("Empty alloc sizes");
}
if (acSizes_.size() != ac_.size()) {
throw std::invalid_argument(folly::sformat(
"Allocation classes are not setup correctly. acSize.size = {}, but "
"ac.size() = {}",
acSizes_.size(), ac_.size()));
}
if (!std::is_sorted(acSizes_.begin(), acSizes_.end())) {
throw std::invalid_argument("Allocation sizes are not sorted.");
}
const auto firstDuplicate =
std::adjacent_find(acSizes_.begin(), acSizes_.end());
if (firstDuplicate != acSizes_.end()) {
throw std::invalid_argument(
folly::sformat("Duplicate allocation size: {}", *firstDuplicate));
}
for (size_t i = 0; i < acSizes_.size(); i++) {
if (acSizes_[i] != ac_[i]->getAllocSize() ||
acSizes_[i] < Slab::kMinAllocSize || acSizes_[i] > Slab::kSize) {
throw std::invalid_argument(folly::sformat(
"Allocation Class with id {} and size {}, does not match the "
"allocation size we expect {}",
ac_[i]->getId(), ac_[i]->getAllocSize(), acSizes_[i]));
}
}
for (const auto slab : freeSlabs_) {
if (!slabAllocator_.isValidSlab(slab)) {
throw std::invalid_argument(folly::sformat("Invalid free slab {}", slab));
}
}
}