[compiler-rt] 18207db - [scudo] update Pushedblocks/PoppedBlocks in Impl functions
Chia-hung Duan via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 23 11:53:48 PDT 2023
Author: Chia-hung Duan
Date: 2023-06-23T18:53:22Z
New Revision: 18207dbc3a614542906be4f7a7a69b2fb6f448f7
URL: https://github.com/llvm/llvm-project/commit/18207dbc3a614542906be4f7a7a69b2fb6f448f7
DIFF: https://github.com/llvm/llvm-project/commit/18207dbc3a614542906be4f7a7a69b2fb6f448f7.diff
LOG: [scudo] update Pushedblocks/PoppedBlocks in Impl functions
Reviewed By: cferris
Differential Revision: https://reviews.llvm.org/D152420
Added:
Modified:
compiler-rt/lib/scudo/standalone/primary32.h
compiler-rt/lib/scudo/standalone/primary64.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/scudo/standalone/primary32.h b/compiler-rt/lib/scudo/standalone/primary32.h
index 2ef26a55bf7c6..e99de23f8281e 100644
--- a/compiler-rt/lib/scudo/standalone/primary32.h
+++ b/compiler-rt/lib/scudo/standalone/primary32.h
@@ -154,7 +154,6 @@ template <typename Config> class SizeClassAllocator32 {
// if `populateFreeList` succeeded, we are supposed to get free blocks.
DCHECK_NE(B, nullptr);
}
- Sci->FreeListInfo.PoppedBlocks += B->getCount();
return B;
}
@@ -175,7 +174,6 @@ template <typename Config> class SizeClassAllocator32 {
if (Size == 1 && !populateFreeList(C, ClassId, Sci))
return;
pushBlocksImpl(C, ClassId, Sci, Array, Size);
- Sci->FreeListInfo.PushedBlocks += Size;
return;
}
@@ -201,7 +199,6 @@ template <typename Config> class SizeClassAllocator32 {
ScopedLock L(Sci->Mutex);
pushBlocksImpl(C, ClassId, Sci, Array, Size, SameGroup);
- Sci->FreeListInfo.PushedBlocks += Size;
if (ClassId != SizeClassMap::BatchClassId)
releaseToOSMaybe(Sci, ClassId);
}
@@ -533,6 +530,7 @@ template <typename Config> class SizeClassAllocator32 {
BG->PushedBlocks += Size;
};
+ Sci->FreeListInfo.PushedBlocks += Size;
BatchGroup *Cur = Sci->FreeListInfo.BlockList.front();
if (ClassId == SizeClassMap::BatchClassId) {
@@ -635,6 +633,7 @@ template <typename Config> class SizeClassAllocator32 {
C->deallocate(SizeClassMap::BatchClassId, BG);
}
+ Sci->FreeListInfo.PoppedBlocks += B->getCount();
return B;
}
@@ -708,6 +707,12 @@ template <typename Config> class SizeClassAllocator32 {
/*SameGroup=*/true);
}
+ // Note that `PushedBlocks` and `PoppedBlocks` are supposed to only record
+ // the requests from `PushBlocks` and `PopBatch` which are external
+ // interfaces. `populateFreeList` is the internal interface so we should set
+ // the values back to avoid incorrectly setting the stats.
+ Sci->FreeListInfo.PushedBlocks -= NumberOfBlocks;
+
const uptr AllocatedUser = Size * NumberOfBlocks;
C->getStats().add(StatFree, AllocatedUser);
DCHECK_LE(Sci->CurrentRegionAllocated + AllocatedUser, RegionSize);
diff --git a/compiler-rt/lib/scudo/standalone/primary64.h b/compiler-rt/lib/scudo/standalone/primary64.h
index d01d31b0f8768..3d9aeed55e5ae 100644
--- a/compiler-rt/lib/scudo/standalone/primary64.h
+++ b/compiler-rt/lib/scudo/standalone/primary64.h
@@ -155,10 +155,8 @@ template <typename Config> class SizeClassAllocator64 {
{
ScopedLock L(Region->FLLock);
TransferBatch *B = popBatchImpl(C, ClassId, Region);
- if (LIKELY(B)) {
- Region->FreeListInfo.PoppedBlocks += B->getCount();
+ if (LIKELY(B))
return B;
- }
}
bool PrintStats = false;
@@ -174,10 +172,8 @@ template <typename Config> class SizeClassAllocator64 {
{
ScopedLock FL(Region->FLLock);
TransferBatch *B = popBatchImpl(C, ClassId, Region);
- if (LIKELY(B)) {
- Region->FreeListInfo.PoppedBlocks += B->getCount();
+ if (LIKELY(B))
return B;
- }
}
const bool RegionIsExhausted = Region->Exhausted;
@@ -229,7 +225,6 @@ template <typename Config> class SizeClassAllocator64 {
Size == 1U && Region->FreeListInfo.BlockList.empty();
if (!NeedToRefill) {
pushBlocksImpl(C, SizeClassMap::BatchClassId, Region, Array, Size);
- Region->FreeListInfo.PushedBlocks += Size;
return;
}
}
@@ -274,7 +269,6 @@ template <typename Config> class SizeClassAllocator64 {
{
ScopedLock L(Region->FLLock);
pushBlocksImpl(C, ClassId, Region, Array, Size, SameGroup);
- Region->FreeListInfo.PushedBlocks += Size;
}
// Only non-BatchClass will be here, try to release the pages in the region.
@@ -677,6 +671,7 @@ template <typename Config> class SizeClassAllocator64 {
BG->PushedBlocks += Size;
};
+ Region->FreeListInfo.PushedBlocks += Size;
BatchGroup *Cur = Region->FreeListInfo.BlockList.front();
if (ClassId == SizeClassMap::BatchClassId) {
@@ -779,6 +774,8 @@ template <typename Config> class SizeClassAllocator64 {
C->deallocate(SizeClassMap::BatchClassId, BG);
}
+ Region->FreeListInfo.PoppedBlocks += B->getCount();
+
return B;
}
@@ -861,6 +858,12 @@ template <typename Config> class SizeClassAllocator64 {
/*SameGroup=*/true);
}
+ // Note that `PushedBlocks` and `PoppedBlocks` are supposed to only record
+ // the requests from `PushBlocks` and `PopBatch` which are external
+ // interfaces. `populateFreeListAndPopBatch` is the internal interface so we
+ // should set the values back to avoid incorrectly setting the stats.
+ Region->FreeListInfo.PushedBlocks -= NumberOfBlocks;
+
const uptr AllocatedUser = Size * NumberOfBlocks;
C->getStats().add(StatFree, AllocatedUser);
Region->MemMapInfo.AllocatedUser += AllocatedUser;
More information about the llvm-commits
mailing list