Skip to content

Commit ddd1a02

Browse files
committed
Revert "[scudo] Update secondary cache time-based release logic (#107507)"
This reverts commit e5271fe. Reason: buildbot breakage: https://lab.llvm.org/buildbot/#/builders/139/builds/3806
1 parent d95597d commit ddd1a02

File tree

1 file changed

+21
-31
lines changed

1 file changed

+21
-31
lines changed

Diff for: compiler-rt/lib/scudo/standalone/secondary.h

+21-31
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ class MapAllocatorCache {
247247
// The cache is initially empty
248248
LRUHead = CachedBlock::InvalidEntry;
249249
LRUTail = CachedBlock::InvalidEntry;
250-
LastUnreleasedEntry = CachedBlock::InvalidEntry;
251250

252251
// Available entries will be retrieved starting from the beginning of the
253252
// Entries array
@@ -322,10 +321,9 @@ class MapAllocatorCache {
322321
}
323322
CachedBlock PrevEntry = Quarantine[QuarantinePos];
324323
Quarantine[QuarantinePos] = Entry;
324+
if (OldestTime == 0)
325+
OldestTime = Entry.Time;
325326
Entry = PrevEntry;
326-
// Update the entry time to reflect the time that the
327-
// quarantined memory is placed in the Entries array
328-
Entry.Time = Time;
329327
}
330328

331329
// All excess entries are evicted from the cache
@@ -336,6 +334,9 @@ class MapAllocatorCache {
336334
}
337335

338336
insert(Entry);
337+
338+
if (OldestTime == 0)
339+
OldestTime = Entry.Time;
339340
} while (0);
340341

341342
for (MemMapT &EvictMemMap : EvictionMemMaps)
@@ -534,9 +535,6 @@ class MapAllocatorCache {
534535
Entries[LRUHead].Prev = static_cast<u16>(FreeIndex);
535536
}
536537

537-
if (LastUnreleasedEntry == CachedBlock::InvalidEntry)
538-
LastUnreleasedEntry = static_cast<u16>(FreeIndex);
539-
540538
Entries[FreeIndex] = Entry;
541539
Entries[FreeIndex].Next = LRUHead;
542540
Entries[FreeIndex].Prev = CachedBlock::InvalidEntry;
@@ -554,9 +552,6 @@ class MapAllocatorCache {
554552

555553
Entries[I].invalidate();
556554

557-
if (I == LastUnreleasedEntry)
558-
LastUnreleasedEntry = Entries[LastUnreleasedEntry].Prev;
559-
560555
if (I == LRUHead)
561556
LRUHead = Entries[I].Next;
562557
else
@@ -598,37 +593,35 @@ class MapAllocatorCache {
598593
}
599594
}
600595

601-
inline void release(CachedBlock &Entry) {
602-
DCHECK(Entry.Time != 0);
596+
void releaseIfOlderThan(CachedBlock &Entry, u64 Time) REQUIRES(Mutex) {
597+
if (!Entry.isValid() || !Entry.Time)
598+
return;
599+
if (Entry.Time > Time) {
600+
if (OldestTime == 0 || Entry.Time < OldestTime)
601+
OldestTime = Entry.Time;
602+
return;
603+
}
603604
Entry.MemMap.releaseAndZeroPagesToOS(Entry.CommitBase, Entry.CommitSize);
604605
Entry.Time = 0;
605606
}
606607

607608
void releaseOlderThan(u64 Time) EXCLUDES(Mutex) {
608609
ScopedLock L(Mutex);
609-
if (!EntriesCount)
610+
if (!EntriesCount || OldestTime == 0 || OldestTime > Time)
610611
return;
611-
612-
for (uptr I = 0; I < Config::getQuarantineSize(); I++) {
613-
CachedBlock &ReleaseEntry = Quarantine[I];
614-
if (!ReleaseEntry.isValid() || !ReleaseEntry.Time ||
615-
ReleaseEntry.Time > Time)
616-
continue;
617-
release(ReleaseEntry);
618-
}
619-
620-
// Release oldest entries first by releasing from decommit base
621-
while (LastUnreleasedEntry != CachedBlock::InvalidEntry &&
622-
Entries[LastUnreleasedEntry].Time <= Time) {
623-
release(Entries[LastUnreleasedEntry]);
624-
LastUnreleasedEntry = Entries[LastUnreleasedEntry].Prev;
625-
}
612+
OldestTime = 0;
613+
for (uptr I = 0; I < Config::getQuarantineSize(); I++)
614+
releaseIfOlderThan(Quarantine[I], Time);
615+
for (uptr I = 0; I < Config::getEntriesArraySize(); I++)
616+
releaseIfOlderThan(Entries[I], Time);
626617
}
618+
627619
HybridMutex Mutex;
628620
u32 EntriesCount GUARDED_BY(Mutex) = 0;
629621
u32 QuarantinePos GUARDED_BY(Mutex) = 0;
630622
atomic_u32 MaxEntriesCount = {};
631623
atomic_uptr MaxEntrySize = {};
624+
u64 OldestTime GUARDED_BY(Mutex) = 0;
632625
atomic_s32 ReleaseToOsIntervalMs = {};
633626
u32 CallsToRetrieve GUARDED_BY(Mutex) = 0;
634627
u32 SuccessfulRetrieves GUARDED_BY(Mutex) = 0;
@@ -643,9 +636,6 @@ class MapAllocatorCache {
643636
u16 LRUTail GUARDED_BY(Mutex) = 0;
644637
// The AvailableHead is the top of the stack of available entries
645638
u16 AvailableHead GUARDED_BY(Mutex) = 0;
646-
// The LastUnreleasedEntry is the least recently used entry that has not
647-
// been released
648-
u16 LastUnreleasedEntry GUARDED_BY(Mutex) = 0;
649639
};
650640

651641
template <typename Config> class MapAllocator {

0 commit comments

Comments
 (0)