[compiler-rt] Reapply "[scudo] Update secondary cache time-based release logic" (PR #110391)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 11 12:56:20 PDT 2024
================
@@ -523,22 +522,37 @@ class MapAllocatorCache {
// Cache should be populated with valid entries when not empty
DCHECK_NE(AvailableHead, CachedBlock::InvalidEntry);
- u32 FreeIndex = AvailableHead;
+ u16 FreeIndex = AvailableHead;
AvailableHead = Entries[AvailableHead].Next;
+ Entries[FreeIndex] = Entry;
- if (EntriesCount == 0) {
- LRUTail = static_cast<u16>(FreeIndex);
+ // Check list order
+ if (EntriesCount > 1)
+ DCHECK_GE(Entries[LRUHead].Time, Entries[Entries[LRUHead].Next].Time);
+
+ // Released entry goes after LastUnreleasedEntry rather than at LRUHead
+ if (Entry.Time == 0 && LastUnreleasedEntry != CachedBlock::InvalidEntry) {
+ Entries[FreeIndex].Next = Entries[LastUnreleasedEntry].Next;
+ Entries[FreeIndex].Prev = LastUnreleasedEntry;
+ Entries[LastUnreleasedEntry].Next = FreeIndex;
+ if (LRUTail == LastUnreleasedEntry) {
+ LRUTail = FreeIndex;
+ } else {
+ Entries[Entries[FreeIndex].Next].Prev = FreeIndex;
+ }
} else {
- // Check list order
- if (EntriesCount > 1)
- DCHECK_GE(Entries[LRUHead].Time, Entries[Entries[LRUHead].Next].Time);
- Entries[LRUHead].Prev = static_cast<u16>(FreeIndex);
+ Entries[FreeIndex].Next = LRUHead;
+ Entries[FreeIndex].Prev = CachedBlock::InvalidEntry;
+ if (EntriesCount == 0) {
+ LRUTail = FreeIndex;
+ } else {
+ Entries[LRUHead].Prev = FreeIndex;
+ }
+ LRUHead = FreeIndex;
+ if (LastUnreleasedEntry == CachedBlock::InvalidEntry)
+ LastUnreleasedEntry = FreeIndex;
}
----------------
ChiaHungDuan wrote:
The logic here seems a little bit too complicated (at least in terms of readability). Can we simplify it as
```
if (Entry.Time == 0) {
if (LastUnreleasedEntry ...) {} else {}
} else {
if (LastUnreleasedEntry ...) {} else {}
}
```
In addition, single line statement of if-else doesn't need brackets
https://github.com/llvm/llvm-project/pull/110391
More information about the llvm-commits
mailing list