[compiler-rt] [scudo] Mitigate the overhead in cache storing when MTE enabled (PR #66717)

via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 18 15:43:41 PDT 2023


https://github.com/ChiaHungDuan created https://github.com/llvm/llvm-project/pull/66717

mapSecondary() requires two mmap calls and may impact the performance in some cases that use secondary allocator heavily. Only use setMemoryPermission to reduce the time in contention of memory system calls.

>From e425a559525d945f150c6b2390893694d19ff560 Mon Sep 17 00:00:00 2001
From: Chia-hung Duan <chiahungduan at google.com>
Date: Mon, 18 Sep 2023 22:34:42 +0000
Subject: [PATCH] [scudo] Mitigate the overhead in cache storing when MTE
 enabled

mapSecondary() requires two mmap calls and may impact the performance in
some cases that use secondary allocator heavily. Only use
setMemoryPermission to reduce the time in contention of memory system calls.
---
 compiler-rt/lib/scudo/standalone/secondary.h | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/compiler-rt/lib/scudo/standalone/secondary.h b/compiler-rt/lib/scudo/standalone/secondary.h
index d0890d1c5e2d3d5..c4192bfd45bba2e 100644
--- a/compiler-rt/lib/scudo/standalone/secondary.h
+++ b/compiler-rt/lib/scudo/standalone/secondary.h
@@ -210,18 +210,10 @@ template <typename Config> class MapAllocatorCache {
     Entry.MemMap = H->MemMap;
     Entry.Time = Time;
     if (useMemoryTagging<Config>(Options)) {
-      if (Interval == 0 && !SCUDO_FUCHSIA) {
-        // Release the memory and make it inaccessible at the same time by
-        // creating a new MAP_NOACCESS mapping on top of the existing mapping.
-        // Fuchsia does not support replacing mappings by creating a new mapping
-        // on top so we just do the two syscalls there.
+      if (Interval == 0)
         Entry.Time = 0;
-        mapSecondary<Config>(Options, Entry.CommitBase, Entry.CommitSize,
-                             Entry.CommitBase, MAP_NOACCESS, Entry.MemMap);
-      } else {
-        Entry.MemMap.setMemoryPermission(Entry.CommitBase, Entry.CommitSize,
-                                         MAP_NOACCESS);
-      }
+      Entry.MemMap.setMemoryPermission(Entry.CommitBase, Entry.CommitSize,
+                                       MAP_NOACCESS);
     } else if (Interval == 0) {
       Entry.MemMap.releasePagesToOS(Entry.CommitBase, Entry.CommitSize);
       Entry.Time = 0;



More information about the llvm-commits mailing list