[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<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());
</pre>
</details>
https://github.com/llvm/llvm-project/pull/66422
More information about the llvm-commits
mailing list