| 110 | } |
| 111 | |
| 112 | void BlockCache::validate(BlockCache::Config& config) const { |
| 113 | uint32_t allocAlignSize = calcAllocAlignSize(); |
| 114 | if (!folly::isPowTwo(allocAlignSize)) { |
| 115 | throw std::invalid_argument("invalid block size"); |
| 116 | } |
| 117 | if (config.regionSize % allocAlignSize != 0) { |
| 118 | throw std::invalid_argument("invalid region size"); |
| 119 | } |
| 120 | auto shiftWidth = |
| 121 | facebook::cachelib::NumBits<decltype(RelAddress().offset())>::value; |
| 122 | if (config.cacheSize > static_cast<uint64_t>(allocAlignSize) << shiftWidth) { |
| 123 | throw std::invalid_argument( |
| 124 | fmt::format("can't address cache with {} bits", shiftWidth)); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | uint32_t BlockCache::calcAllocAlignSize() const { |
| 129 | // Shift the total device size by <RelAddressWidth-in-bits>, |
no test coverage detected