[compiler-rt] [scudo] Update secondary cache time-based release logic. (PR #107507)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 12 11:45:24 PDT 2024


================
@@ -590,35 +594,37 @@ class MapAllocatorCache {
     }
   }
 
-  void releaseIfOlderThan(CachedBlock &Entry, u64 Time) REQUIRES(Mutex) {
-    if (!Entry.isValid() || !Entry.Time)
-      return;
-    if (Entry.Time > Time) {
-      if (OldestTime == 0 || Entry.Time < OldestTime)
-        OldestTime = Entry.Time;
-      return;
-    }
+  inline void release(CachedBlock &Entry) {
+    DCHECK(Entry.Time != 0);
     Entry.MemMap.releaseAndZeroPagesToOS(Entry.CommitBase, Entry.CommitSize);
     Entry.Time = 0;
   }
 
   void releaseOlderThan(u64 Time) EXCLUDES(Mutex) {
     ScopedLock L(Mutex);
-    if (!EntriesCount || OldestTime == 0 || OldestTime > Time)
+    if (!EntriesCount)
       return;
-    OldestTime = 0;
-    for (uptr I = 0; I < Config::getQuarantineSize(); I++)
-      releaseIfOlderThan(Quarantine[I], Time);
-    for (uptr I = 0; I < Config::getEntriesArraySize(); I++)
-      releaseIfOlderThan(Entries[I], Time);
-  }
 
+    for (uptr I = 0; I < Config::getQuarantineSize(); I++) {
+      CachedBlock &ReleaseEntry = Quarantine[I];
+      if (!ReleaseEntry.isValid() || ReleaseEntry.Time > Time ||
+          !ReleaseEntry.Time)
+        continue;
----------------
ChiaHungDuan wrote:

```suggestion
      if (!ReleaseEntry.isValid() || !ReleaseEntry.Time ||
          ReleaseEntry.Time > Time)  {
        continue;
      }
```
It's more logical to check `!ReleaseEntry.Time` first

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


More information about the llvm-commits mailing list