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

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 14 12:30:33 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-compiler-rt-sanitizer
            
<details>
<summary>Changes</summary>
The fragmentation of secondary cache is the difference between mapped page size and the user request size
--
Full diff: https://github.com/llvm/llvm-project/pull/66422.diff

1 Files Affected:

- (modified) compiler-rt/lib/scudo/standalone/secondary.h (+3-3) 


<pre>
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&lt;Config&gt;::allocate(const Options &amp;Options, uptr Size,
         ScopedLock L(Mutex);
         InUseBlocks.push_back(H);
         AllocatedBytes += H-&gt;CommitSize;
-        FragmentedBytes += reinterpret_cast&lt;uptr&gt;(H) - H-&gt;CommitBase;
+        FragmentedBytes += H-&gt;MemMap.getCapacity() - H-&gt;CommitSize;
         NumberOfAllocs++;
         Stats.add(StatAllocated, H-&gt;CommitSize);
         Stats.add(StatMapped, H-&gt;MemMap.getCapacity());
@@ -668,7 +668,7 @@ void *MapAllocator&lt;Config&gt;::allocate(const Options &amp;Options, uptr Size,
     ScopedLock L(Mutex);
     InUseBlocks.push_back(H);
     AllocatedBytes += CommitSize;
-    FragmentedBytes += reinterpret_cast&lt;uptr&gt;(H) - H-&gt;CommitBase;
+    FragmentedBytes += H-&gt;MemMap.getCapacity() - CommitSize;
     if (LargestSize &lt; CommitSize)
       LargestSize = CommitSize;
     NumberOfAllocs++;
@@ -687,7 +687,7 @@ void MapAllocator&lt;Config&gt;::deallocate(const Options &amp;Options, void *Ptr)
     ScopedLock L(Mutex);
     InUseBlocks.remove(H);
     FreedBytes += CommitSize;
-    FragmentedBytes -= reinterpret_cast&lt;uptr&gt;(H) - H-&gt;CommitBase;
+    FragmentedBytes -= H-&gt;MemMap.getCapacity() - CommitSize;
     NumberOfFrees++;
     Stats.sub(StatAllocated, CommitSize);
     Stats.sub(StatMapped, H-&gt;MemMap.getCapacity());
</pre>
</details>


https://github.com/llvm/llvm-project/pull/66422


More information about the llvm-commits mailing list