@@ -321,12 +321,23 @@ const size_t minSharedAllocDelay = 128;
321321
322322SatoriObject* SatoriAllocator::AllocRegular (SatoriAllocationContext* context, size_t size, uint32_t flags)
323323{
324+ // when allocations cross certain thresholds, check if GC should start or help is needed.
325+ size_t curAlloc = context->alloc_bytes + context->alloc_bytes_uoh ;
326+ size_t expectedAlloc = max (size, SatoriUtil::MinZeroInitSize ());
327+ size_t change = (curAlloc ^ (curAlloc + expectedAlloc));
328+ if (curAlloc == 0 || change >= Satori::REGION_SIZE_GRANULARITY)
329+ {
330+ m_heap->Recycler ()->MaybeTriggerGC (gc_reason::reason_alloc_soh);
331+ }
332+ else if (change >= Satori::PACE_BUDGET)
333+ {
334+ m_heap->Recycler ()->HelpOnce ();
335+ }
324336
325337// tryAgain:
338+
326339 if (!context->RegularRegion ())
327340 {
328- m_heap->Recycler ()->MaybeTriggerGC (gc_reason::reason_alloc_soh);
329-
330341 SatoriObject* freeObj = context->alloc_ptr != 0 ? context->FinishAllocFromShared () : nullptr ;
331342
332343 size_t usecNow = m_heap->Recycler ()->GetNowUsecs ();
@@ -348,18 +359,6 @@ SatoriObject* SatoriAllocator::AllocRegular(SatoriAllocationContext* context, si
348359 }
349360 }
350361 }
351- else
352- {
353- size_t expectedAlloc = max (size, SatoriUtil::MinZeroInitSize ());
354- if ((context->alloc_bytes ^ (context->alloc_bytes + expectedAlloc)) >= Satori::REGION_SIZE_GRANULARITY)
355- {
356- m_heap->Recycler ()->MaybeTriggerGC (gc_reason::reason_alloc_soh);
357- }
358- else
359- {
360- m_heap->Recycler ()->HelpOnce ();
361- }
362- }
363362
364363 SatoriRegion* region = context->RegularRegion ();
365364 _ASSERTE (region == nullptr || region->IsAttachedToAllocatingOwner ());
@@ -678,29 +677,31 @@ SatoriObject* SatoriAllocator::AllocLarge(SatoriAllocationContext* context, size
678677 return AllocHuge (context, size, flags);
679678 }
680679
680+ // when allocations cross certain thresholds, check if GC should start or help is needed.
681+ // when allocations cross certain thresholds, check if GC should start or help is needed.
682+ size_t curAlloc = context->alloc_bytes + context->alloc_bytes_uoh ;
683+ size_t expectedAlloc = size;
684+ size_t change = (curAlloc ^ (curAlloc + expectedAlloc));
685+ if (curAlloc == 0 || change >= Satori::REGION_SIZE_GRANULARITY)
686+ {
687+ m_heap->Recycler ()->MaybeTriggerGC (gc_reason::reason_alloc_soh);
688+ }
689+ else if (change >= Satori::PACE_BUDGET)
690+ {
691+ m_heap->Recycler ()->HelpOnce ();
692+ }
693+
681694tryAgain:
695+
682696 if (!context->LargeRegion () &&
683697 size < Satori::REGION_SIZE_GRANULARITY / 2 )
684698 {
685- m_heap->Recycler ()->MaybeTriggerGC (gc_reason::reason_alloc_loh);
686-
687699 // m_largeAllocLock.Enter();
688700 if (m_largeAllocLock.TryEnter ())
689701 {
690702 return AllocLargeShared (context, size, flags);
691703 }
692704 }
693- else
694- {
695- if ((context->alloc_bytes_uoh ^ (context->alloc_bytes_uoh + size)) >= Satori::REGION_SIZE_GRANULARITY)
696- {
697- m_heap->Recycler ()->MaybeTriggerGC (gc_reason::reason_alloc_soh);
698- }
699- else
700- {
701- m_heap->Recycler ()->HelpOnce ();
702- }
703- }
704705
705706 SatoriRegion* region = context->LargeRegion ();
706707 while (true )
@@ -941,14 +942,25 @@ SatoriObject* SatoriAllocator::AllocPinned(SatoriAllocationContext* context, siz
941942 return AllocHuge (context, size, flags);
942943 }
943944
944- m_heap->Recycler ()->MaybeTriggerGC (gc_reason::reason_alloc_soh);
945-
946945 // if can't get a lock, let AllocLarge handle this.
947946 if (!m_pinnedAllocLock.TryEnter ())
948947 {
949948 return AllocLarge (context, size, flags);
950949 }
951950
951+ // when allocations cross certain thresholds, check if GC should start or help is needed.
952+ size_t curAlloc = context->alloc_bytes + context->alloc_bytes_uoh ;
953+ size_t expectedAlloc = size;
954+ size_t change = (curAlloc ^ (curAlloc + expectedAlloc));
955+ if (curAlloc == 0 || change >= Satori::REGION_SIZE_GRANULARITY)
956+ {
957+ m_heap->Recycler ()->MaybeTriggerGC (gc_reason::reason_alloc_soh);
958+ }
959+ else if (change >= Satori::PACE_BUDGET)
960+ {
961+ m_heap->Recycler ()->HelpOnce ();
962+ }
963+
952964 SatoriRegion* region = m_pinnedRegion;
953965 while (true )
954966 {
0 commit comments