@@ -61,12 +61,12 @@ template <typename Config> class SizeClassAllocator64 {
6161 typedef TransferBatch<ThisT> TransferBatchT;
6262 typedef BatchGroup<ThisT> BatchGroupT;
6363
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.
6766 static uptr getSizeByClassId (uptr ClassId) {
6867 return (ClassId == SizeClassMap::BatchClassId)
69- ? roundUp (sizeof (TransferBatchT), 1U << CompactPtrScale)
68+ ? roundUp (Max (sizeof (TransferBatchT), sizeof (BatchGroupT)),
69+ 1U << CompactPtrScale)
7070 : SizeClassMap::getSizeByClassId (ClassId);
7171 }
7272
@@ -236,7 +236,7 @@ template <typename Config> class SizeClassAllocator64 {
236236 } else {
237237 while (true ) {
238238 // 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
240240 // doing that, always check the freelist before mapping new pages.
241241 ScopedLock ML (Region->MMLock );
242242 {
@@ -690,9 +690,6 @@ template <typename Config> class SizeClassAllocator64 {
690690 // BatchClass hasn't enabled memory group. Use `0` to indicate there's no
691691 // memory group here.
692692 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 ;
696693 BG->BytesInBGAtLastCheckpoint = 0 ;
697694 BG->MaxCachedPerBatch =
698695 CacheT::getMaxCached (getSizeByClassId (SizeClassMap::BatchClassId));
@@ -717,9 +714,6 @@ template <typename Config> class SizeClassAllocator64 {
717714 TB->add (
718715 compactPtr (SizeClassMap::BatchClassId, reinterpret_cast <uptr>(BG)));
719716 --Size;
720- DCHECK_EQ (BG->PushedBlocks , 1U );
721- // `TB` is also the block of BatchClassId.
722- BG->PushedBlocks += 1 ;
723717 BG->Batches .push_front (TB);
724718 }
725719
@@ -746,8 +740,6 @@ template <typename Config> class SizeClassAllocator64 {
746740 CurBatch->appendFromArray (&Array[I], AppendSize);
747741 I += AppendSize;
748742 }
749-
750- BG->PushedBlocks += Size;
751743 }
752744
753745 // Push the blocks to their batch group. The layout will be like,
@@ -782,7 +774,6 @@ template <typename Config> class SizeClassAllocator64 {
782774
783775 BG->CompactPtrGroupBase = CompactPtrGroupBase;
784776 BG->Batches .push_front (TB);
785- BG->PushedBlocks = 0 ;
786777 BG->BytesInBGAtLastCheckpoint = 0 ;
787778 BG->MaxCachedPerBatch = TransferBatchT::MaxNumCached;
788779
@@ -810,8 +801,6 @@ template <typename Config> class SizeClassAllocator64 {
810801 CurBatch->appendFromArray (&Array[I], AppendSize);
811802 I += AppendSize;
812803 }
813-
814- BG->PushedBlocks += Size;
815804 };
816805
817806 Region->FreeListInfo .PushedBlocks += Size;
@@ -884,7 +873,7 @@ template <typename Config> class SizeClassAllocator64 {
884873 while (true ) {
885874 // We only expect one thread doing the freelist refillment and other
886875 // threads will be waiting for either the completion of the
887- // `populateFreeListAndPopBatch ()` or `pushBlocks()` called by other
876+ // `populateFreeListAndPopBlocks ()` or `pushBlocks()` called by other
888877 // threads.
889878 bool PopulateFreeList = false ;
890879 {
@@ -922,7 +911,7 @@ template <typename Config> class SizeClassAllocator64 {
922911 // At here, there are two preconditions to be met before waiting,
923912 // 1. The freelist is empty.
924913 // 2. Region->isPopulatingFreeList == true, i.e, someone is still doing
925- // `populateFreeListAndPopBatch ()`.
914+ // `populateFreeListAndPopBlocks ()`.
926915 //
927916 // Note that it has the chance that freelist is empty but
928917 // Region->isPopulatingFreeList == false because all the new populated
@@ -938,8 +927,8 @@ template <typename Config> class SizeClassAllocator64 {
938927
939928 // Now the freelist is empty and someone's doing the refillment. We will
940929 // 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()`,
943932 // `pushBatchClassBlocks()` and `mergeGroupsToReleaseBack()`.
944933 Region->FLLockCV .wait (Region->FLLock );
945934
@@ -1119,8 +1108,8 @@ template <typename Config> class SizeClassAllocator64 {
11191108
11201109 // Note that `PushedBlocks` and `PoppedBlocks` are supposed to only record
11211110 // 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.
11241113 Region->FreeListInfo .PushedBlocks -= NumberOfBlocks;
11251114
11261115 const uptr AllocatedUser = Size * NumberOfBlocks;
@@ -1689,7 +1678,6 @@ template <typename Config> class SizeClassAllocator64 {
16891678 GroupsToRelease.pop_front ();
16901679
16911680 if (BG->CompactPtrGroupBase == Cur->CompactPtrGroupBase ) {
1692- BG->PushedBlocks += Cur->PushedBlocks ;
16931681 // We have updated `BatchGroup::BytesInBGAtLastCheckpoint` while
16941682 // collecting the `GroupsToRelease`.
16951683 BG->BytesInBGAtLastCheckpoint = Cur->BytesInBGAtLastCheckpoint ;
0 commit comments