diff --git a/velox/common/caching/AsyncDataCache.cpp b/velox/common/caching/AsyncDataCache.cpp index 517aaaf3603c..e156ae2d8323 100644 --- a/velox/common/caching/AsyncDataCache.cpp +++ b/velox/common/caching/AsyncDataCache.cpp @@ -663,6 +663,8 @@ bool AsyncDataCache::makeSpace( // serialize with a mutex because memory arbitration must not be // called from inside a global mutex. + clearMemoryCache(); + constexpr int32_t kMaxAttempts = kNumShards * 4; // Evict at least 1MB even for small allocations to avoid constantly hitting // the mutex protected evict loop. @@ -883,6 +885,13 @@ void AsyncDataCache::clear() { } } +void AsyncDataCache::clearMemoryCache() { + for (auto& shard : shards_) { + memory::Allocation unused; + shard->evict(std::numeric_limits::max(), false, 0, unused); + } +} + std::string AsyncDataCache::toString(bool details) const { auto stats = refreshStats(); std::stringstream out; diff --git a/velox/common/caching/AsyncDataCache.h b/velox/common/caching/AsyncDataCache.h index dd09e560543f..a29d2297617a 100644 --- a/velox/common/caching/AsyncDataCache.h +++ b/velox/common/caching/AsyncDataCache.h @@ -779,6 +779,9 @@ class AsyncDataCache : public memory::Cache { // Drops all unpinned entries. Pins stay valid. void clear(); + // Drops all unpinned entries. Pins stay valid. + void clearMemoryCache(); + // Saves all entries with 'ssdSaveable_' to 'ssdCache_'. void saveToSsd();