[compiler-rt] [scudo] Added LRU eviction policy to secondary cache. (PR #99409)
Christopher Ferris via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 22 22:08:46 PDT 2024
================
@@ -213,23 +225,39 @@ template <typename Config> class MapAllocatorCache {
if (Config::getDefaultReleaseToOsIntervalMs() != INT32_MIN)
ReleaseToOsInterval = Config::getDefaultReleaseToOsIntervalMs();
setOption(Option::ReleaseInterval, static_cast<sptr>(ReleaseToOsInterval));
+
+ // The cache is initially empty
+ LRUHead = CachedBlock::InvalidEntry;
+ LRUTail = CachedBlock::InvalidEntry;
+
+ // Available entries will be retrieved starting from the beginning of the
+ // Entries array
+ AvailableHead = 0;
+ for (u32 I = 0; I < Config::getEntriesArraySize() - 1; I++)
+ Entries[I].Next = static_cast<u16>(I + 1);
+
+ Entries[Config::getEntriesArraySize() - 1].Next = CachedBlock::InvalidEntry;
}
void store(const Options &Options, LargeBlock::Header *H) EXCLUDES(Mutex) {
if (!canCache(H->CommitSize))
return unmap(H);
- bool EntryCached = false;
- bool EmptyCache = false;
const s32 Interval = atomic_load_relaxed(&ReleaseToOsIntervalMs);
- const u64 Time = getMonotonicTimeFast();
- const u32 MaxCount = atomic_load_relaxed(&MaxEntriesCount);
+ u64 Time;
CachedBlock Entry;
+
+ // Usually only one entry will be evicted from the cache.
+ // Only in the rare event that the cache shrinks in real-time
+ // due to a decrease in the configurable value MaxEntriesCount
+ // will more than one cache entry be evicted
+ Vector<MemMapT, 1U> EvictionMemMaps;
----------------
cferris1000 wrote:
I'd move this right in front of the do loop down below so it's more obvious where this is used. I'd also add a comment explaining that you using this to gather the maps to evict and then doing it outside of the lock.
https://github.com/llvm/llvm-project/pull/99409
More information about the llvm-commits
mailing list