| 112 | } |
| 113 | |
| 114 | void AsyncDataCacheEntry::initialize(FileCacheKey key) { |
| 115 | BOLT_CHECK(isExclusive()); |
| 116 | setSsdFile(nullptr, 0); |
| 117 | key_ = std::move(key); |
| 118 | auto* cache = shard_->cache(); |
| 119 | ClockTimer t(shard_->allocClocks()); |
| 120 | if (size_ < AsyncDataCacheEntry::kTinyDataSize) { |
| 121 | tinyData_.resize(size_); |
| 122 | tinyData_.shrink_to_fit(); |
| 123 | } else { |
| 124 | tinyData_.clear(); |
| 125 | tinyData_.shrink_to_fit(); |
| 126 | const auto sizePages = memory::AllocationTraits::numPages(size_); |
| 127 | if (cache->allocator()->allocateNonContiguous(sizePages, data_)) { |
| 128 | cache->incrementCachedPages(data().numPages()); |
| 129 | } else { |
| 130 | // No memory to cover 'this'. |
| 131 | release(); |
| 132 | _BOLT_THROW( |
| 133 | BoltRuntimeError, |
| 134 | error_source::kErrorSourceRuntime.c_str(), |
| 135 | error_code::kNoCacheSpace.c_str(), |
| 136 | /* isRetriable */ true, |
| 137 | "Failed to allocate {} bytes for cache", |
| 138 | size_); |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | void AsyncDataCacheEntry::makeEvictable() { |
| 144 | accessStats_.lastUse = 0; |
no test coverage detected