[compiler-rt] [scudo] Added LRU eviction policy to secondary cache. (PR #99409)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 18 17:14:29 PDT 2024


================
@@ -269,30 +299,27 @@ template <typename Config> class MapAllocatorCache {
           OldestTime = Entry.Time;
         Entry = PrevEntry;
       }
-      if (EntriesCount >= MaxCount) {
-        if (IsFullEvents++ == 4U)
-          EmptyCache = true;
-      } else {
-        for (u32 I = 0; I < MaxCount; I++) {
-          if (Entries[I].isValid())
-            continue;
-          if (I != 0)
-            Entries[I] = Entries[0];
-          Entries[0] = Entry;
-          EntriesCount++;
-          if (OldestTime == 0)
-            OldestTime = Entry.Time;
-          EntryCached = true;
-          break;
-        }
+
+      // All excess entries are evicted from the cache
+      while (EntriesCount >= MaxCount) {
+        // Save MemMaps of evicted entries to perform unmap outside of lock
+        EvictionMemMaps.push_back(Entries[LRUTail].MemMap);
+        remove(LRUTail);
----------------
ChiaHungDuan wrote:

No, use it as the loop condition.
```
while (needToEvict()) {
  ...
}
```

https://github.com/llvm/llvm-project/pull/99409


More information about the llvm-commits mailing list