Skip to content

Commit dc4bf78

Browse files
authored
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
1 parent 331ebb0 commit dc4bf78

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ void *MapAllocator<Config>::allocate(const Options &Options, uptr Size,
594594
ScopedLock L(Mutex);
595595
InUseBlocks.push_back(H);
596596
AllocatedBytes += H->CommitSize;
597-
FragmentedBytes += reinterpret_cast<uptr>(H) - H->CommitBase;
597+
FragmentedBytes += H->MemMap.getCapacity() - H->CommitSize;
598598
NumberOfAllocs++;
599599
Stats.add(StatAllocated, H->CommitSize);
600600
Stats.add(StatMapped, H->MemMap.getCapacity());
@@ -668,7 +668,7 @@ void *MapAllocator<Config>::allocate(const Options &Options, uptr Size,
668668
ScopedLock L(Mutex);
669669
InUseBlocks.push_back(H);
670670
AllocatedBytes += CommitSize;
671-
FragmentedBytes += reinterpret_cast<uptr>(H) - H->CommitBase;
671+
FragmentedBytes += H->MemMap.getCapacity() - CommitSize;
672672
if (LargestSize < CommitSize)
673673
LargestSize = CommitSize;
674674
NumberOfAllocs++;
@@ -687,7 +687,7 @@ void MapAllocator<Config>::deallocate(const Options &Options, void *Ptr)
687687
ScopedLock L(Mutex);
688688
InUseBlocks.remove(H);
689689
FreedBytes += CommitSize;
690-
FragmentedBytes -= reinterpret_cast<uptr>(H) - H->CommitBase;
690+
FragmentedBytes -= H->MemMap.getCapacity() - CommitSize;
691691
NumberOfFrees++;
692692
Stats.sub(StatAllocated, CommitSize);
693693
Stats.sub(StatMapped, H->MemMap.getCapacity());

0 commit comments

Comments
 (0)