[compiler-rt] 2aa9977 - [scudo] Reduce the times of holding MapAllocatorCache::Mutex (NFC)

Chia-hung Duan via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 13 10:11:40 PDT 2023


Author: Chia-hung Duan
Date: 2023-03-13T17:09:47Z
New Revision: 2aa99771b626e5ec28bf7652098a5fb78c58881a

URL: https://github.com/llvm/llvm-project/commit/2aa99771b626e5ec28bf7652098a5fb78c58881a
DIFF: https://github.com/llvm/llvm-project/commit/2aa99771b626e5ec28bf7652098a5fb78c58881a.diff

LOG: [scudo] Reduce the times of holding MapAllocatorCache::Mutex (NFC)

Also fix few lints

Reviewed By: cryptoad

Differential Revision: https://reviews.llvm.org/D145427

Added: 
    

Modified: 
    compiler-rt/lib/scudo/standalone/secondary.h

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/scudo/standalone/secondary.h b/compiler-rt/lib/scudo/standalone/secondary.h
index b312887722261..b30f51b9c494d 100644
--- a/compiler-rt/lib/scudo/standalone/secondary.h
+++ b/compiler-rt/lib/scudo/standalone/secondary.h
@@ -256,36 +256,36 @@ template <typename Config> class MapAllocatorCache {
         Found = true;
         Entry = Entries[I];
         Entries[I].CommitBase = 0;
+        EntriesCount--;
         break;
       }
     }
-    if (Found) {
-      *H = reinterpret_cast<LargeBlock::Header *>(
-          LargeBlock::addHeaderTag<Config>(HeaderPos));
-      *Zeroed = Entry.Time == 0;
-      if (useMemoryTagging<Config>(Options))
-        setMemoryPermission(Entry.CommitBase, Entry.CommitSize, 0, &Entry.Data);
-      uptr NewBlockBegin = reinterpret_cast<uptr>(*H + 1);
-      if (useMemoryTagging<Config>(Options)) {
-        if (*Zeroed)
-          storeTags(LargeBlock::addHeaderTag<Config>(Entry.CommitBase),
-                    NewBlockBegin);
-        else if (Entry.BlockBegin < NewBlockBegin)
-          storeTags(Entry.BlockBegin, NewBlockBegin);
-        else
-          storeTags(untagPointer(NewBlockBegin),
-                    untagPointer(Entry.BlockBegin));
-      }
-      (*H)->CommitBase = Entry.CommitBase;
-      (*H)->CommitSize = Entry.CommitSize;
-      (*H)->MapBase = Entry.MapBase;
-      (*H)->MapSize = Entry.MapSize;
-      (*H)->Data = Entry.Data;
+    if (!Found)
+      return false;
 
-      ScopedLock L(Mutex);
-      EntriesCount--;
+    *H = reinterpret_cast<LargeBlock::Header *>(
+        LargeBlock::addHeaderTag<Config>(HeaderPos));
+    *Zeroed = Entry.Time == 0;
+    if (useMemoryTagging<Config>(Options))
+      setMemoryPermission(Entry.CommitBase, Entry.CommitSize, 0, &Entry.Data);
+    uptr NewBlockBegin = reinterpret_cast<uptr>(*H + 1);
+    if (useMemoryTagging<Config>(Options)) {
+      if (*Zeroed) {
+        storeTags(LargeBlock::addHeaderTag<Config>(Entry.CommitBase),
+                  NewBlockBegin);
+      } else if (Entry.BlockBegin < NewBlockBegin) {
+        storeTags(Entry.BlockBegin, NewBlockBegin);
+      } else {
+        storeTags(untagPointer(NewBlockBegin),
+                  untagPointer(Entry.BlockBegin));
+      }
     }
-    return Found;
+    (*H)->CommitBase = Entry.CommitBase;
+    (*H)->CommitSize = Entry.CommitSize;
+    (*H)->MapBase = Entry.MapBase;
+    (*H)->MapSize = Entry.MapSize;
+    (*H)->Data = Entry.Data;
+    return true;
   }
 
   bool canCache(uptr Size) {


        


More information about the llvm-commits mailing list