-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Remove inheritence relationship between AsyncDataCache and MemoryAllo… #5503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,7 @@ AsyncDataCacheEntry::AsyncDataCacheEntry(CacheShard* shard) : shard_(shard) { | |
| } | ||
|
|
||
| AsyncDataCacheEntry::~AsyncDataCacheEntry() { | ||
| shard_->cache()->freeNonContiguous(data_); | ||
| shard_->cache()->allocator()->freeNonContiguous(data_); | ||
| } | ||
|
|
||
| void AsyncDataCacheEntry::setExclusiveToShared() { | ||
|
|
@@ -108,7 +108,7 @@ void AsyncDataCacheEntry::initialize(FileCacheKey key) { | |
| tinyData_.clear(); | ||
| auto sizePages = bits::roundUp(size_, memory::AllocationTraits::kPageSize) / | ||
| memory::AllocationTraits::kPageSize; | ||
| if (cache->allocateNonContiguous(sizePages, data_)) { | ||
| if (cache->allocator()->allocateNonContiguous(sizePages, data_)) { | ||
| cache->incrementCachedPages(data().numPages()); | ||
| } else { | ||
| // No memory to cover 'this'. | ||
|
|
@@ -324,7 +324,7 @@ void CacheShard::removeEntryLocked(AsyncDataCacheEntry* entry) { | |
| auto numPages = entry->data().numPages(); | ||
| if (numPages) { | ||
| cache_->incrementCachedPages(-numPages); | ||
| cache_->freeNonContiguous(entry->data()); | ||
| cache_->allocator()->freeNonContiguous(entry->data()); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -412,7 +412,7 @@ void CacheShard::evict(uint64_t bytesToFree, bool evictAllUnpinned) { | |
|
|
||
| void CacheShard::freeAllocations(std::vector<memory::Allocation>& allocations) { | ||
| for (auto& allocation : allocations) { | ||
| cache_->freeNonContiguous(allocation); | ||
| cache_->allocator()->freeNonContiguous(allocation); | ||
| } | ||
| allocations.clear(); | ||
| } | ||
|
|
@@ -495,24 +495,52 @@ void CacheShard::appendSsdSaveable(std::vector<CachePin>& pins) { | |
| } | ||
|
|
||
| AsyncDataCache::AsyncDataCache( | ||
| const std::shared_ptr<MemoryAllocator>& allocator, | ||
| uint64_t /* maxBytes */, | ||
| memory::MemoryAllocator* allocator, | ||
| std::unique_ptr<SsdCache> ssdCache) | ||
| : allocator_(allocator), ssdCache_(std::move(ssdCache)), cachedPages_(0) { | ||
| for (auto i = 0; i < kNumShards; ++i) { | ||
| shards_.push_back(std::make_unique<CacheShard>(this)); | ||
| } | ||
| } | ||
|
|
||
| AsyncDataCache::AsyncDataCache( | ||
| const std::shared_ptr<MemoryAllocator>& allocator, | ||
| std::unique_ptr<SsdCache> ssdCache) | ||
| : allocator_(allocator), ssdCache_(std::move(ssdCache)), cachedPages_(0) { | ||
| for (auto i = 0; i < kNumShards; ++i) { | ||
| shards_.push_back(std::make_unique<CacheShard>(this)); | ||
| AsyncDataCache::~AsyncDataCache() {} | ||
|
|
||
| // static | ||
| std::shared_ptr<AsyncDataCache> AsyncDataCache::create( | ||
| memory::MemoryAllocator* allocator, | ||
| std::unique_ptr<SsdCache> ssdCache) { | ||
| auto cache = std::make_shared<AsyncDataCache>(allocator, std::move(ssdCache)); | ||
| allocator->registerCache(cache); | ||
| return cache; | ||
| } | ||
|
|
||
| // static | ||
| AsyncDataCache* AsyncDataCache::getInstance() { | ||
| return *getInstancePtr(); | ||
| } | ||
|
|
||
| // static | ||
| void AsyncDataCache::setInstance(AsyncDataCache* asyncDataCache) { | ||
| *getInstancePtr() = asyncDataCache; | ||
| } | ||
|
|
||
| // static | ||
| AsyncDataCache** AsyncDataCache::getInstancePtr() { | ||
| static AsyncDataCache* cache_{nullptr}; | ||
| return &cache_; | ||
| } | ||
|
|
||
| void AsyncDataCache::prepareShutdown() { | ||
| for (auto& shard : shards_) { | ||
| shard->prepareShutdown(); | ||
| } | ||
| } | ||
|
|
||
| void CacheShard::prepareShutdown() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just name it as shutdown() |
||
| entries_.clear(); | ||
| freeEntries_.clear(); | ||
| } | ||
|
|
||
| CachePin AsyncDataCache::findOrCreate( | ||
| RawFileCacheKey key, | ||
| uint64_t size, | ||
|
|
@@ -611,50 +639,6 @@ void AsyncDataCache::backoff(int32_t counter) { | |
| std::this_thread::sleep_for(std::chrono::microseconds(usec)); // NOLINT | ||
| } | ||
|
|
||
| bool AsyncDataCache::allocateNonContiguous( | ||
| MachinePageCount numPages, | ||
| memory::Allocation& out, | ||
| ReservationCallback reservationCB, | ||
| MachinePageCount minSizeClass) { | ||
| return makeSpace(numPages, [&]() { | ||
| return allocator_->allocateNonContiguous( | ||
| numPages, out, reservationCB, minSizeClass); | ||
| }); | ||
| } | ||
|
|
||
| bool AsyncDataCache::allocateContiguous( | ||
| memory::MachinePageCount numPages, | ||
| memory::Allocation* collateral, | ||
| memory::ContiguousAllocation& allocation, | ||
| ReservationCallback reservationCB, | ||
| memory::MachinePageCount maxPages) { | ||
| return makeSpace(numPages, [&]() { | ||
| return allocator_->allocateContiguous( | ||
| numPages, collateral, allocation, reservationCB, maxPages); | ||
| }); | ||
| } | ||
|
|
||
| bool AsyncDataCache::growContiguous( | ||
| MachinePageCount increment, | ||
| memory::ContiguousAllocation& allocation, | ||
| ReservationCallback reservationCB) { | ||
| return makeSpace(increment, [&]() { | ||
| return allocator_->growContiguous(increment, allocation, reservationCB); | ||
| }); | ||
| } | ||
|
|
||
| void* AsyncDataCache::allocateBytes(uint64_t bytes, uint16_t alignment) { | ||
| void* result = nullptr; | ||
| makeSpace( | ||
| bits::roundUp(bytes, memory::AllocationTraits::kPageSize) / | ||
| memory::AllocationTraits::kPageSize, | ||
| [&]() { | ||
| result = allocator_->allocateBytes(bytes, alignment); | ||
| return result != nullptr; | ||
| }); | ||
| return result; | ||
| } | ||
|
|
||
| void AsyncDataCache::incrementNew(uint64_t size) { | ||
| newBytes_ += size; | ||
| if (!ssdCache_) { | ||
|
|
@@ -725,7 +709,7 @@ std::string AsyncDataCache::toString() const { | |
| << " read pins " << stats.numShared << " write pins " | ||
| << stats.numExclusive << " unused prefetch " << stats.numPrefetch | ||
| << " Alloc Megaclocks " << (stats.allocClocks >> 20) | ||
| << " allocated pages " << numAllocated() << " cached pages " | ||
| << " allocated pages " << allocator_->numAllocated() << " cached pages " | ||
| << cachedPages_; | ||
| out << "\nBacking: " << allocator_->toString(); | ||
| if (ssdCache_) { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.