[compiler-rt] 526027d - [scudo] Change secondary StatsAllocated update

Christopher Ferris via llvm-commits llvm-commits at lists.llvm.org
Tue May 9 15:41:12 PDT 2023


Author: Christopher Ferris
Date: 2023-05-09T15:40:57-07:00
New Revision: 526027df2d62432db3cfce3a61356369ed13cf5e

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

LOG: [scudo] Change secondary StatsAllocated update

In the secondary allocation routine, the StatsAllocated stat is
increased by BlockSize. However, in the deallocate routine, the
stat subtract uses CommitSize. CommitSize can be bigger than BlockSize
so this can lead to a negative calculated stat. Since the stats
are not guaranteed to be completely accurate, just add CommitSize
during allocation.

Reviewed By: Chia-hungDuan

Differential Revision: https://reviews.llvm.org/D150169

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 935b48914d00c..94009f5fa9c65 100644
--- a/compiler-rt/lib/scudo/standalone/secondary.h
+++ b/compiler-rt/lib/scudo/standalone/secondary.h
@@ -522,13 +522,12 @@ void *MapAllocator<Config>::allocate(Options Options, uptr Size, uptr Alignment,
       if (FillContents && !Zeroed)
         memset(Ptr, FillContents == ZeroFill ? 0 : PatternFillByte,
                BlockEnd - PtrInt);
-      const uptr BlockSize = BlockEnd - HInt;
       {
         ScopedLock L(Mutex);
         InUseBlocks.push_back(H);
-        AllocatedBytes += BlockSize;
+        AllocatedBytes += H->CommitSize;
         NumberOfAllocs++;
-        Stats.add(StatAllocated, BlockSize);
+        Stats.add(StatAllocated, H->CommitSize);
         Stats.add(StatMapped, H->MemMap.getCapacity());
       }
       return Ptr;


        


More information about the llvm-commits mailing list