[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 17:09:24 PDT 2024
https://github.com/JoshuaMBa updated https://github.com/llvm/llvm-project/pull/102984
>From 1a48fb02b2511fd7f49b86ea2a17680a1c1a808b 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 | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/compiler-rt/lib/scudo/standalone/secondary.h b/compiler-rt/lib/scudo/standalone/secondary.h
index e3dc8d4ef8247c..05178a4827cad4 100644
--- a/compiler-rt/lib/scudo/standalone/secondary.h
+++ b/compiler-rt/lib/scudo/standalone/secondary.h
@@ -351,9 +351,13 @@ class MapAllocatorCache {
for (MemMapT &EvictMemMap : EvictionMemMaps)
unmapCallBack(EvictMemMap);
- if (Interval >= 0) {
+ // If a thread already holds the mutex, the current thread can
+ // skip the release logic since the thread holding the mutex
+ // will perform the release anyway
+ if (Interval >= 0 && Mutex.tryLock()) {
// TODO: Add ReleaseToOS logic to LRU algorithm
releaseOlderThan(Time - static_cast<u64>(Interval) * 1000000);
+ Mutex.unlock();
}
}
@@ -455,7 +459,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 +604,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