[compiler-rt] [scudo] Update secondary cache time-based release logic. (PR #107507)
Joshua Baehring via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 12 12:20:32 PDT 2024
================
@@ -318,9 +318,10 @@ class MapAllocatorCache {
}
CachedBlock PrevEntry = Quarantine[QuarantinePos];
Quarantine[QuarantinePos] = Entry;
- if (OldestTime == 0)
- OldestTime = Entry.Time;
Entry = PrevEntry;
+ // Set entry time once more to reflect time
+ // that quarantined memory was placed in the cache
+ Entry.Time = Time;
----------------
JoshuaMBa wrote:
In the line above, `Entry` is set to `PrevEntry`, so the value we set has been overwritten. When we put an entry in the quarantine, we want its `CachedBlock::Time` field to reflect the time that the entry was placed in the quarantine. Likewise, when we put an entry in `Entries`, we want its `CachedBlock::Time` field to reflect the time that the entry was placed in `Entries` (so that the LRU list remains sorted by the time that its contents were placed in `Entries`).
For example, suppose we are going to store two entries `Entry1` and `Entry2` (and we don't set the `CachedBlock::Time` field a second time). Now consider the following sequence of events:
1. Store `Entry1` when `Time == 1` and `useMemoryTagging<Config>(Options) == true`
2. Set `Entry1.Time = 1` and store `Entry1` in `Quarantine`
3. Store `Entry2` when `Time == 2` and `useMemoryTagging<Config>(Options) == false`
4. Set `Entry2.Time = 2` and store `Entry2` in `Entries`
5. Eventually, `Entry1` comes out of `Quarantine` (say at `Time == 3`) and is placed in `Entries` without overwriting `Entry1.Time`
After this sequence of events, we have that `Entry1` comes before `Entry2` in the LRU list (as it should because `Entry1` was placed in `Entries` more recently than `Entry2`), however, `Entry1.Time == 1 < 2 = Entry2.Time`. Thus, the time values reflect that `Entry2` is more recent that `Entry1` when we really should have set `Entry1.Time = 3` before placing it into `Entries`.
https://github.com/llvm/llvm-project/pull/107507
More information about the llvm-commits
mailing list