@@ -61,12 +61,12 @@ template <typename Config> class SizeClassAllocator64 {
61
61
typedef TransferBatch<ThisT> TransferBatchT;
62
62
typedef BatchGroup<ThisT> BatchGroupT;
63
63
64
- static_assert (sizeof (BatchGroupT) <= sizeof(TransferBatchT),
65
- "BatchGroupT uses the same class size as TransferBatchT");
66
-
64
+ // BachClass is used to store internal metadata so it needs to be at least as
65
+ // large as the largest data structure.
67
66
static uptr getSizeByClassId (uptr ClassId) {
68
67
return (ClassId == SizeClassMap::BatchClassId)
69
- ? roundUp (sizeof (TransferBatchT), 1U << CompactPtrScale)
68
+ ? roundUp (Max (sizeof (TransferBatchT), sizeof (BatchGroupT)),
69
+ 1U << CompactPtrScale)
70
70
: SizeClassMap::getSizeByClassId (ClassId);
71
71
}
72
72
@@ -236,7 +236,7 @@ template <typename Config> class SizeClassAllocator64 {
236
236
} else {
237
237
while (true ) {
238
238
// When two threads compete for `Region->MMLock`, we only want one of
239
- // them to call populateFreeListAndPopBatch (). To avoid both of them
239
+ // them to call populateFreeListAndPopBlocks (). To avoid both of them
240
240
// doing that, always check the freelist before mapping new pages.
241
241
ScopedLock ML (Region->MMLock );
242
242
{
@@ -690,9 +690,6 @@ template <typename Config> class SizeClassAllocator64 {
690
690
// BatchClass hasn't enabled memory group. Use `0` to indicate there's no
691
691
// memory group here.
692
692
BG->CompactPtrGroupBase = 0 ;
693
- // `BG` is also the block of BatchClassId. Note that this is different
694
- // from `CreateGroup` in `pushBlocksImpl`
695
- BG->PushedBlocks = 1 ;
696
693
BG->BytesInBGAtLastCheckpoint = 0 ;
697
694
BG->MaxCachedPerBatch =
698
695
CacheT::getMaxCached (getSizeByClassId (SizeClassMap::BatchClassId));
@@ -717,9 +714,6 @@ template <typename Config> class SizeClassAllocator64 {
717
714
TB->add (
718
715
compactPtr (SizeClassMap::BatchClassId, reinterpret_cast <uptr>(BG)));
719
716
--Size;
720
- DCHECK_EQ (BG->PushedBlocks , 1U );
721
- // `TB` is also the block of BatchClassId.
722
- BG->PushedBlocks += 1 ;
723
717
BG->Batches .push_front (TB);
724
718
}
725
719
@@ -746,8 +740,6 @@ template <typename Config> class SizeClassAllocator64 {
746
740
CurBatch->appendFromArray (&Array[I], AppendSize);
747
741
I += AppendSize;
748
742
}
749
-
750
- BG->PushedBlocks += Size;
751
743
}
752
744
753
745
// Push the blocks to their batch group. The layout will be like,
@@ -782,7 +774,6 @@ template <typename Config> class SizeClassAllocator64 {
782
774
783
775
BG->CompactPtrGroupBase = CompactPtrGroupBase;
784
776
BG->Batches .push_front (TB);
785
- BG->PushedBlocks = 0 ;
786
777
BG->BytesInBGAtLastCheckpoint = 0 ;
787
778
BG->MaxCachedPerBatch = TransferBatchT::MaxNumCached;
788
779
@@ -810,8 +801,6 @@ template <typename Config> class SizeClassAllocator64 {
810
801
CurBatch->appendFromArray (&Array[I], AppendSize);
811
802
I += AppendSize;
812
803
}
813
-
814
- BG->PushedBlocks += Size;
815
804
};
816
805
817
806
Region->FreeListInfo .PushedBlocks += Size;
@@ -884,7 +873,7 @@ template <typename Config> class SizeClassAllocator64 {
884
873
while (true ) {
885
874
// We only expect one thread doing the freelist refillment and other
886
875
// threads will be waiting for either the completion of the
887
- // `populateFreeListAndPopBatch ()` or `pushBlocks()` called by other
876
+ // `populateFreeListAndPopBlocks ()` or `pushBlocks()` called by other
888
877
// threads.
889
878
bool PopulateFreeList = false ;
890
879
{
@@ -922,7 +911,7 @@ template <typename Config> class SizeClassAllocator64 {
922
911
// At here, there are two preconditions to be met before waiting,
923
912
// 1. The freelist is empty.
924
913
// 2. Region->isPopulatingFreeList == true, i.e, someone is still doing
925
- // `populateFreeListAndPopBatch ()`.
914
+ // `populateFreeListAndPopBlocks ()`.
926
915
//
927
916
// Note that it has the chance that freelist is empty but
928
917
// Region->isPopulatingFreeList == false because all the new populated
@@ -938,8 +927,8 @@ template <typename Config> class SizeClassAllocator64 {
938
927
939
928
// Now the freelist is empty and someone's doing the refillment. We will
940
929
// wait until anyone refills the freelist or someone finishes doing
941
- // `populateFreeListAndPopBatch ()`. The refillment can be done by
942
- // `populateFreeListAndPopBatch ()`, `pushBlocks()`,
930
+ // `populateFreeListAndPopBlocks ()`. The refillment can be done by
931
+ // `populateFreeListAndPopBlocks ()`, `pushBlocks()`,
943
932
// `pushBatchClassBlocks()` and `mergeGroupsToReleaseBack()`.
944
933
Region->FLLockCV .wait (Region->FLLock );
945
934
@@ -1119,8 +1108,8 @@ template <typename Config> class SizeClassAllocator64 {
1119
1108
1120
1109
// Note that `PushedBlocks` and `PoppedBlocks` are supposed to only record
1121
1110
// the requests from `PushBlocks` and `PopBatch` which are external
1122
- // interfaces. `populateFreeListAndPopBatch ` is the internal interface so we
1123
- // should set the values back to avoid incorrectly setting the stats.
1111
+ // interfaces. `populateFreeListAndPopBlocks ` is the internal interface so
1112
+ // we should set the values back to avoid incorrectly setting the stats.
1124
1113
Region->FreeListInfo .PushedBlocks -= NumberOfBlocks;
1125
1114
1126
1115
const uptr AllocatedUser = Size * NumberOfBlocks;
@@ -1689,7 +1678,6 @@ template <typename Config> class SizeClassAllocator64 {
1689
1678
GroupsToRelease.pop_front ();
1690
1679
1691
1680
if (BG->CompactPtrGroupBase == Cur->CompactPtrGroupBase ) {
1692
- BG->PushedBlocks += Cur->PushedBlocks ;
1693
1681
// We have updated `BatchGroup::BytesInBGAtLastCheckpoint` while
1694
1682
// collecting the `GroupsToRelease`.
1695
1683
BG->BytesInBGAtLastCheckpoint = Cur->BytesInBGAtLastCheckpoint ;
0 commit comments