[compiler-rt] [scudo] Reduce thread contention in secondary cache releases. (PR #102984)
Joshua Baehring via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 12 16:31:39 PDT 2024
https://github.com/JoshuaMBa created https://github.com/llvm/llvm-project/pull/102984
Threads will skip the releaseOlderThan() call if another thread holds the secondary cache lock because the other thread holding the lock can release the old cache entries instead. This way threads will not be backed up waiting to acquire the cache lock while another thread is already performing the necessary releases.
>From 9d515cc802e39e89a091eb6771e1cb0a544506ff Mon Sep 17 00:00:00 2001
From: Joshua Baehring <jmbaehring at google.com>
Date: Mon, 12 Aug 2024 23:27:13 +0000
Subject: [PATCH] [scudo] Reduce thread contention in secondary cache releases.
Threads will skip the releaseOlderThan() call if another thread holds
the secondary cache lock because the other thread holding the
lock can release the old cache entries instead. This way threads will
not be backed up waiting to acquire the cache lock while another thread
is already performing the necessary releases.
---
compiler-rt/lib/scudo/standalone/secondary.h | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/compiler-rt/lib/scudo/standalone/secondary.h b/compiler-rt/lib/scudo/standalone/secondary.h
index e3dc8d4ef8247c..39610a8be2c428 100644
--- a/compiler-rt/lib/scudo/standalone/secondary.h
+++ b/compiler-rt/lib/scudo/standalone/secondary.h
@@ -351,9 +351,10 @@ class MapAllocatorCache {
for (MemMapT &EvictMemMap : EvictionMemMaps)
unmapCallBack(EvictMemMap);
- if (Interval >= 0) {
+ if (Interval >= 0 && Mutex.tryLock()) {
// TODO: Add ReleaseToOS logic to LRU algorithm
releaseOlderThan(Time - static_cast<u64>(Interval) * 1000000);
+ Mutex.unlock();
}
}
@@ -455,7 +456,10 @@ class MapAllocatorCache {
return true;
}
- void releaseToOS() { releaseOlderThan(UINT64_MAX); }
+ void releaseToOS() {
+ ScopedLock L(Mutex);
+ releaseOlderThan(UINT64_MAX);
+ }
void disableMemoryTagging() EXCLUDES(Mutex) {
ScopedLock L(Mutex);
@@ -597,8 +601,7 @@ class MapAllocatorCache {
Entry.Time = 0;
}
- void releaseOlderThan(u64 Time) EXCLUDES(Mutex) {
- ScopedLock L(Mutex);
+ void releaseOlderThan(u64 Time) REQUIRES(Mutex) {
if (!EntriesCount || OldestTime == 0 || OldestTime > Time)
return;
OldestTime = 0;
More information about the llvm-commits
mailing list