[compiler-rt] dc4bf78 - Fix the calculation of fragmented bytes in secondary (#66422)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 14 15:24:58 PDT 2023


Author: ChiaHungDuan
Date: 2023-09-14T15:24:54-07:00
New Revision: dc4bf78e4ebb57206c9bca5934a3deaeba76c2d2

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

LOG: Fix the calculation of fragmented bytes in secondary (#66422)

The fragmentation of secondary cache is the difference between mapped
page size and the user request size

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 01a4108a75f368b..d0890d1c5e2d3d5 100644
--- a/compiler-rt/lib/scudo/standalone/secondary.h
+++ b/compiler-rt/lib/scudo/standalone/secondary.h
@@ -594,7 +594,7 @@ void *MapAllocator<Config>::allocate(const Options &Options, uptr Size,
         ScopedLock L(Mutex);
         InUseBlocks.push_back(H);
         AllocatedBytes += H->CommitSize;
-        FragmentedBytes += reinterpret_cast<uptr>(H) - H->CommitBase;
+        FragmentedBytes += H->MemMap.getCapacity() - H->CommitSize;
         NumberOfAllocs++;
         Stats.add(StatAllocated, H->CommitSize);
         Stats.add(StatMapped, H->MemMap.getCapacity());
@@ -668,7 +668,7 @@ void *MapAllocator<Config>::allocate(const Options &Options, uptr Size,
     ScopedLock L(Mutex);
     InUseBlocks.push_back(H);
     AllocatedBytes += CommitSize;
-    FragmentedBytes += reinterpret_cast<uptr>(H) - H->CommitBase;
+    FragmentedBytes += H->MemMap.getCapacity() - CommitSize;
     if (LargestSize < CommitSize)
       LargestSize = CommitSize;
     NumberOfAllocs++;
@@ -687,7 +687,7 @@ void MapAllocator<Config>::deallocate(const Options &Options, void *Ptr)
     ScopedLock L(Mutex);
     InUseBlocks.remove(H);
     FreedBytes += CommitSize;
-    FragmentedBytes -= reinterpret_cast<uptr>(H) - H->CommitBase;
+    FragmentedBytes -= H->MemMap.getCapacity() - CommitSize;
     NumberOfFrees++;
     Stats.sub(StatAllocated, CommitSize);
     Stats.sub(StatMapped, H->MemMap.getCapacity());


        


More information about the llvm-commits mailing list