mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-02 18:58:15 +00:00
[scudo] Pass the max number of blocks to popBlocks (#70243)
Make the cache have the fully control on how many blocks to be popped (At before, it depended the number of blocks stored in the TransferBatch)
This commit is contained in:
parent
ec456ba9ca
commit
4e8d6c4f82
@ -40,7 +40,11 @@ template <class SizeClassAllocator> struct SizeClassAllocatorLocalCache {
|
||||
DCHECK_LT(ClassId, NumClasses);
|
||||
PerClass *C = &PerClassArray[ClassId];
|
||||
if (C->Count == 0) {
|
||||
if (UNLIKELY(!refill(C, ClassId)))
|
||||
initCacheMaybe(C);
|
||||
|
||||
// Refill half of the number of max cached.
|
||||
DCHECK_GT(C->MaxCount / 2, 0U);
|
||||
if (UNLIKELY(!refill(C, ClassId, C->MaxCount / 2)))
|
||||
return nullptr;
|
||||
DCHECK_GT(C->Count, 0);
|
||||
}
|
||||
@ -173,14 +177,10 @@ private:
|
||||
deallocate(BatchClassId, B);
|
||||
}
|
||||
|
||||
NOINLINE bool refill(PerClass *C, uptr ClassId) {
|
||||
initCacheMaybe(C);
|
||||
|
||||
// TODO(chiahungduan): Pass the max number cached for each size class.
|
||||
NOINLINE bool refill(PerClass *C, uptr ClassId, u16 MaxRefill) {
|
||||
const u16 NumBlocksRefilled =
|
||||
Allocator->popBlocks(this, ClassId, C->Chunks);
|
||||
DCHECK_LE(NumBlocksRefilled,
|
||||
getMaxCached(SizeClassAllocator::getSizeByClassId(ClassId)));
|
||||
Allocator->popBlocks(this, ClassId, C->Chunks, MaxRefill);
|
||||
DCHECK_LE(NumBlocksRefilled, MaxRefill);
|
||||
C->Count = static_cast<u16>(C->Count + NumBlocksRefilled);
|
||||
return NumBlocksRefilled != 0;
|
||||
}
|
||||
|
@ -191,7 +191,11 @@ public:
|
||||
return BlockSize > PageSize;
|
||||
}
|
||||
|
||||
u16 popBlocks(CacheT *C, uptr ClassId, CompactPtrT *ToArray) {
|
||||
// Note that the `MaxBlockCount` will be used when we support arbitrary blocks
|
||||
// count. Now it's the same as the number of blocks stored in the
|
||||
// `TransferBatch`.
|
||||
u16 popBlocks(CacheT *C, uptr ClassId, CompactPtrT *ToArray,
|
||||
UNUSED const u16 MaxBlockCount) {
|
||||
TransferBatchT *B = popBatch(C, ClassId);
|
||||
if (!B)
|
||||
return 0;
|
||||
|
@ -221,7 +221,11 @@ public:
|
||||
DCHECK_EQ(BlocksInUse, BatchClassUsedInFreeLists);
|
||||
}
|
||||
|
||||
u16 popBlocks(CacheT *C, uptr ClassId, CompactPtrT *ToArray) {
|
||||
// Note that the `MaxBlockCount` will be used when we support arbitrary blocks
|
||||
// count. Now it's the same as the number of blocks stored in the
|
||||
// `TransferBatch`.
|
||||
u16 popBlocks(CacheT *C, uptr ClassId, CompactPtrT *ToArray,
|
||||
UNUSED const u16 MaxBlockCount) {
|
||||
TransferBatchT *B = popBatch(C, ClassId);
|
||||
if (!B)
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user